Revision: 1053
Author: allain.lalonde
Date: Thu Aug 26 12:57:21 2010
Log: Fixing breaking unit test in PText and refactoring examples to use common scene counter
http://code.google.com/p/piccolo2d/source/detail?r=1053

Added:
 /piccolo2d.js/trunk/examples/examples.js
Modified:
 /piccolo2d.js/trunk/examples/activities.html
 /piccolo2d.js/trunk/examples/calendar.html
 /piccolo2d.js/trunk/piccolo2d.js
 /piccolo2d.js/trunk/test.html

=======================================
--- /dev/null
+++ /piccolo2d.js/trunk/examples/examples.js    Thu Aug 26 12:57:21 2010
@@ -0,0 +1,45 @@
+/*
+Copyright (c) 2008-2009, Piccolo2D project, http://piccolo2d.org
+Copyright (c) 1998-2008, University of Maryland
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided
+that the following conditions are met:
+
+Redistributions of source code must retain the above copyright notice, this list of conditions
+and the following disclaimer.
+
+Redistributions in binary form must reproduce the above copyright notice, this list of conditions +and the following disclaimer in the documentation and/or other materials provided with the
+distribution.
+
+None of the name of the University of Maryland, the name of the Piccolo2D project, or the names of its +contributors may be used to endorse or promote products derived from this software without specific
+prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED +WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A +PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR +ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR +TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+//This file is used by the examples for common tasks like counting total number of nodes in a scene, etc.
+$(function() {
+    function countNodes(node) {
+       var result = 1;
+
+       for (var i=0; i<node.children.length; i++) {
+         result += countNodes(node.children[i]);
+       }
+
+       return result;
+    }
+
+    var nodeCount = countNodes(pCanvas.camera.layers[0]);
+
+    $("#totalNodeCount").text(nodeCount);
+});
=======================================
--- /piccolo2d.js/trunk/examples/activities.html        Thu Aug 26 12:26:01 2010
+++ /piccolo2d.js/trunk/examples/activities.html        Thu Aug 26 12:57:21 2010
@@ -85,13 +85,17 @@

           return true;
         }
-      }));
-    }
+      }));
+    }
+
+
   </script>
+  <script type="text/javascript" src="examples.js"></script>
   <h1>Activity Example</h1>
   <p>This example contains:</p>
   <ul>
- <li>1000 Rectangles being scheduled every 1.5 seconds for 1 second.</li> + <li><strong>1000</strong> Rectangles being scheduled every 1.5 seconds for 1 second.</li> + <li><strong id="totalNodeCount">???</strong> total nodes in the scene.</li>
   </ul>
 </body>
 </html>
=======================================
--- /piccolo2d.js/trunk/examples/calendar.html  Thu Aug 26 12:26:01 2010
+++ /piccolo2d.js/trunk/examples/calendar.html  Thu Aug 26 12:57:21 2010
@@ -117,7 +117,7 @@
                     var currentDay = 0;
                     while (currentDay < daysInMonth) {
var dayLabel = currentDay < 0 ? "" : (currentDay + 1); - var tasks = ["Testing 1, 2, 3", "Testing Again", "Kilroy was here", "Random again", "Testing 1, 2, 3", "Testing Again", "Kilroy was here", "Random again"]; + var tasks = ["Woot", "Eat more fish", "Testing 1, 2, 3", "Testing Again", "Kilroy was here", "Random again", "Testing 1, 2, 3", "Testing Again", "Kilroy was here", "Random again"]; this.addChild(new Day(dayLabel, tasks).translate(columnNumber*columnWidth, currentY).scale(0.2));
                         currentDay += 1;
                         columnNumber += 1;
@@ -187,9 +187,10 @@
             });
         }
     </script>
+    <script type="text/javascript" src="examples.js"></script>
     <h1>Calendar Example</h1>
     <p>Benchmarking example mostly.</p>

- <p># of nodes being rendered is <strong>4123</strong> = 365 * 11 + 12 * (2 + 7)!</p> + <p><strong id="totalNodeCount">????</strong> total nodes in the scene.</p>
 </body>
 </html>
=======================================
--- /piccolo2d.js/trunk/piccolo2d.js    Thu Aug 26 12:25:46 2010
+++ /piccolo2d.js/trunk/piccolo2d.js    Thu Aug 26 12:57:21 2010
@@ -516,8 +516,8 @@
             }
         },

-        paint: function (ctx) {
-            if (this.globalFullBounds.height / ctx.displayScale  < 3) {
+        paint: function (ctx) {
+ if (this.getGlobalFullBounds().height * ctx.displayScale < 3) {
                 return;
             }

@@ -601,8 +601,9 @@
             ctx.save();

             this.viewTransform.applyTo(ctx);
+            ctx.displayScale = this.viewTransform.getScale();
+
             var viewInverse = this.viewTransform.getInverse();
-            ctx.displayScale = viewInverse.getScale();
             ctx.clipBounds = viewInverse.transform(this.bounds);

             for (var i = 0; i < this.layers.length; i += 1) {
=======================================
--- /piccolo2d.js/trunk/test.html       Thu Aug 26 11:02:54 2010
+++ /piccolo2d.js/trunk/test.html       Thu Aug 26 12:57:21 2010
@@ -495,11 +495,22 @@

         test("draws text on graphics context", function() {
           var t = new PText("Hello");
-          var ctx = mock("fillText");
+          var ctx = mock("fillText", "save", "restore", "transform");
+          ctx.clipBounds = new PBounds(0, 0, 100, 100);
+          ctx.displayScale = 1;
           t.paint(ctx);
           same(ctx.calls.fillText[0], ["Hello", 0, 0]);
         });

+        test("does not draw text when too small", function() {
+          var t = new PText("Hello");
+          var ctx = mock("fillText", "save", "restore", "transform");
+          ctx.clipBounds = new PBounds(0, 0, 100, 100);
+          ctx.displayScale = 0.01;
+          t.paint(ctx);
+ equal(ctx.calls.fillText.length, 0, "fillText should not have been called");
+        });
+
         test("FullBounds are empty when text is empty", function() {
           var t = new PText("");
           var bounds = t.getFullBounds();

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

Reply via email to