Revision: 812
Author: allain.lalonde
Date: Fri Oct 23 14:31:51 2009
Log: As per Issue # 27, I'm making the repainting of the canvas lazier.
During an animation it'll record what bounds have actually been dirty, then  
rather than repainting the entire scene, it'll only paint the region that's  
been dirtied.
http://code.google.com/p/piccolo2d/source/detail?r=812

Modified:
  /piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java

=======================================
---  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Thu Oct 22 19:28:10 2009
+++  
/piccolo2d.java/trunk/core/src/main/java/edu/umd/cs/piccolo/PCanvas.java        
 
Fri Oct 23 14:31:51 2009
@@ -35,6 +35,7 @@
  import java.awt.Graphics2D;
  import java.awt.KeyEventPostProcessor;
  import java.awt.KeyboardFocusManager;
+import java.awt.Rectangle;
  import java.awt.event.ActionListener;
  import java.awt.event.HierarchyEvent;
  import java.awt.event.HierarchyListener;
@@ -564,6 +565,8 @@

          repaint((int) bounds.x, (int) bounds.y, (int) bounds.width, (int)  
bounds.height);
      }
+
+    private PBounds repaintBounds = new PBounds();

      /**
       * {...@inheritdoc}
@@ -580,6 +583,10 @@
              g2.setColor(getBackground());
              g2.fillRect(0, 0, getWidth(), getHeight());
          }
+
+        if (getAnimating()) {
+            repaintBounds.add(g2.getClipBounds());
+        }

          // create new paint context and set render quality to lowest common
          // denominator render quality.
@@ -596,16 +603,16 @@
              paintContext.setRenderQuality(normalRenderQuality);
          }

-        // paint piccolo
          camera.fullPaint(paintContext);

          // if switched state from animating to not animating invalidate the
-        // entire
-        // screen so that it will be drawn with the default instead of  
animating
-        // render quality.
+        // repaint bounds so that it will be drawn with the default  
instead of
+        // animating render quality.
          if (!getAnimating() && animatingOnLastPaint) {
-            repaint();
-        }
+            repaint(repaintBounds);
+            repaintBounds.reset();
+        }
+
          animatingOnLastPaint = getAnimating();

          PDebug.endProcessingOutput(g2);

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

Reply via email to