From 64a05cfa97b1192ac247558c0601ba0e4ec464c9 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 15 Oct 2010 13:04:23 +1000 Subject: Snake demo now pauses when the window loses focus. Task-number: QTBUG-11592 --- demos/declarative/snake/content/pics/pause.png | Bin 0 -> 4327 bytes demos/declarative/snake/content/snake.js | 4 ++-- demos/declarative/snake/snake.qml | 12 +++++++++++- 3 files changed, 13 insertions(+), 3 deletions(-) create mode 100644 demos/declarative/snake/content/pics/pause.png diff --git a/demos/declarative/snake/content/pics/pause.png b/demos/declarative/snake/content/pics/pause.png new file mode 100644 index 0000000..056d97d Binary files /dev/null and b/demos/declarative/snake/content/pics/pause.png differ diff --git a/demos/declarative/snake/content/snake.js b/demos/declarative/snake/content/snake.js index c2e9d3a..5c089de 100644 --- a/demos/declarative/snake/content/snake.js +++ b/demos/declarative/snake/content/snake.js @@ -32,7 +32,7 @@ function startNewGame() if (state == "starting") return; - if (heartbeat.running) { + if (activeGame) { endGame(); startNewGameTimer.running = true; state = ""; @@ -87,7 +87,7 @@ function startNewGame() function endGame() { - heartbeat.running = false; + activeGame = false; for(var i in snake) snake[i].dying = true; if (cookie) { diff --git a/demos/declarative/snake/snake.qml b/demos/declarative/snake/snake.qml index 5b69217..6eaa976 100644 --- a/demos/declarative/snake/snake.qml +++ b/demos/declarative/snake/snake.qml @@ -47,6 +47,7 @@ Rectangle { id: screen; SystemPalette { id: activePalette } color: activePalette.window + property bool activeGame: false property int gridSize : 34 property int margin: 4 @@ -75,6 +76,7 @@ Rectangle { Timer { id: heartbeat; interval: heartbeatInterval; + running: activeGame && runtime.isActiveWindow repeat: true onTriggered: { Logic.move() } } @@ -94,9 +96,17 @@ Rectangle { Timer { id: startHeartbeatTimer; interval: 1000 ; - onTriggered: { state = "running"; heartbeat.running = true; } + onTriggered: { state = "running"; activeGame = true; } } + Image{ + id: pauseDialog + z: 1 + source: "content/pics/pause.png" + anchors.centerIn: parent; + //opacity is deliberately not animated + opacity: gameActive && !runtime.isActiveWindow + } Image { Image { -- cgit v0.12