Welcome to mirror list, hosted at ThFree Co, Russian Federation.

FPSItem.qml « qml « resources - github.com/Ultimaker/Cura.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9f7dfe874679db8ad1f8a3938da91af41e3a0f4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import QtQuick 2.0
import QtQuick.Window 2.2
import UM 1.3 as UM

// This is an QML item that shows the FPS and a running average of the FPS.
Item
{
    id: base
    property alias backgroundColor: background.color
    property alias textColor: fpsText.color

    property int numMeasurementsToAverage: 3

    width:  fpsText.contentWidth + UM.Theme.getSize("default_margin").height
    height: fpsText.contentHeight + UM.Theme.getSize("default_margin").height

    Rectangle
    {
        id: background

        // We use a trick here to figure out how often we can get a redraw triggered.
        // By adding a rotating rectangle, we can increase a counter by one every time we get notified.
        // After that, we trigger a timer once every second to look at that number.
        property int frameCounter: 0
        property int averageFrameCounter: 0
        property int counter: 0
        property int fps: 0
        property real averageFps: 0.0

        color: UM.Theme.getColor("primary")

        width: parent.width
        height: parent.height

        Rectangle
        {
            width: 0
            height: 0
            NumberAnimation on rotation
            {
                from: 0
                to: 360
                duration: 1000
                loops: Animation.Infinite
            }
            onRotationChanged: parent.frameCounter++;
            visible: false
        }

        Text
        {
            id: fpsText
            anchors.fill:parent
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignHCenter
            color: UM.Theme.getColor("text")
            font: UM.Theme.getFont("default")
            text: "Ø " + parent.averageFps + " | " + parent.fps + " fps"
        }

        Timer
        {
            interval: 1000
            repeat: true
            running: true
            onTriggered:
            {
                parent.averageFrameCounter += parent.frameCounter;
                parent.fps = parent.frameCounter;
                parent.counter++;
                parent.frameCounter = 0;
                if (parent.counter >= base.numMeasurementsToAverage)
                {
                    parent.averageFps = (parent.averageFrameCounter / parent.counter).toFixed(2)
                    parent.averageFrameCounter = 0;
                    parent.counter = 0;
                }
            }
        }
    }
}