Revision: 1049
Author: allain.lalonde
Date: Thu Aug 26 11:38:14 2010
Log: Adding getScale to PNode and improving events.html example a little more
http://code.google.com/p/piccolo2d/source/detail?r=1049

Modified:
 /piccolo2d.js/trunk/examples/events.html
 /piccolo2d.js/trunk/piccolo2d.js

=======================================
--- /piccolo2d.js/trunk/examples/events.html    Thu Aug 26 11:02:54 2010
+++ /piccolo2d.js/trunk/examples/events.html    Thu Aug 26 11:38:14 2010
@@ -67,15 +67,19 @@
           layer.addChild(new ZoomNode({
fillStyle: "rgb("+Math.round(Math.random()*255)+","+Math.round(Math.random()*255)+","+Math.round(Math.random()*255)+")",
             bounds: new PBounds(0,0, 100, 100),
-          }).scale(0.25).translate(30*x, 30*y));
+          }).scale(0.25).translate(30*x + 1.25, 30*y + 1.25));
         }
       }

       layer.addListener({
         click: function(event) {
-          var globalTransform = event.pickedNodes[0].getGlobalTransform();
+          var clickedNode = event.pickedNodes[0];
+          var globalTransform = clickedNode.getGlobalTransform();
+          var focusBounds = clickedNode.getGlobalFullBounds();
           var inverse = globalTransform.getInverse();
-
+          console.log(clickedNode.getScale());
+ inverse.translate((camera.bounds.width-focusBounds.width/clickedNode.getScale())/2, (camera.bounds.height-focusBounds.height/clickedNode.getScale())/2);
+
           camera.animateViewToTransform(inverse, 500);
         },

=======================================
--- /piccolo2d.js/trunk/piccolo2d.js    Thu Aug 26 11:02:54 2010
+++ /piccolo2d.js/trunk/piccolo2d.js    Thu Aug 26 11:38:14 2010
@@ -430,7 +430,7 @@
                 var fullBounds = this.getFullBounds(),
                     currentNode = this,
                     tl = new PPoint(fullBounds.x, fullBounds.y),
- br = new PPoint(fullBounds.x + fullBounds.width, fullBounds.y + fullBounds.height); + br = new PPoint(fullBounds.x + fullBounds.width, fullBounds.y + fullBounds.height);

                 while (currentNode.parent) {
                     tl = currentNode.transform.transform(tl);
@@ -473,6 +473,14 @@
             if (this.listeners.indexOf(listener) === -1) {
                 this.listeners.push(listener);
             }
+        },
+
+        getScale: function() {
+          var p = new PPoint(0,1);
+          var tp = this.transform.transform(p);
+          tp.x -= this.transform.values[4];
+          tp.y -= this.transform.values[5];
+          return Math.sqrt(tp.x * tp.x + tp.y * tp.y);
         }
     });

--
Piccolo2D Developers Group: http://groups.google.com/group/piccolo2d-dev?hl=en

Reply via email to