From 280e573d7881ffb5dd052f3774de3bc7aff3174a Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 27 Jul 2009 14:46:08 +1000 Subject: Fix layouts a little. Not fully, there are still some issues with the transitions. --- src/declarative/fx/qfxlayouts.cpp | 48 +++++++++++++++++++++++++-------------- src/declarative/fx/qfxlayouts.h | 3 ++- src/declarative/fx/qfxlayouts_p.h | 8 ++++++- 3 files changed, 40 insertions(+), 19 deletions(-) diff --git a/src/declarative/fx/qfxlayouts.cpp b/src/declarative/fx/qfxlayouts.cpp index 3e8a64c..6b94321 100644 --- a/src/declarative/fx/qfxlayouts.cpp +++ b/src/declarative/fx/qfxlayouts.cpp @@ -319,13 +319,15 @@ void QFxBaseLayout::preLayout() if (!d->_items.contains(child)){ QObject::connect(child, SIGNAL(visibleChanged()), this, SLOT(preLayout())); + QObject::connect(child, SIGNAL(opacityChanged()), + this, SLOT(preLayout())); QObject::connect(child, SIGNAL(heightChanged()), this, SLOT(preLayout())); QObject::connect(child, SIGNAL(widthChanged()), this, SLOT(preLayout())); d->_items += child; } - if (!child->isVisible()){ + if (child->opacity() == 0.0){ if (d->_stableItems.contains(child)){ d->_leavingItems += child; d->_stableItems -= child; @@ -339,7 +341,7 @@ void QFxBaseLayout::preLayout() foreach(QFxItem *child, d->_items){ if (!allItems.contains(child)){ if (!deletedItems.contains(child)) { - QObject::disconnect(child, SIGNAL(visibleChanged()), + QObject::disconnect(child, SIGNAL(opacityChanged()), this, SLOT(preLayout())); QObject::disconnect(child, SIGNAL(heightChanged()), this, SLOT(preLayout())); @@ -356,7 +358,7 @@ void QFxBaseLayout::preLayout() qreal width=0; qreal height=0; foreach(QFxItem *item, d->_items){ - if (item->isVisible()){ + if (item->opacity() == 0.0){ if (!d->_animated.contains(item)){ setMovingItem(item); QPointF p(item->x(), item->y()); @@ -385,21 +387,18 @@ void QFxBaseLayout::preLayout() setLayoutItem(0); } -//###This should be considered to move more centrally, as it seems useful -void QFxBaseLayout::applyTransition(const QList >& changes, QFxItem* target, QmlTransition* trans) +void QFxBaseLayout::applyTransition(const QList >& changes, QFxItem* target, QmlStateOperation::ActionList &actions) { Q_D(QFxBaseLayout); - if (!trans||!target)//TODO: if !trans, just apply changes + if (!target) return; setLayoutItem(target); - QmlStateOperation::ActionList actions; - for (int ii=0; ii_margin && - (changes[ii].first == QLatin1String("x") || + (changes[ii].first == QLatin1String("x") || changes[ii].first == QLatin1String("y"))) { val = QVariant(val.toInt() + d->_margin); } @@ -408,10 +407,19 @@ void QFxBaseLayout::applyTransition(const QList >& chan } - d->transitionManager.transition(actions, trans); d->_animated << target; } +void QFxBaseLayout::finishApplyTransitions() +{ + Q_D(QFxBaseLayout); + d->addTransitionManager.transition(d->addActions, d->addTransition); + d->moveTransitionManager.transition(d->moveActions, d->moveTransition); + d->removeTransitionManager.transition(d->removeActions, d->removeTransition); + d->addActions.clear(); + d->moveActions.clear(); + d->removeActions.clear(); +} void QFxBaseLayout::setMovingItem(QFxItem *i) { Q_D(QFxBaseLayout); @@ -424,7 +432,8 @@ void QFxBaseLayout::setMovingItem(QFxItem *i) */ void QFxBaseLayout::applyAdd(const QList >& changes, QFxItem* target) { - applyTransition(changes,target, add()); + Q_D(QFxBaseLayout); + applyTransition(changes,target, d->addActions); } /*! @@ -433,7 +442,8 @@ void QFxBaseLayout::applyAdd(const QList >& changes, QF */ void QFxBaseLayout::applyMove(const QList >& changes, QFxItem* target) { - applyTransition(changes,target, move()); + Q_D(QFxBaseLayout); + applyTransition(changes,target, d->moveActions); } /*! @@ -442,7 +452,8 @@ void QFxBaseLayout::applyMove(const QList >& changes, Q */ void QFxBaseLayout::applyRemove(const QList >& changes, QFxItem* target) { - applyTransition(changes,target, remove()); + Q_D(QFxBaseLayout); + applyTransition(changes,target, d->removeActions); } QML_DEFINE_TYPE(Qt,4,6,(QT_VERSION&0x00ff00)>>8,VerticalLayout,QFxVerticalLayout) @@ -623,7 +634,7 @@ void QFxVerticalLayout::doLayout() QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { QFxItem *child = qobject_cast(children.at(ii)); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; bool needMove = (child->y() != voffset || child->x()); @@ -643,6 +654,7 @@ void QFxVerticalLayout::doLayout() voffset += child->height(); voffset += spacing(); } + finishApplyTransitions(); setMovingItem(this); setHeight(voffset); setMovingItem(0); @@ -790,7 +802,7 @@ void QFxHorizontalLayout::doLayout() QList children = childItems(); for (int ii = 0; ii < children.count(); ++ii) { QFxItem *child = qobject_cast(children.at(ii)); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; bool needMove = (child->x() != hoffset || child->y()); @@ -810,6 +822,7 @@ void QFxHorizontalLayout::doLayout() hoffset += child->width(); hoffset += spacing(); } + finishApplyTransitions(); setWidth(hoffset); } @@ -1028,7 +1041,7 @@ void QFxGridLayout::doLayout() if (childIndex == children.count()) continue; QFxItem *child = qobject_cast(children.at(childIndex++)); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; if (child->width() > maxColWidth[j]) maxColWidth[j] = child->width(); @@ -1049,7 +1062,7 @@ void QFxGridLayout::doLayout() } foreach(QGraphicsItem* schild, children){ QFxItem *child = qobject_cast(schild); - if (!child || !child->isVisible()) + if (!child || child->opacity() == 0.0) continue; bool needMove = (child->x()!=xoffset)||(child->y()!=yoffset); QList > changes; @@ -1077,6 +1090,7 @@ void QFxGridLayout::doLayout() return; } } + finishApplyTransitions(); } QT_END_NAMESPACE diff --git a/src/declarative/fx/qfxlayouts.h b/src/declarative/fx/qfxlayouts.h index 5767bc5..03ddf3e 100644 --- a/src/declarative/fx/qfxlayouts.h +++ b/src/declarative/fx/qfxlayouts.h @@ -96,6 +96,7 @@ protected: void applyAdd(const QList >& changes, QFxItem* target); void applyMove(const QList >& changes, QFxItem* target); void applyRemove(const QList >& changes, QFxItem* target); + void finishApplyTransitions(); Q_SIGNALS: void layoutItemChanged(); @@ -113,7 +114,7 @@ protected: private: void applyTransition(const QList >& changes, QFxItem* target, - QmlTransition* transition); + QmlStateOperation::ActionList &actions); Q_DISABLE_COPY(QFxBaseLayout) Q_DECLARE_PRIVATE_D(QGraphicsItem::d_ptr, QFxBaseLayout) }; diff --git a/src/declarative/fx/qfxlayouts_p.h b/src/declarative/fx/qfxlayouts_p.h index 5ffe70e..87b944c 100644 --- a/src/declarative/fx/qfxlayouts_p.h +++ b/src/declarative/fx/qfxlayouts_p.h @@ -59,6 +59,7 @@ #include #include #include +#include QT_BEGIN_NAMESPACE class QFxBaseLayoutPrivate : public QFxItemPrivate @@ -92,7 +93,12 @@ public: QSet _newItems; QSet _animated; QFxItem *_layoutItem; - QmlTransitionManager transitionManager; + QmlStateOperation::ActionList addActions; + QmlStateOperation::ActionList moveActions; + QmlStateOperation::ActionList removeActions; + QmlTransitionManager addTransitionManager; + QmlTransitionManager moveTransitionManager; + QmlTransitionManager removeTransitionManager; // QmlStateGroup *stateGroup; QFxItem *_movingItem; }; -- cgit v0.12 From 5cddf5630ff0e408a84c19b7bb5ebc36871fa025 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 27 Jul 2009 15:22:45 +1000 Subject: Add a glowy effect like KSame to SameGame Just want this in the repo, samegame is about to be majorly revised. --- demos/declarative/samegame/content/BoomBlock.qml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index 9637bd6..ec4430e 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -11,9 +11,17 @@ Item { id:block x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } y: Follow { source: targetY; spring: 2; damping: 0.2 } + //TODO: Replace with an image with a fuzzy effect like KSame + Rect { id: shine; radius:16; anchors.fill:parent; color: "yellow"; + opacity: 0 + opacity: SequentialAnimation{running: selected&&!dying; finishPlaying: true; repeat: true + NumberAnimation{ from: 0; to: 1; }NumberAnimation{ from:1; to:0; }} + } MouseRegion { id: gameMR; anchors.fill: parent onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); + onExited: handleHover(-1,-1); } Image { id: img -- cgit v0.12 From 1a5338d8cc96cd07d2340aa2aff5880fd2fdce68 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 27 Jul 2009 16:39:56 +1000 Subject: Repurpose SameGame to be slimmer No theming and no selected, plus some cleanup. --- demos/declarative/samegame/README | 2 - demos/declarative/samegame/SameGame.qml | 46 ++++----- demos/declarative/samegame/TODO | 2 - demos/declarative/samegame/content/BoomBlock.qml | 15 --- demos/declarative/samegame/content/FastBlock.qml | 33 ------ demos/declarative/samegame/content/MediaButton.qml | 41 -------- demos/declarative/samegame/content/SameDialog.qml | 19 ---- demos/declarative/samegame/content/SpinBlock.qml | 47 --------- .../samegame/content/pics/button-pressed.png | Bin 571 -> 0 bytes demos/declarative/samegame/content/pics/button.png | Bin 564 -> 0 bytes .../samegame/content/pics/gnome/blueStone.gif | Bin 19122 -> 0 bytes .../samegame/content/pics/gnome/greenStone.gif | Bin 20545 -> 0 bytes .../samegame/content/pics/gnome/redStone.gif | Bin 18455 -> 0 bytes demos/declarative/samegame/content/pics/qtlogo.png | Bin 2738 -> 0 bytes demos/declarative/samegame/content/samegame.js | 111 ++++----------------- 15 files changed, 42 insertions(+), 274 deletions(-) delete mode 100644 demos/declarative/samegame/TODO delete mode 100644 demos/declarative/samegame/content/FastBlock.qml delete mode 100644 demos/declarative/samegame/content/MediaButton.qml delete mode 100644 demos/declarative/samegame/content/SameDialog.qml delete mode 100644 demos/declarative/samegame/content/SpinBlock.qml delete mode 100644 demos/declarative/samegame/content/pics/button-pressed.png delete mode 100644 demos/declarative/samegame/content/pics/button.png delete mode 100644 demos/declarative/samegame/content/pics/gnome/blueStone.gif delete mode 100644 demos/declarative/samegame/content/pics/gnome/greenStone.gif delete mode 100644 demos/declarative/samegame/content/pics/gnome/redStone.gif delete mode 100644 demos/declarative/samegame/content/pics/qtlogo.png diff --git a/demos/declarative/samegame/README b/demos/declarative/samegame/README index 2f2a728..244b205 100644 --- a/demos/declarative/samegame/README +++ b/demos/declarative/samegame/README @@ -8,5 +8,3 @@ greenStone.png yellowStone.png and are presumably under the same GPL2 license as the rest of kdegames - -The images in the pics/gnome folder are from the gnome games project, and are also GPL2 licensed. diff --git a/demos/declarative/samegame/SameGame.qml b/demos/declarative/samegame/SameGame.qml index e2c2089..1788341 100644 --- a/demos/declarative/samegame/SameGame.qml +++ b/demos/declarative/samegame/SameGame.qml @@ -3,38 +3,38 @@ import Qt 4.6 import "content" Rect { - width: 460 - height: 700 - color: activePalette.window + id: page; width: 460; height: 700; color: activePalette.window Script { source: "content/samegame.js" } - Rect{ + Rect { + id: gameCanvas property int score: 0 - y:20; width:400; height:600; id: gameCanvas; - //For Fixed Size + z:20; y:20; width:400; height:600; color: "white"; pen.width: 1 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(mouse.x,mouse.y); + } + } + Dialog { id: dialog; anchors.centeredIn: parent; z: 21} + Button { + id: btnA; text: "New Game"; onClicked: {initBoard();} + anchors.top: gameCanvas.bottom; anchors.topMargin: 4; anchors.left: gameCanvas.left; } - 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 Tiles"; onClicked: {swapTileSrc(); dialog.opacity = 1; - dialog.text="Takes effect next game.";} } - Text{ text: "Score: " + gameCanvas.score; width:120; font.size:14 } + Text { + text: "Score: " + gameCanvas.score; width:100; font.size:14 + anchors.top: gameCanvas.bottom; anchors.topMargin: 4; anchors.right: gameCanvas.right; } - SameDialog { - id: dialog - anchors.centeredIn: parent - text: "Hello World" + Text { + text: "Just over 300 lines of QML/JS code!" + anchors.horizontalCenter: parent.horizontalCenter + anchors.bottom: parent.bottom; anchors.bottomMargin: 16; + opacity: SequentialAnimation{ running: true; repeat: true; + NumberAnimation { from: 0; to: 1; duration: 1000; easing: "easeInQuad" } + NumberAnimation { from: 1; to: 0; duration: 1000; easing: "easeInQuad" } + } } } diff --git a/demos/declarative/samegame/TODO b/demos/declarative/samegame/TODO deleted file mode 100644 index 3be2a3a..0000000 --- a/demos/declarative/samegame/TODO +++ /dev/null @@ -1,2 +0,0 @@ -Still to do: - diff --git a/demos/declarative/samegame/content/BoomBlock.qml b/demos/declarative/samegame/content/BoomBlock.qml index ec4430e..a4f4fe9 100644 --- a/demos/declarative/samegame/content/BoomBlock.qml +++ b/demos/declarative/samegame/content/BoomBlock.qml @@ -3,7 +3,6 @@ import Qt 4.6 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 @@ -11,19 +10,6 @@ Item { id:block x: Follow { enabled: spawned; source: targetX; spring: 2; damping: 0.2 } y: Follow { source: targetY; spring: 2; damping: 0.2 } - //TODO: Replace with an image with a fuzzy effect like KSame - Rect { id: shine; radius:16; anchors.fill:parent; color: "yellow"; - opacity: 0 - opacity: SequentialAnimation{running: selected&&!dying; finishPlaying: true; repeat: true - NumberAnimation{ from: 0; to: 1; }NumberAnimation{ from:1; to:0; }} - } - MouseRegion { - id: gameMR; anchors.fill: parent - onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onExited: handleHover(-1,-1); - } - Image { id: img source: { if(type == 0){ @@ -55,7 +41,6 @@ Item { id:block } states: [ - State{ name: "AliveState"; when: spawned == true && dying == false SetProperties { target: img; opacity: 1 } }, diff --git a/demos/declarative/samegame/content/FastBlock.qml b/demos/declarative/samegame/content/FastBlock.qml deleted file mode 100644 index f30d8da..0000000 --- a/demos/declarative/samegame/content/FastBlock.qml +++ /dev/null @@ -1,33 +0,0 @@ -import Qt 4.6 - -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 - - color: {if(type==0){"red";}else if(type==1){"blue";}else{"green";}} - pen.width: 1 - pen.color: "black" - opacity: 0 - y: targetY - x: targetX - - MouseRegion { - id: gameMR; anchors.fill: parent - onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); - } - - states: [ - - State{ name: "AliveState"; when: spawned == 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 deleted file mode 100644 index cbe4265..0000000 --- a/demos/declarative/samegame/content/MediaButton.qml +++ /dev/null @@ -1,41 +0,0 @@ -import Qt 4.6 - -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 deleted file mode 100644 index 86248a6..0000000 --- a/demos/declarative/samegame/content/SameDialog.qml +++ /dev/null @@ -1,19 +0,0 @@ -import Qt 4.6 - -Rect { - property string text: "Hello World!" - property int show: 0 - id: page - opacity: 0 - opacity: Behavior { - SequentialAnimation { - NumberAnimation {property: "opacity"; duration: 1500 } - NumberAnimation {property: "opacity"; to: 0; duration: 1500 } - } - } - color: "white" - pen.width: 1 - width: 200 - height: 60 - Text { anchors.centeredIn: parent; text: parent.text } -} diff --git a/demos/declarative/samegame/content/SpinBlock.qml b/demos/declarative/samegame/content/SpinBlock.qml deleted file mode 100644 index 4c8f123..0000000 --- a/demos/declarative/samegame/content/SpinBlock.qml +++ /dev/null @@ -1,47 +0,0 @@ -import Qt 4.6 - -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 - - AnimatedImage { - source: if(type == 0) { - "pics/gnome/redStone.gif"; - } else if (type == 1) { - "pics/gnome/blueStone.gif"; - } else { - "pics/gnome/greenStone.gif"; - } - paused: !selected - paused: Behavior { to: true; from: false; - NumberAnimation { properties:"currentFrame"; to:0; duration: 200} - } - } - opacity: 0 - y: targetY - x: targetX - y: Behavior { NumberAnimation { properties:"y"; duration: 200 } } - x: Behavior { NumberAnimation { properties:"x"; duration: 200 } } - opacity: Behavior { NumberAnimation { properties:"opacity"; duration: 200 } } - MouseRegion { - id: gameMR; anchors.fill: parent - onClicked: handleClick(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onEntered: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); - onExited: handleHover(Math.floor(parent.x/width), Math.floor(parent.y/height)); - } - - states: [ - - State{ name: "AliveState"; when: spawned == 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/pics/button-pressed.png b/demos/declarative/samegame/content/pics/button-pressed.png deleted file mode 100644 index e434d32..0000000 Binary files a/demos/declarative/samegame/content/pics/button-pressed.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/button.png b/demos/declarative/samegame/content/pics/button.png deleted file mode 100644 index 56a63ce..0000000 Binary files a/demos/declarative/samegame/content/pics/button.png and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/gnome/blueStone.gif b/demos/declarative/samegame/content/pics/gnome/blueStone.gif deleted file mode 100644 index 333efbe..0000000 Binary files a/demos/declarative/samegame/content/pics/gnome/blueStone.gif and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/gnome/greenStone.gif b/demos/declarative/samegame/content/pics/gnome/greenStone.gif deleted file mode 100644 index 1bc5bf4..0000000 Binary files a/demos/declarative/samegame/content/pics/gnome/greenStone.gif and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/gnome/redStone.gif b/demos/declarative/samegame/content/pics/gnome/redStone.gif deleted file mode 100644 index b80f901..0000000 Binary files a/demos/declarative/samegame/content/pics/gnome/redStone.gif and /dev/null differ diff --git a/demos/declarative/samegame/content/pics/qtlogo.png b/demos/declarative/samegame/content/pics/qtlogo.png deleted file mode 100644 index 399bd0b..0000000 Binary files a/demos/declarative/samegame/content/pics/qtlogo.png and /dev/null differ diff --git a/demos/declarative/samegame/content/samegame.js b/demos/declarative/samegame/content/samegame.js index ef32230..a7dd82b 100755 --- a/demos/declarative/samegame/content/samegame.js +++ b/demos/declarative/samegame/content/samegame.js @@ -1,5 +1,4 @@ /* This script file handles the game logic */ - //Note that X/Y referred to here are in game coordinates var maxX = 10;//Nums are for tileSize 40 var maxY = 15; @@ -7,19 +6,8 @@ var tileSize = 40; var maxIndex = maxX*maxY; var board = new Array(maxIndex); var tileSrc = "content/BoomBlock.qml"; -var swapped = false; - -var compSrc; var component; -function swapTileSrc(){ - if(tileSrc == "content/SpinBlock.qml"){ - tileSrc = "content/BoomBlock.qml"; - }else{ - tileSrc = "content/SpinBlock.qml"; - } -} - //Index function used instead of a 2D array function index(xIdx,yIdx){ return xIdx + (yIdx * maxX); @@ -33,11 +21,6 @@ function initBoard() board[i].destroy(); } - //Game size is as many rows/cols fit in the GameCanvas - maxX = Math.floor(gameCanvas.width/tileSize); - maxY = Math.floor(gameCanvas.height/tileSize); - maxIndex = maxX*maxY; - //Initialize Board board = new Array(maxIndex); gameCanvas.score = 0; @@ -47,43 +30,21 @@ function initBoard() startCreatingBlock(xIdx,yIdx); } } - //TODO: a flag that handleMouse uses to ignore clicks when we're loading } var fillFound;//Set after a floodFill call to the number of tiles found -var floodBoard;//Set to 1 if the floodFill ticks off that node (mostly used by floodFill) - -var lastHoveredIdx = -2 -function handleHover(xIdx,yIdx, btn) -{ - //Turn UI x,y into Game x,y - if(index(xIdx, yIdx) == lastHoveredIdx) - return; - //if(btn != 0) - // return; - //Sets 'selected' on tile underneath and all connected - floodFill(xIdx, yIdx, -1, "hover"); - //Could use the fillFound value to tell the player how many stones/points - - //Resets any previously selected - if(board[lastHoveredIdx] != null){ - lastX = lastHoveredIdx % maxX; - lastY = Math.floor(lastHoveredIdx / maxX); - floodFill(lastX, lastY, -1, "unhover"); - } - lastHoveredIdx = index(xIdx, yIdx); -} - +var floodBoard;//Set to 1 if the floodFill reaches off that node //NOTE: Be careful with vars named x,y, as the calling object's x,y are still in scope -function handleClick(xIdx,yIdx) +function handleClick(x,y) { + 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; - //If it's a valid tile, remove it and all connected - //floodFill does nothing if it's not connected to any other tiles. - floodFill(xIdx,yIdx, -1, "kill"); + //If it's a valid tile, remove it and all connected (does nothing if it's not connected) + floodFill(xIdx,yIdx, -1); if(fillFound <= 0) return; gameCanvas.score += (fillFound - 1) * (fillFound - 1); @@ -91,18 +52,7 @@ function handleClick(xIdx,yIdx) victoryCheck(); } -/* - the floodFill function does something on all tiles connected to the - given Game position. Connected requires the adjacency of one or more - tiles of the same type. Note that if there is no tile, or the tile - is not adjacent to a similar typed tile, then it will not do anything. - - Since many things need this flood functionality, a string command is - given telling it what to do with these tiles. - - cmd = "kill" is the removal case, cmd = "hover" sets selection -*/ -function floodFill(xIdx,yIdx,type, cmd) +function floodFill(xIdx,yIdx,type) { if(board[index(xIdx, yIdx)] == null) return; @@ -117,29 +67,17 @@ function floodFill(xIdx,yIdx,type, cmd) } if(xIdx >= maxX || xIdx < 0 || yIdx >= maxY || yIdx < 0) return; - if(floodBoard[index(xIdx, yIdx)] == 1) + if(floodBoard[index(xIdx, yIdx)] == 1 || (!first && type != board[index(xIdx,yIdx)].type)) return; - if(!first && type != board[index(xIdx,yIdx)].type) - return; floodBoard[index(xIdx, yIdx)] = 1; - 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 + floodFill(xIdx+1,yIdx,type); + floodFill(xIdx-1,yIdx,type); + floodFill(xIdx,yIdx+1,type); + floodFill(xIdx,yIdx-1,type); + if(first==true && fillFound == 0) return;//Can't remove single tiles - } - if(cmd == "kill"){ - board[index(xIdx,yIdx)].dying = true; - board[index(xIdx,yIdx)] = null; - }else if(cmd == "hover"){ - board[index(xIdx,yIdx)].selected = true; - }else if(cmd == "unhover"){ - board[index(xIdx,yIdx)].selected = false; - }else{ - print ("Flood Error"); - } + board[index(xIdx,yIdx)].dying = true; + board[index(xIdx,yIdx)] = null; fillFound += 1; } @@ -191,17 +129,12 @@ function victoryCheck() if(deservesBonus) gameCanvas.score += 500; //Checks for game over - if(deservesBonus || noMoreMoves()){ + if(deservesBonus || !(floodMoveCheck(0,maxY-1, -1))){ dialog.text = "Game Over. Your score is " + gameCanvas.score; dialog.opacity = 1; } } -function noMoreMoves() -{ - return !floodMoveCheck(0, maxY-1, -1); -} - //only floods up and right, to see if it can find adjacent same-typed tiles function floodMoveCheck(xIdx, yIdx, type) { @@ -212,15 +145,13 @@ function floodMoveCheck(xIdx, yIdx, type) myType = board[index(xIdx, yIdx)].type; if(type == myType) return true; - aT = myType; - bT = myType; - return floodMoveCheck(xIdx + 1, yIdx, aT) || floodMoveCheck(xIdx, yIdx - 1, bT); + return floodMoveCheck(xIdx + 1, yIdx, myType) || + floodMoveCheck(xIdx, yIdx - 1, board[index(xIdx,yIdx)].type); } //If the component isn't ready, then the signal doesn't include the game x,y //So we store any x,y sent that we couldn't create at the time, and use those //if we are triggered by the signal. -//Need a simpler method of doing this? var waitStack = new Array(maxIndex); var waitTop = -1; @@ -263,15 +194,11 @@ function finishCreatingBlock(xIdx,yIdx){ } function startCreatingBlock(xIdx,yIdx){ - if(component!=null && compSrc == tileSrc){ + if(component!=null){ 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; -- cgit v0.12 From 0cdd8518090be320fa89efaa11ced32215cc2ccc Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Tue, 28 Jul 2009 12:56:11 +1000 Subject: Make private stuff public commit 752a15ca makes some stuff private that is needed to be public. Moving some stuff back to public until we make a real decision (on how apps can interact with the engine). --- src/declarative/fx/qfxitem.cpp | 2 +- src/declarative/qml/qmlcomponentjs.cpp | 2 +- src/declarative/qml/qmlcontext.cpp | 2 +- src/declarative/qml/qmlengine.cpp | 27 +++++++++++++++++---------- src/declarative/qml/qmlengine.h | 2 ++ src/declarative/qml/qmlengine_p.h | 3 --- src/declarative/qml/qmlexpression.cpp | 2 +- src/declarative/util/qmlscript.cpp | 2 +- 8 files changed, 24 insertions(+), 18 deletions(-) diff --git a/src/declarative/fx/qfxitem.cpp b/src/declarative/fx/qfxitem.cpp index f8ed7b4..09ae22c 100644 --- a/src/declarative/fx/qfxitem.cpp +++ b/src/declarative/fx/qfxitem.cpp @@ -821,7 +821,7 @@ void QFxItem::qmlLoaded() QFxItem* ret = qobject_cast(o); if (ret) { ret->setItemParent(this); - QScriptValue v = QmlEnginePrivate::getScriptEngine(qmlEngine(this))->newQObject(ret); + QScriptValue v = QmlEngine::getScriptEngine(qmlEngine(this))->newQObject(ret); emit newChildCreated(d->_qmlnewloading.at(i).toString(),v); } diff --git a/src/declarative/qml/qmlcomponentjs.cpp b/src/declarative/qml/qmlcomponentjs.cpp index df3e834..2552f78 100644 --- a/src/declarative/qml/qmlcomponentjs.cpp +++ b/src/declarative/qml/qmlcomponentjs.cpp @@ -84,7 +84,7 @@ QScriptValue QmlComponentJS::createObject() { Q_D(QmlComponentJS); QObject* ret = create(d->ctxt); - return QmlEnginePrivate::qmlScriptObject(ret, d->engine); + return QmlEngine::qmlScriptObject(ret, d->engine); } /*! diff --git a/src/declarative/qml/qmlcontext.cpp b/src/declarative/qml/qmlcontext.cpp index dabaa5e..bf549d8 100644 --- a/src/declarative/qml/qmlcontext.cpp +++ b/src/declarative/qml/qmlcontext.cpp @@ -106,7 +106,7 @@ void QmlContextPrivate::init() parent->d_func()->childContexts.insert(q); //set scope chain - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValue scopeObj = scriptEngine->newObject(QmlEnginePrivate::get(engine)->contextClass, scriptEngine->newVariant(QVariant::fromValue((QObject*)q))); if (!parent) diff --git a/src/declarative/qml/qmlengine.cpp b/src/declarative/qml/qmlengine.cpp index 321feb9..0016144 100644 --- a/src/declarative/qml/qmlengine.cpp +++ b/src/declarative/qml/qmlengine.cpp @@ -520,6 +520,13 @@ void QmlInstanceDeclarativeData::destroyed(QObject *object) delete this; } +/*! A way to access the QScriptEngine, so that you can add your own objects. + This function is likely to be removed upon further reflection. +*/ +QScriptEngine *QmlEngine::getScriptEngine(QmlEngine *e) +{ + return &e->d_func()->scriptEngine; +} /*! \internal */ /* QScriptEngine *QmlEngine::scriptEngine() @@ -533,14 +540,14 @@ QScriptEngine *QmlEngine::scriptEngine() Creates a QScriptValue allowing you to use \a object in QML script. \a engine is the QmlEngine it is to be created in. - The QScriptValue returned is a QtScript Object, not a QtScript QObject, due - to the special needs of QML requiring more functionality than a standard + The QScriptValue returned is a Qml Script Object, not a QtScript QObject, + due to the special needs of QML requiring more functionality than a standard QtScript QObject. */ -QScriptValue QmlEnginePrivate::qmlScriptObject(QObject* object, +QScriptValue QmlEngine::qmlScriptObject(QObject* object, QmlEngine* engine) { - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); return scriptEngine->newObject(new QmlObjectScriptClass(engine), scriptEngine->newQObject(object)); } @@ -684,13 +691,13 @@ QScriptValue QmlEnginePrivate::createQmlObject(QScriptContext *ctxt, QScriptEngi if(obj) { obj->setParent(parentArg); obj->setProperty("parent", QVariant::fromValue(parentArg)); - return qmlScriptObject(obj, activeEngine); + return QmlEngine::qmlScriptObject(obj, activeEngine); } return engine->nullValue(); } QmlScriptClass::QmlScriptClass(QmlEngine *bindengine) -: QScriptClass(QmlEnginePrivate::getScriptEngine(bindengine)), +: QScriptClass(QmlEngine::getScriptEngine(bindengine)), engine(bindengine) { } @@ -780,7 +787,7 @@ QScriptValue QmlContextScriptClass::property(const QScriptValue &object, uint basicId = id & QmlScriptClass::ClassIdMask; - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QmlEnginePrivate *ep = QmlEnginePrivate::get(engine); switch (basicId) { @@ -840,7 +847,7 @@ void QmlContextScriptClass::setProperty(QScriptValue &object, int objIdx = (id & QmlScriptClass::ClassIdSelectorMask) >> 24; QObject *obj = bindContext->d_func()->defaultObjects.at(objIdx); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValue oldact = scriptEngine->currentContext()->activationObject(); scriptEngine->currentContext()->setActivationObject(scriptEngine->globalObject()); @@ -948,7 +955,7 @@ QmlObjectScriptClass::QmlObjectScriptClass(QmlEngine *bindEngine) : QmlScriptClass(bindEngine) { engine = bindEngine; - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(bindEngine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(bindEngine); prototypeObject = scriptEngine->newObject(); prototypeObject.setProperty(QLatin1String("destroy"), scriptEngine->newFunction(QmlObjectDestroy)); @@ -1020,7 +1027,7 @@ void QmlObjectScriptClass::setProperty(QScriptValue &object, qWarning() << "Set QmlObject Property" << name.toString() << value.toVariant(); #endif - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValue oldact = scriptEngine->currentContext()->activationObject(); scriptEngine->currentContext()->setActivationObject(scriptEngine->globalObject()); diff --git a/src/declarative/qml/qmlengine.h b/src/declarative/qml/qmlengine.h index 6066059..a3457f0 100644 --- a/src/declarative/qml/qmlengine.h +++ b/src/declarative/qml/qmlengine.h @@ -86,6 +86,8 @@ public: static QmlContext *contextForObject(const QObject *); static void setContextForObject(QObject *, QmlContext *); + static QScriptValue qmlScriptObject(QObject*, QmlEngine*); + static QScriptEngine *getScriptEngine(QmlEngine *e); private: Q_DECLARE_PRIVATE(QmlEngine) }; diff --git a/src/declarative/qml/qmlengine_p.h b/src/declarative/qml/qmlengine_p.h index 18cdd83..7b459e9 100644 --- a/src/declarative/qml/qmlengine_p.h +++ b/src/declarative/qml/qmlengine_p.h @@ -193,12 +193,9 @@ public: bool resolveType(const Imports&, const QByteArray& type, QmlType** type_return, QUrl* url_return, ImportedNamespace** ns_return=0) const; void resolveTypeInNamespace(ImportedNamespace*, const QByteArray& type, QmlType** type_return, QUrl* url_return ) const; - - static QScriptValue qmlScriptObject(QObject*, QmlEngine*); static QScriptValue createComponent(QScriptContext*, QScriptEngine*); static QScriptValue createQmlObject(QScriptContext*, QScriptEngine*); - static QScriptEngine *getScriptEngine(QmlEngine *e) { return &e->d_func()->scriptEngine; } static QmlEnginePrivate *get(QmlEngine *e) { return e->d_func(); } }; diff --git a/src/declarative/qml/qmlexpression.cpp b/src/declarative/qml/qmlexpression.cpp index 2c06efa..990722a 100644 --- a/src/declarative/qml/qmlexpression.cpp +++ b/src/declarative/qml/qmlexpression.cpp @@ -240,7 +240,7 @@ QVariant QmlExpressionPrivate::evalQtScript() if (me) ctxtPriv->defaultObjects.insert(ctxtPriv->highPriorityCount, me); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptValueList oldScopeChain = scriptEngine->currentContext()->scopeChain(); diff --git a/src/declarative/util/qmlscript.cpp b/src/declarative/util/qmlscript.cpp index ca9aad5..df05d8e 100644 --- a/src/declarative/util/qmlscript.cpp +++ b/src/declarative/util/qmlscript.cpp @@ -185,7 +185,7 @@ void QmlScriptPrivate::addScriptToEngine(const QString &script, const QString &s Q_Q(QmlScript); QmlEngine *engine = qmlEngine(q); QmlContext *context = qmlContext(q); - QScriptEngine *scriptEngine = QmlEnginePrivate::getScriptEngine(engine); + QScriptEngine *scriptEngine = QmlEngine::getScriptEngine(engine); QScriptContext *currentContext = scriptEngine->currentContext(); QScriptValueList oldScopeChain = currentContext->scopeChain(); -- cgit v0.12