[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [gcompris/gsoc_pulkit_digital_electricity] src/activities/digital_electricity: digital_electricity: 
From:       Rudra Nil Basu <null () kde ! org>
Date:       2017-08-22 17:06:18
Message-ID: E1dkCd8-00088n-0H () code ! kde ! org
[Download RAW message or body]

Git commit 3d8657914e41cf3fe4c77a4e28bdf3e5ec90509d by Rudra Nil Basu.
Committed on 22/08/2017 at 15:31.
Pushed by rudranilbasu into branch 'gsoc_pulkit_digital_electricity'.

digital_electricity: Move in the playArea

Implemented moving in the playArea using the arrow keys. On pressing the
arrow keys, we check on which side we should be moving and if they are
restricted to the given frame, the corresponding move is made.

The positioning of the components should also be relative to the current
zoom ratio, which is implemented by:

  components[i].posX *= zoomRatio
  components[i].posY *= zoomRatio

whenever there is zoom in or out.

Signed-off-by: Rudra Nil Basu <rudra.nil.basu.1996@gmail.com>

M  +12   -0    src/activities/digital_electricity/DigitalElectricity.qml
M  +70   -2    src/activities/digital_electricity/digital_electricity.js

https://commits.kde.org/gcompris/3d8657914e41cf3fe4c77a4e28bdf3e5ec90509d

diff --git a/src/activities/digital_electricity/DigitalElectricity.qml \
b/src/activities/digital_electricity/DigitalElectricity.qml index db975bcd..95a77cb1 \
                100644
--- a/src/activities/digital_electricity/DigitalElectricity.qml
+++ b/src/activities/digital_electricity/DigitalElectricity.qml
@@ -56,6 +56,18 @@ ActivityBase {
             if (event.key == Qt.Key_Minus) {
                 Activity.zoomOut()
             }
+            if (event.key == Qt.Key_Right) {
+                Activity.move(Activity.direction.RIGHT)
+            }
+            if (event.key == Qt.Key_Left) {
+                Activity.move(Activity.direction.LEFT)
+            }
+            if (event.key == Qt.Key_Up) {
+                Activity.move(Activity.direction.UP)
+            }
+            if (event.key == Qt.Key_Down) {
+                Activity.move(Activity.direction.DOWN)
+            }
         }
 
         // Add here the QML items you need to access in javascript
diff --git a/src/activities/digital_electricity/digital_electricity.js \
b/src/activities/digital_electricity/digital_electricity.js index 8711337c..d480c774 \
                100644
--- a/src/activities/digital_electricity/digital_electricity.js
+++ b/src/activities/digital_electricity/digital_electricity.js
@@ -43,6 +43,22 @@ var minZoom = 0.5
 var defaultZoom = 1
 var zoomStep = 0.25
 
+var direction = {
+    LEFT: -1,
+    RIGHT: 1,
+    UP: -2,
+    DOWN: 2
+}
+
+var viewPort = {
+    leftExtreme: 0,
+    rightExtreme: 2,
+    topExtreme: 0,
+    bottomExtreme: 2.5,
+    leftEdge: 0,
+    topEdge: 0
+}
+
 function start(items_) {
 
     items = items_
@@ -110,8 +126,8 @@ function initLevel() {
             components[index] = staticElectricalComponent.createObject(
                         items.playArea, {
                           "index": index,
-                          "posX": levelProperties.playAreaComponentPositionX[i],
-                          "posY": levelProperties.playAreaComponentPositionY[i],
+                          "posX": levelProperties.playAreaComponentPositionX[i] * \
currentZoom, +                          "posY": \
levelProperties.playAreaComponentPositionY[i] * currentZoom,  "imgSrc": \
                currentPlayAreaComponent.imageName,
                           "toolTipTxt": currentPlayAreaComponent.toolTipText,
                           "imgWidth": currentPlayAreaComponent.width * currentZoom,
@@ -359,11 +375,63 @@ function zoomOut() {
 
 function updateComponentDimension(zoomRatio) {
     for (var i = 0; i < components.length; i++) {
+        components[i].posX *= zoomRatio
+        components[i].posY *= zoomRatio
         components[i].imgWidth *= zoomRatio
         components[i].imgHeight *= zoomRatio
     }
 }
 
+function move(_direction) {
+    var x, y
+    x = 0
+    y = 0
+    if (_direction == direction.RIGHT) {
+        x = 0.1
+    } else if (_direction == direction.LEFT) {
+        x = -0.1
+    } else if (_direction == direction.UP) {
+        y = -0.1
+    } else if (_direction == direction.DOWN) {
+        y = 0.1
+    }
+
+    if (x == 0.1) {
+        var viewPortRightEdge = Math.round(((viewPort.leftEdge + 0.1) + (1 / \
currentZoom)) * 100) / 100 +        if ( viewPortRightEdge > viewPort.rightExtreme) {
+            return
+        } else {
+            viewPort.leftEdge = Math.round((viewPort.leftEdge + 0.1) * 100) / 100
+        }
+    } else if (x == -0.1) {
+        var viewportLeftEdge = Math.round(((viewPort.leftEdge - 0.1)) * 100) / 100
+        if (viewportLeftEdge < viewPort.leftExtreme) {
+            return
+        } else {
+            viewPort.leftEdge = Math.round((viewPort.leftEdge - 0.1) * 100) / 100
+        }
+    } else if (y == 0.1) {
+        var viewPortBottomEdge = Math.round(((viewPort.topEdge + 0.1) + (1 / \
currentZoom)) * 100) / 100 +        if (viewPortBottomEdge > viewPort.bottomExtreme) \
{ +            return
+        } else {
+            viewPort.topEdge = Math.round((viewPort.topEdge + 0.1) * 100) / 100
+        }
+    } else if (y == -0.1) {
+        var viewportTopEdge = Math.round((viewPort.topEdge - 0.1) * 100) / 100
+        if (viewportTopEdge < viewPort.topExtreme) {
+            return
+        } else {
+            viewPort.topEdge = Math.round((viewPort.topEdge - 0.1) * 100) / 100
+        }
+    }
+
+    for (var i = 0; i < components.length; i++) {
+        components[i].posX -= x
+        components[i].posY -= y
+    }
+}
+
 function nextLevel() {
 
     if(numberOfLevel < ++currentLevel ) {


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic