[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-20 18:34:16
Message-ID: E1djV3A-0005fk-7P () code ! kde ! org
[Download RAW message or body]

Git commit b8c8138708e9bf8dc8efe4953fc58ed038873ed7 by Rudra Nil Basu.
Committed on 20/08/2017 at 18:28.
Pushed by rudranilbasu into branch 'gsoc_pulkit_digital_electricity'.

digital_electricity: Implemented zooming of components

Currently zooming is done via "+" and "-" keys (icons will be added
shortly) for zoom in and zoom out respectively.

Zoom in is done in the zoomIn() function where the currentZoom is
updated to it's value in between maxZoom and minZoom. and the final zoom
ratio is calculated, which is multiplied by the imgWidth and imgHwight,
thus updating the values of the dimensions of the components present in the
playArea.

Similar procedure is done for the ZoomOut, only in this case, the
currentZoom is subtracted by the zoomStep.

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

M  +9    -0    src/activities/digital_electricity/DigitalElectricity.qml
M  +37   -4    src/activities/digital_electricity/digital_electricity.js

https://commits.kde.org/gcompris/b8c8138708e9bf8dc8efe4953fc58ed038873ed7

diff --git a/src/activities/digital_electricity/DigitalElectricity.qml \
b/src/activities/digital_electricity/DigitalElectricity.qml index 302f3b98..db975bcd \
                100644
--- a/src/activities/digital_electricity/DigitalElectricity.qml
+++ b/src/activities/digital_electricity/DigitalElectricity.qml
@@ -49,6 +49,15 @@ ActivityBase {
             activity.stop.connect(stop)
         }
 
+        Keys.onPressed: {
+            if (event.key == Qt.Key_Plus) {
+                Activity.zoomIn()
+            }
+            if (event.key == Qt.Key_Minus) {
+                Activity.zoomOut()
+            }
+        }
+
         // Add here the QML items you need to access in javascript
         QtObject {
             id: items
diff --git a/src/activities/digital_electricity/digital_electricity.js \
b/src/activities/digital_electricity/digital_electricity.js index 0c87d25b..067df79c \
                100644
--- a/src/activities/digital_electricity/digital_electricity.js
+++ b/src/activities/digital_electricity/digital_electricity.js
@@ -37,6 +37,12 @@ var connected = []
 var determiningComponents = []
 var processingAnswer
 
+var currentZoom
+var maxZoom = 1
+var minZoom = 0.5
+var defaultZoom = 1
+var zoomStep = 0.25
+
 function start(items_) {
 
     items = items_
@@ -76,6 +82,8 @@ function initLevel() {
     deselect()
     updateToolTip("")
 
+    currentZoom = defaultZoom
+
     if (!items.isTutorialMode) {
         items.tutorialInstruction.visible = false
         loadFreeMode(sizeMultiplier)
@@ -106,8 +114,8 @@ function initLevel() {
                           "posY": levelProperties.playAreaComponentPositionY[i],
                           "imgSrc": currentPlayAreaComponent.imageName,
                           "toolTipTxt": currentPlayAreaComponent.toolTipText,
-                          "imgWidth": currentPlayAreaComponent.width,
-                          "imgHeight": currentPlayAreaComponent.height,
+                          "imgWidth": currentPlayAreaComponent.width * currentZoom,
+                          "imgHeight": currentPlayAreaComponent.height * \
currentZoom,  "destructible": false
                         });
         }
@@ -331,6 +339,31 @@ function checkAnswer() {
     }
 }
 
+function zoomIn() {
+    var previousZoom = currentZoom
+    currentZoom += zoomStep
+    if (currentZoom > maxZoom)
+        currentZoom = maxZoom
+    var zoomRatio = currentZoom / previousZoom
+    updateComponentDimension(zoomRatio)
+}
+
+function zoomOut() {
+    var previousZoom = currentZoom
+    currentZoom -= zoomStep
+    if (currentZoom < minZoom)
+        currentZoom = minZoom
+    var zoomRatio = currentZoom / previousZoom
+    updateComponentDimension(zoomRatio)
+}
+
+function updateComponentDimension(zoomRatio) {
+    for (var i = 0; i < components.length; i++) {
+        components[i].imgWidth *= zoomRatio
+        components[i].imgHeight *= zoomRatio
+    }
+}
+
 function nextLevel() {
 
     if(numberOfLevel < ++currentLevel ) {
@@ -381,8 +414,8 @@ function createComponent(x, y, componentIndex) {
                             "posY": y,
                             "imgSrc": component.imageName,
                             "toolTipTxt": component.toolTipTxt,
-                            "imgWidth": component.imageWidth,
-                            "imgHeight": component.imageHeight,
+                            "imgWidth": component.imageWidth * currentZoom,
+                            "imgHeight": component.imageHeight * currentZoom,
                             "destructible": true
                         });
 


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

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