added fps counter
This commit is contained in:
parent
66a18ca17a
commit
9e3db3865a
59
Qt_Performance_Benchmark/FpsItem.qml
Normal file
59
Qt_Performance_Benchmark/FpsItem.qml
Normal file
@ -0,0 +1,59 @@
|
|||||||
|
import QtQuick 2.0
|
||||||
|
import QtQuick.Window 2.2
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
id: root
|
||||||
|
property int frameCounter: 0
|
||||||
|
property int frameCounterAvg: 0
|
||||||
|
property int counter: 0
|
||||||
|
property int fps: 0
|
||||||
|
property int fpsAvg: 0
|
||||||
|
|
||||||
|
readonly property real dp: Screen.pixelDensity * 25.4/160
|
||||||
|
|
||||||
|
color: "black"
|
||||||
|
width: childrenRect.width + 10*dp;
|
||||||
|
height: childrenRect.height + 10*dp;
|
||||||
|
|
||||||
|
Image {
|
||||||
|
id: spinnerImage
|
||||||
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
x: 4 * dp
|
||||||
|
width: 36 * dp
|
||||||
|
height: width
|
||||||
|
source: "images/spinner.png"
|
||||||
|
NumberAnimation on rotation {
|
||||||
|
from:0
|
||||||
|
to: 360
|
||||||
|
duration: 800
|
||||||
|
loops: Animation.Infinite
|
||||||
|
}
|
||||||
|
onRotationChanged: frameCounter++;
|
||||||
|
}
|
||||||
|
|
||||||
|
Text {
|
||||||
|
anchors.left: spinnerImage.right
|
||||||
|
anchors.leftMargin: 8 * dp
|
||||||
|
anchors.verticalCenter: spinnerImage.verticalCenter
|
||||||
|
color: "#c0c0c0"
|
||||||
|
font.pixelSize: 18 * dp
|
||||||
|
text: "Ø " + root.fpsAvg + " | " + root.fps + " fps"
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 2000
|
||||||
|
repeat: true
|
||||||
|
running: true
|
||||||
|
onTriggered: {
|
||||||
|
frameCounterAvg += frameCounter;
|
||||||
|
root.fps = frameCounter/2;
|
||||||
|
counter++;
|
||||||
|
frameCounter = 0;
|
||||||
|
if (counter >= 3) {
|
||||||
|
root.fpsAvg = frameCounterAvg/(2*counter)
|
||||||
|
frameCounterAvg = 0;
|
||||||
|
counter = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,6 +2,7 @@ import QtQuick 2.12
|
|||||||
import QtQuick.Window 2.12
|
import QtQuick.Window 2.12
|
||||||
import QtQuick.Controls 2.3
|
import QtQuick.Controls 2.3
|
||||||
|
|
||||||
|
|
||||||
Window {
|
Window {
|
||||||
id: rootwin
|
id: rootwin
|
||||||
width: 640
|
width: 640
|
||||||
@ -18,10 +19,23 @@ Window {
|
|||||||
|
|
||||||
//NumberAnimation on x { id: ani; loops: Animation.Infinite; to: 250; duration: 1000 }
|
//NumberAnimation on x { id: ani; loops: Animation.Infinite; to: 250; duration: 1000 }
|
||||||
|
|
||||||
NumberAnimation on x { id: ani; loops: Animation.Infinite; from: 0; to: 1000; duration: 5000 }
|
NumberAnimation on x { id: ani; loops: Animation.Infinite; from: 0; to: 100; duration: 500 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Rectangle {
|
||||||
|
x: 20
|
||||||
|
y: 148
|
||||||
|
width: 100; height: 100
|
||||||
|
color: "blue"
|
||||||
|
|
||||||
|
//NumberAnimation on x { id: ani; loops: Animation.Infinite; to: 250; duration: 1000 }
|
||||||
|
|
||||||
|
NumberAnimation on x { id: ani2; loops: Animation.Infinite; from: 0; to: 1000; duration: 5000 }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function onChecked(checked) {
|
function onChecked(checked) {
|
||||||
|
|
||||||
if (checked) {
|
if (checked) {
|
||||||
@ -33,14 +47,19 @@ Window {
|
|||||||
|
|
||||||
CheckBox {
|
CheckBox {
|
||||||
id: checkBox
|
id: checkBox
|
||||||
x: 78
|
x: 41
|
||||||
y: 200
|
y: 279
|
||||||
state: active
|
state: active
|
||||||
text: qsTr("Check Box")
|
text: qsTr("Check Box")
|
||||||
onClicked: rootwin.onChecked(checked)
|
onClicked: rootwin.onChecked(checked)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
FpsItem {
|
||||||
|
id: fpsItem
|
||||||
|
anchors.verticalCenterOffset: 106
|
||||||
|
anchors.horizontalCenterOffset: -239
|
||||||
|
anchors.centerIn: parent
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/">
|
<qresource prefix="/">
|
||||||
<file>main.qml</file>
|
<file>main.qml</file>
|
||||||
|
<file>FpsItem.qml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
Loading…
Reference in New Issue
Block a user