Browse Source

Add FPS counter

Donald Carr 8 years ago
parent
commit
16fce53721
4 changed files with 54 additions and 1 deletions
  1. 6 1
      qml/main.qml
  2. 1 0
      qml/qml.qrc
  3. 1 0
      qml/qmldir
  4. 46 0
      qml/widget/FPSMonitor.qml

+ 6 - 1
qml/main.qml

@@ -2,7 +2,8 @@ import QtQuick 2.5
 import QtQuick.Window 2.2
 import Qt.labs.settings 1.0
 import PictureModel 1.0
-import "qrc:/3rdparty/animatedBackground"
+
+import "."
 
 Window {
     id: appWindow
@@ -340,4 +341,8 @@ Window {
             }
         }
     }
+
+    FPSMonitor {
+        anchors { top: parent.top; right: parent.right }
+    }
 }

+ 1 - 0
qml/qml.qrc

@@ -2,6 +2,7 @@
     <qresource prefix="/">
         <file>main.qml</file>
         <file>qmldir</file>
+        <file>widget/FPSMonitor.qml</file>
         <file>common/VisualEffect.qml</file>
         <file>physics/BoxBody.qml</file>
         <file>physics/ImageBoxBody.qml</file>

+ 1 - 0
qml/qmldir

@@ -6,3 +6,4 @@ ImageBoxBody 1.0 physics/ImageBoxBody.qml
 ArtBoxBody 1.0 physics/ArtBoxBody.qml
 RectangleBoxBody 1.0 physics/RectangleBoxBody.qml
 BoxBody 1.0 physics/BoxBody.qml
+FPSMonitor 1.0 widget/FPSMonitor.qml

+ 46 - 0
qml/widget/FPSMonitor.qml

@@ -0,0 +1,46 @@
+import QtQuick 2.0
+
+// pretty much entirely stolen from:
+// https://github.com/capisce/motionblur/blob/master/main.qml
+
+Rectangle {
+    color: "black"
+
+    property real t
+    property int frame: 0
+
+    height: fpsText.height
+    width: fpsText.width
+
+    Text {
+        id: fpsText
+
+        font.pixelSize: 100
+        color: "white"
+        text: "FPS:" + fpsTimer.fps
+    }
+
+    Timer {
+        id: fpsTimer
+        property real fps: 0
+        repeat: true
+        interval: 1000
+        running: true
+        onTriggered: {
+            fps = frame
+            frame = 0
+        }
+    }
+
+    NumberAnimation on t {
+        id: tAnim
+        from: 0
+        to: 100
+        loops: Animation.Infinite
+    }
+
+    onTChanged: {
+        update() // force continuous animation
+        ++frame
+    }
+}