Debian Codegraph @

tests/manual/planets-qml/FpsDisplay.qml

raw
1 // Copyright (C) 2016 The Qt Company Ltd.
2 // SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
3
4 import QtQuick 2.0
5
6 Item {
7 id: fpsDisplayControl
8 property bool hidden: true
9 property real fps: 0.0
10
11 onHiddenChanged: {
12 if (fpsDisplayControl.hidden)
13 fpsDisplay.color = "transparent"
14 else
15 fpsDisplay.color = "#000000FF"
16 }
17
18 onFpsChanged: {
19 fpsDisplay.updateFps()
20 }
21
22 Rectangle {
23 anchors.fill: parent
24 id: fpsDisplay
25 color: "transparent"
26
27 property real maxFps: 60.0
28 property color maxFpsColor: "#5500FF00"
29 property color minFpsColor: "#55FF0000"
30
31 function updateFps() {
32 var scale = (fps > maxFps)?1.0:(fps/maxFps)
33 var r = (1 - scale) * minFpsColor.r + scale * maxFpsColor.r
34 var g = (1 - scale) * minFpsColor.g + scale * maxFpsColor.g
35 var b = (1 - scale) * minFpsColor.b + scale * maxFpsColor.b
36 var a = (1 - scale) * minFpsColor.a + scale * maxFpsColor.a
37 fpsCauge.height = scale * fpsDisplay.height
38 fpsCauge.color = Qt.rgba(r, g, b, a)
39 }
40
41 Rectangle {
42 id: fpsCauge
43 width: parent.width
44 anchors.bottom: parent.bottom
45 visible: !fpsDisplayControl.hidden
46 }
47
48 Text {
49 id: fpsText
50 text: ""+(fps | 0)
51 font.family: "Helvetica"
52 font.pixelSize: 16
53 font.weight: Font.Light
54 color: "white"
55 anchors.fill: parent
56 verticalAlignment: Text.AlignVCenter
57 horizontalAlignment: Text.AlignHCenter
58 visible: !fpsDisplayControl.hidden
59 }
60 }
61
62 MouseArea {
63 anchors.fill: parent
64 onClicked: {
65 fpsDisplayControl.hidden = !fpsDisplayControl.hidden
66 }
67 }
68 }
69