summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorAlan Alpert <alan.alpert@nokia.com>2009-07-20 06:25:53 (GMT)
committerAlan Alpert <alan.alpert@nokia.com>2009-07-20 06:25:53 (GMT)
commitebcec1a247c4cb67537131c0d801780f4987a810 (patch)
treec2f0dbd2dfb1feb7c504e1e804203e2bf081674e /demos
parent91178b5826c40ad7ecdd70692d0c6128a1743dc9 (diff)
downloadQt-ebcec1a247c4cb67537131c0d801780f4987a810.zip
Qt-ebcec1a247c4cb67537131c0d801780f4987a810.tar.gz
Qt-ebcec1a247c4cb67537131c0d801780f4987a810.tar.bz2
Update Gnome theme to only spin on mouse over, like same-gnome
Note that currently we can only get mouse move signals if a button is pressed.
Diffstat (limited to 'demos')
-rw-r--r--demos/declarative/samegame/SameGame.qml1
-rw-r--r--demos/declarative/samegame/content/BoomBlock.qml1
-rw-r--r--demos/declarative/samegame/content/FastBlock.qml1
-rw-r--r--demos/declarative/samegame/content/SpinBlock.qml2
-rw-r--r--demos/declarative/samegame/content/pics/gnome/blueStone.gifbin19122 -> 19122 bytes
-rw-r--r--demos/declarative/samegame/content/pics/gnome/greenStone.gifbin20545 -> 20545 bytes
-rw-r--r--demos/declarative/samegame/content/pics/gnome/redStone.gifbin18455 -> 18455 bytes
-rw-r--r--demos/declarative/samegame/content/samegame.js75
8 files changed, 56 insertions, 24 deletions
diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml
index fd3ca88..5e998e8 100644
--- a/demos/declarative/samegame/SameGame.qml
+++ b/demos/declarative/samegame/SameGame.qml
@@ -22,6 +22,7 @@ Rect {
MouseRegion { id: gameMR; anchors.fill: parent;
onClicked: handleClick(mouseX, mouseY);
+ onPositionChanged: handleHover(mouseX, mouseY);
}
}
HorizontalLayout {
diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml
index 542e7bc..9148e60 100644
--- a/demos/declarative/samegame/content/BoomBlock.qml
+++ b/demos/declarative/samegame/content/BoomBlock.qml
@@ -1,6 +1,7 @@
Item { id:block
property bool dying: false
property bool spawned: false
+ property bool selected: false
property int type: 0
property int targetX: 0
property int targetY: 0
diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml
index 6e02ced..5149911 100644
--- a/demos/declarative/samegame/content/FastBlock.qml
+++ b/demos/declarative/samegame/content/FastBlock.qml
@@ -2,6 +2,7 @@ Rect { id:block
//Note: These properties are the interface used to control the blocks
property bool dying: false
property bool spawned: false
+ property bool selected: false
property int type: 0
property int targetY: 0
property int targetX: 0
diff --git a/demos/declarative/samegame/content/SpinBlock.qml b/demos/declarative/samegame/content/SpinBlock.qml
index 6737196..42276d0 100644
--- a/demos/declarative/samegame/content/SpinBlock.qml
+++ b/demos/declarative/samegame/content/SpinBlock.qml
@@ -2,6 +2,7 @@ Item { id:block
//Note: These properties are the interface used to control the blocks
property bool dying: false
property bool spawned: false
+ property bool selected: false
property int type: 0
property int targetY: 0
property int targetX: 0
@@ -14,6 +15,7 @@ Item { id:block
} else {
"pics/gnome/greenStone.gif";
}
+ playing: selected
}
opacity: 0
y: targetY
diff --git a/demos/declarative/samegame/content/pics/gnome/blueStone.gif b/demos/declarative/samegame/content/pics/gnome/blueStone.gif
index 4e6bd35..333efbe 100644
--- a/demos/declarative/samegame/content/pics/gnome/blueStone.gif
+++ b/demos/declarative/samegame/content/pics/gnome/blueStone.gif
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/gnome/greenStone.gif b/demos/declarative/samegame/content/pics/gnome/greenStone.gif
index c572e80..1bc5bf4 100644
--- a/demos/declarative/samegame/content/pics/gnome/greenStone.gif
+++ b/demos/declarative/samegame/content/pics/gnome/greenStone.gif
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/gnome/redStone.gif b/demos/declarative/samegame/content/pics/gnome/redStone.gif
index c6c10c5..b80f901 100644
--- a/demos/declarative/samegame/content/pics/gnome/redStone.gif
+++ b/demos/declarative/samegame/content/pics/gnome/redStone.gif
Binary files differ
diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js
index 1f76b9f..1814031 100644
--- a/demos/declarative/samegame/content/samegame.js
+++ b/demos/declarative/samegame/content/samegame.js
@@ -46,55 +46,82 @@ function initBoard()
//TODO: a flag that handleMouse uses to ignore clicks when we're loading
}
-var removed;
+var fillFound;
var floodBoard;
+
+var lastHoveredIdx = -1
+function handleHover(x,y, btn)
+{
+ xIdx = Math.floor(x/tileSize);
+ yIdx = Math.floor(y/tileSize);
+ if(index(xIdx, yIdx) == lastHoveredIdx)
+ return;
+ lastHoveredIdx = index(xIdx, yIdx);
+ //if(btn != 0)
+ // return;
+ floodFill(xIdx, yIdx, -1, "hover");
+ for(i=0; i<maxIndex; i++){
+ if(floodBoard[i] != 1 && board[i] != null)
+ board[i].selected = false;
+ }
+ //Could use the fillFound value to tell the player how many stones/points
+}
+
function handleClick(x,y)
{
- //NOTE: Be careful with vars named x,y - they can set to the calling object?
+ //NOTE: Be careful with vars named x,y - they can set to the calling object
xIdx = Math.floor(x/tileSize);
yIdx = Math.floor(y/tileSize);
if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
return;
if(board[index(xIdx, yIdx)] == null)
return;
- removed = 0;
- floodBoard = new Array(maxIndex);
- floodKill(xIdx,yIdx, -1);
- if(removed <= 0)
+ floodFill(xIdx,yIdx, -1, "kill");
+ if(fillFound <= 0)
return;
- gameCanvas.score += (removed - 1) * (removed - 1);
+ gameCanvas.score += (fillFound - 1) * (fillFound - 1);
shuffleDown();
victoryCheck();
}
-function floodKill(xIdx,yIdx,type)
+//cmd = "kill" is the removal case, cmd = "hover" is the mouse overed case
+function floodFill(xIdx,yIdx,type, cmd)
{
- if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
- return;
- if(floodBoard[index(xIdx, yIdx)] == 1)
- return;
if(board[index(xIdx, yIdx)] == null)
return;
var first = false;
if(type == -1){
- type = board[index(xIdx,yIdx)].type;
first = true;
- }else{
- if(type != board[index(xIdx,yIdx)].type)
- return;
+ type = board[index(xIdx,yIdx)].type;
+
+ //Flood fill initialization
+ fillFound = 0;
+ floodBoard = new Array(maxIndex);
}
+ if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0)
+ return;
+ if(floodBoard[index(xIdx, yIdx)] == 1)
+ return;
+ if(!first && type != board[index(xIdx,yIdx)].type)
+ return;
floodBoard[index(xIdx, yIdx)] = 1;
- floodKill(xIdx+1,yIdx,type);
- floodKill(xIdx-1,yIdx,type);
- floodKill(xIdx,yIdx+1,type);
- floodKill(xIdx,yIdx-1,type);
- if(first==true && removed == 0){
+ floodFill(xIdx+1,yIdx,type,cmd);
+ floodFill(xIdx-1,yIdx,type,cmd);
+ floodFill(xIdx,yIdx+1,type,cmd);
+ floodFill(xIdx,yIdx-1,type,cmd);
+ if(first==true && fillFound == 0){
//TODO: Provide a way to inform the delegate
return;//Can't remove single tiles
}
- board[index(xIdx,yIdx)].dying = true;
- board[index(xIdx,yIdx)] = null;//They'll have to destroy themselves(can we do that?)
- removed += 1;
+ if(cmd == "kill"){
+ board[index(xIdx,yIdx)].dying = true;
+ board[index(xIdx,yIdx)] = null;//They'll have to destroy themselves(can we do that?)
+ }else if(cmd == "hover"){
+ board[index(xIdx,yIdx)].selected = true;
+ }else{
+ print ("Flood Error");
+ }
+ fillFound += 1;
}
function shuffleDown()