summaryrefslogtreecommitdiffstats
path: root/demos
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2009-07-16 02:29:11 (GMT)
committerMichael Brasser <michael.brasser@nokia.com>2009-07-16 02:29:11 (GMT)
commit8f16f6638bf07adb6c782cb173d323402cfa1c81 (patch)
tree54d4f44f5e44310d878fe4c4614b95433617b0fd /demos
parent7f55f59687d2f21c51b1f124a4eeff62c6b374dd (diff)
parent24b0ad11174118e327a778bbdf16fa64a5eb640c (diff)
downloadQt-8f16f6638bf07adb6c782cb173d323402cfa1c81.zip
Qt-8f16f6638bf07adb6c782cb173d323402cfa1c81.tar.gz
Qt-8f16f6638bf07adb6c782cb173d323402cfa1c81.tar.bz2
Merge branch 'kinetic-declarativeui' of git@scm.dev.nokia.troll.no:qt/kinetic into kinetic-declarativeui-gv
Conflicts: src/declarative/fx/fx.pri
Diffstat (limited to 'demos')
-rw-r--r--demos/declarative/flickr/content/Star.qml4
-rw-r--r--demos/declarative/samegame/README10
-rw-r--r--demos/declarative/samegame/SameGame.qml41
-rw-r--r--demos/declarative/samegame/TODO5
-rw-r--r--demos/declarative/samegame/content/BoomBlock.qml50
-rw-r--r--demos/declarative/samegame/content/FastBlock.qml27
-rw-r--r--demos/declarative/samegame/content/MediaButton.qml39
-rw-r--r--demos/declarative/samegame/content/SameDialog.qml17
-rw-r--r--demos/declarative/samegame/content/pics/background.pngbin0 -> 153328 bytes
-rw-r--r--demos/declarative/samegame/content/pics/blueStar.pngbin0 -> 2684 bytes
-rw-r--r--demos/declarative/samegame/content/pics/blueStone.pngbin0 -> 4823 bytes
-rw-r--r--demos/declarative/samegame/content/pics/button-pressed.pngbin0 -> 571 bytes
-rw-r--r--demos/declarative/samegame/content/pics/button.pngbin0 -> 564 bytes
-rw-r--r--demos/declarative/samegame/content/pics/greenStar.pngbin0 -> 2675 bytes
-rw-r--r--demos/declarative/samegame/content/pics/greenStone.pngbin0 -> 4724 bytes
-rw-r--r--demos/declarative/samegame/content/pics/qtlogo.pngbin0 -> 2738 bytes
-rw-r--r--demos/declarative/samegame/content/pics/redStar.pngbin0 -> 2676 bytes
-rw-r--r--demos/declarative/samegame/content/pics/redStone.pngbin0 -> 4585 bytes
-rw-r--r--demos/declarative/samegame/content/pics/star.pngbin0 -> 262 bytes
-rw-r--r--demos/declarative/samegame/content/pics/yellowStone.pngbin0 -> 4818 bytes
-rw-r--r--demos/declarative/samegame/content/samegame.js214
21 files changed, 405 insertions, 2 deletions
diff --git a/demos/declarative/flickr/content/Star.qml b/demos/declarative/flickr/content/Star.qml
index 2c2807a..0828bc0 100644
--- a/demos/declarative/flickr/content/Star.qml
+++ b/demos/declarative/flickr/content/Star.qml
@@ -3,8 +3,8 @@ Item {
width: 24
height: 24
- property string rating
- property string on
+ property int rating
+ property bool on
signal clicked
diff --git a/demos/declarative/samegame/README b/demos/declarative/samegame/README
new file mode 100644
index 0000000..244b205
--- /dev/null
+++ b/demos/declarative/samegame/README
@@ -0,0 +1,10 @@
+This demo uses pictures from the KDE project (www.kde.org),
+specifically the images from the KSame game. These images are
+
+background.png
+blueStone.png
+redStone.png
+greenStone.png
+yellowStone.png
+
+and are presumably under the same GPL2 license as the rest of kdegames
diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml
new file mode 100644
index 0000000..c929c91
--- /dev/null
+++ b/demos/declarative/samegame/SameGame.qml
@@ -0,0 +1,41 @@
+import "content"
+
+Rect {
+ width: 460
+ height: 700
+ color: "white"
+ Script { source: "content/samegame.js" }
+ Rect{
+ property int score: 0
+ y:20; width:400; height:600; id: gameCanvas;
+ //For Fixed Size
+ anchors.horizontalCenter: parent.horizontalCenter
+ //For flexible width
+ //anchors.left: parent.left; anchors.leftMargin: 30
+ //anchors.right: parent.right; anchors.rightMargin: 30
+ color: "white"
+ pen.width: 1
+ Image { id:background;
+ source: "content/pics/background.png"
+ anchors.fill: parent
+ }
+
+ MouseRegion { id: gameMR; anchors.fill: parent;
+ onClicked: handleClick(mouseX, mouseY);
+ }
+ }
+ HorizontalLayout {
+ anchors.top: gameCanvas.bottom
+ anchors.topMargin: 10
+ anchors.horizontalCenter: parent.horizontalCenter
+ MediaButton { id: btnA; text: "New Game"; onClicked: {initBoard();} }
+ MediaButton { id: btnB; text: "Swap Theme"; onClicked: {swapTileSrc(); dialog.opacity = 1;}
+ }
+ Text{ text: "Score: " + gameCanvas.score; width:100 }
+ }
+ SameDialog {
+ id: dialog
+ anchors.centeredIn: parent
+ text: "Takes effect next game."
+ }
+}
diff --git a/demos/declarative/samegame/TODO b/demos/declarative/samegame/TODO
new file mode 100644
index 0000000..b02ce54
--- /dev/null
+++ b/demos/declarative/samegame/TODO
@@ -0,0 +1,5 @@
+Still to do before initial release
+-Garbage collect on click
+-Particles with count 0->50 should work properly
+-Particles are too slow to start
+-Everything is too slow, we should have four times the number of tiles there
diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml
new file mode 100644
index 0000000..0d05772
--- /dev/null
+++ b/demos/declarative/samegame/content/BoomBlock.qml
@@ -0,0 +1,50 @@
+Item { id:block
+ property bool dying: false
+ property bool spawning: false
+ property int type: 0
+ property int targetX: 0
+ property int targetY: 0
+
+ x: Follow { source: targetX; spring: 1.2; damping: 0.1 }
+ y: Follow { source: targetY; spring: 1.2; damping: 0.1 }
+
+ Image { id: img
+ source: {
+ if(type == 0){
+ "pics/redStone.png";
+ } else if(type == 1) {
+ "pics/blueStone.png";
+ } else {
+ "pics/greenStone.png";
+ }
+ }
+ opacity: 0
+ opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } }
+ anchors.fill: parent
+ }
+ Particles { id: particles
+ width:1; height:1; anchors.centeredIn: parent; opacity: 0
+ lifeSpan: 1000000000; count:0; streamIn: false
+ angle: 0; angleDeviation: 360; velocity: 100; velocityDeviation:30
+ source: {
+ if(type == 0){
+ "pics/redStar.png";
+ } else if (type == 1) {
+ "pics/blueStar.png";
+ } else {
+ "pics/greenStar.png";
+ }
+ }
+ }
+ states: [
+
+ State{ name: "AliveState"; when: spawning == true && dying == false
+ SetProperties { target: img; opacity: 1 }
+ },
+ State{ name: "DeathState"; when: dying == true
+ SetProperties { target: particles; count: 50 }
+ SetProperties { target: particles; opacity: 1 }
+ SetProperties { target: img; opacity: 0 }
+ }
+ ]
+}
diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml
new file mode 100644
index 0000000..04eb59b
--- /dev/null
+++ b/demos/declarative/samegame/content/FastBlock.qml
@@ -0,0 +1,27 @@
+Rect { id:block
+ //Note: These properties are the interface used to control the blocks
+ property bool dying: false
+ property bool spawning: false
+ property int type: 0
+ property int targetY: 0
+ property int targetX: 0
+
+ color: {if(type==0){"red";}else if(type==1){"blue";}else{"green";}}
+ pen.width: 1
+ pen.color: "black"
+ opacity: 0
+ y: targetY
+ x: targetX
+ y: Behavior { NumberAnimation { properties:"y"; duration: 200 } }
+ opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } }
+
+ states: [
+
+ State{ name: "SpawnState"; when: spawning == true && dying == false
+ SetProperties { target: block; opacity: 1 }
+ },
+ State{ name: "DeathState"; when: dying == true
+ SetProperties { target: block; opacity: 0 }
+ }
+ ]
+}
diff --git a/demos/declarative/samegame/content/MediaButton.qml b/demos/declarative/samegame/content/MediaButton.qml
new file mode 100644
index 0000000..49922f0
--- /dev/null
+++ b/demos/declarative/samegame/content/MediaButton.qml
@@ -0,0 +1,39 @@
+Item {
+ id: Container
+
+ signal clicked
+
+ property string text
+
+ Image {
+ id: Image
+ source: "pics/button.png"
+ }
+ Image {
+ id: Pressed
+ source: "pics/button-pressed.png"
+ opacity: 0
+ }
+ MouseRegion {
+ id: MouseRegion
+ anchors.fill: Image
+ onClicked: { Container.clicked(); }
+ }
+ Text {
+ font.bold: true
+ color: "white"
+ anchors.centeredIn: Image
+ text: Container.text
+ }
+ width: Image.width
+ states: [
+ State {
+ name: "Pressed"
+ when: MouseRegion.pressed == true
+ SetProperties {
+ target: Pressed
+ opacity: 1
+ }
+ }
+ ]
+}
diff --git a/demos/declarative/samegame/content/SameDialog.qml b/demos/declarative/samegame/content/SameDialog.qml
new file mode 100644
index 0000000..eed52f0
--- /dev/null
+++ b/demos/declarative/samegame/content/SameDialog.qml
@@ -0,0 +1,17 @@
+Rect {
+ property string text: "Hello World!"
+ property int show: 0
+ id: page
+ opacity: 0
+ opacity: Behavior {
+ SequentialAnimation {
+ NumberAnimation {property: "opacity"; duration: 1000 }
+ NumberAnimation {property: "opacity"; to: 0; duration: 1000 }
+ }
+ }
+ color: "white"
+ pen.width: 1
+ width: 200
+ height: 60
+ Text { anchors.centeredIn: parent; text: parent.text }
+}
diff --git a/demos/declarative/samegame/content/pics/background.png b/demos/declarative/samegame/content/pics/background.png
new file mode 100644
index 0000000..25e885f
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/background.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/blueStar.png b/demos/declarative/samegame/content/pics/blueStar.png
new file mode 100644
index 0000000..822dc53
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/blueStar.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/blueStone.png b/demos/declarative/samegame/content/pics/blueStone.png
new file mode 100644
index 0000000..673f1ce
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/blueStone.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/button-pressed.png b/demos/declarative/samegame/content/pics/button-pressed.png
new file mode 100644
index 0000000..e434d32
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/button-pressed.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/button.png b/demos/declarative/samegame/content/pics/button.png
new file mode 100644
index 0000000..56a63ce
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/button.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/greenStar.png b/demos/declarative/samegame/content/pics/greenStar.png
new file mode 100644
index 0000000..1abbcf0
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/greenStar.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/greenStone.png b/demos/declarative/samegame/content/pics/greenStone.png
new file mode 100644
index 0000000..0c087d0
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/greenStone.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/qtlogo.png b/demos/declarative/samegame/content/pics/qtlogo.png
new file mode 100644
index 0000000..399bd0b
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/qtlogo.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/redStar.png b/demos/declarative/samegame/content/pics/redStar.png
new file mode 100644
index 0000000..b18834f
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/redStar.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/redStone.png b/demos/declarative/samegame/content/pics/redStone.png
new file mode 100644
index 0000000..80c2e2e
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/redStone.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/star.png b/demos/declarative/samegame/content/pics/star.png
new file mode 100644
index 0000000..defbde5
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/star.png
Binary files differ
diff --git a/demos/declarative/samegame/content/pics/yellowStone.png b/demos/declarative/samegame/content/pics/yellowStone.png
new file mode 100644
index 0000000..5349eff
--- /dev/null
+++ b/demos/declarative/samegame/content/pics/yellowStone.png
Binary files differ
diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js
new file mode 100644
index 0000000..fe5ac87
--- /dev/null
+++ b/demos/declarative/samegame/content/samegame.js
@@ -0,0 +1,214 @@
+/* This script file handles the game logic */
+
+var maxX = 10;//Nums are for tileSize 40
+var maxY = 15;
+var tileSize = 40;
+var maxIndex = maxX*maxY;
+var board = new Array(maxIndex);
+var tileSrc = "content/BoomBlock.qml";
+var backSrc = "content/pics/background.png";
+var swapped = false;
+
+var compSrc;
+var component;
+
+function swapTileSrc(){
+ if(swapped)
+ return;
+ if(tileSrc == "content/FastBlock.qml"){
+ tileSrc = "content/BoomBlock.qml";
+ backSrc = "content/pics/background.png";
+ }else{
+ backSrc = "content/pics/qtlogo.png";
+ tileSrc = "content/FastBlock.qml";
+ }
+ swapped = true;
+}
+
+function index(xIdx,yIdx){
+ return xIdx + (yIdx * maxX);
+}
+
+function initBoard()
+{
+ for(i = 0; i<maxIndex; i++){
+ //Delete old blocks
+ if(board[i] != null)
+ board[i].destroy();
+ }
+
+ background.source = backSrc;
+ swapped = false;
+ maxX = Math.floor(gameCanvas.width/tileSize);
+ maxY = Math.floor(gameCanvas.height/tileSize);
+ maxIndex = maxX*maxY;
+ board = new Array(maxIndex);
+ gameCanvas.score = 0;
+
+ for(xIdx=0; xIdx<maxX; xIdx++){
+ for(yIdx=0; yIdx<maxY; yIdx++){
+ board[index(xIdx,yIdx)] = null;
+ startCreatingBlock(xIdx,yIdx);
+ }
+ }
+ //TODO: a flag that handleMouse uses to ignore clicks when we're loading
+}
+
+var removed;
+var floodBoard;
+function handleClick(x,y)
+{
+ //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)
+ return;
+ gameCanvas.score += (removed - 1) * (removed - 1);
+ shuffleDown();
+ victoryCheck();
+}
+
+function floodKill(xIdx,yIdx,type)
+{
+ 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;
+ }
+ 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){
+ //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;
+}
+
+function shuffleDown()
+{
+ //Fall down
+ for(xIdx=0; xIdx<maxX; xIdx++){
+ fallDist = 0;
+ for(yIdx=maxY-1; yIdx>=0; yIdx--){
+ if(board[index(xIdx,yIdx)] == null){
+ fallDist += 1;
+ }else{
+ if(fallDist > 0){
+ obj = board[index(xIdx,yIdx)];
+ obj.targetY += fallDist * tileSize;
+ board[index(xIdx,yIdx+fallDist)] = obj;
+ board[index(xIdx,yIdx)] = null;
+ }
+ }
+ }
+ }
+ //Fall to the left
+ fallDist = 0;
+ for(xIdx=0; xIdx<maxX; xIdx++){
+ if(board[index(xIdx, maxY - 1)] == null){
+ fallDist += 1;
+ }else{
+ if(fallDist > 0){
+ for(yIdx=0; yIdx<maxY; yIdx++){
+ obj = board[index(xIdx,yIdx)];
+ if(obj == null)
+ continue;
+ obj.targetX -= fallDist * tileSize;
+ board[index(xIdx-fallDist,yIdx)] = obj;
+ board[index(xIdx,yIdx)] = null;
+ }
+ }
+ }
+ }
+}
+
+function victoryCheck()
+{
+ //Only awards bonuses at the moment
+ deservesBonus = true;
+ for(xIdx=maxX-1; xIdx>=0; xIdx--)
+ if(board[index(xIdx, maxY - 1)] != null)
+ deservesBonus = false;
+ if(deservesBonus)
+ gameCanvas.score += 250;
+}
+
+//Need a simpler method of doing this?
+var waitStack = new Array(maxIndex);
+var waitTop = -1;
+
+function finishCreatingBlock(xIdx,yIdx){
+ //TODO: Doc that the 'x', 'y' that were here are hidden properties from the calling QFxItem
+ if(component.isReady()){
+ if(xIdx == undefined){
+ //Called without arguments, create a previously stored (xIdx,yIdx)
+ if(waitTop == -1)
+ return;//Don't have a previously stored (xIdx,yIdx)
+ xIdx = waitStack[waitTop] % maxX;
+ yIdx = Math.floor(waitStack[waitTop] / maxX);
+ waitTop -= 1;
+ }
+ dynamicObject = component.createObject();
+ if(dynamicObject == null){
+ print("error creating block");
+ print(component.errorsString());
+ return false;
+ }
+ dynamicObject.type = Math.floor(Math.random() * 3);
+ dynamicObject.parent = gameCanvas;
+ dynamicObject.targetX = xIdx*tileSize;
+ dynamicObject.targetY = yIdx*tileSize;
+ dynamicObject.width = tileSize;
+ dynamicObject.height = tileSize;
+ dynamicObject.spawning = true;
+ board[index(xIdx,yIdx)] = dynamicObject;
+ return true;
+ }else if(component.isError()){
+ print("error creating block");
+ print(component.errorsString());
+ }else{
+ //It isn't ready, but we'll be called again when it is.
+ //So store the requested (xIdx,yIdx) for later use
+ waitTop += 1;
+ waitStack[waitTop] = index(xIdx,yIdx);
+ }
+ return false;
+}
+
+function startCreatingBlock(xIdx,yIdx){
+ if(component!=null && compSrc == tileSrc){
+ finishCreatingBlock(xIdx,yIdx);
+ return;
+ }
+
+ if(component!=null){//Changed source
+ //delete component; //Does the engine handle this?
+ compSrc = tileSrc;
+ }
+ component = createComponent(tileSrc);
+ if(finishCreatingBlock(xIdx,yIdx))
+ return;
+ component.statusChanged.connect(finishCreatingBlock());
+ return;
+}