You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pivot.apache.org by gb...@apache.org on 2009/04/13 22:28:24 UTC

svn commit: r764602 - in /incubator/pivot/trunk: tutorials/src/pivot/tutorials/Demo.java wtk/src/pivot/wtk/effects/DropShadowDecorator.java

Author: gbrown
Date: Mon Apr 13 20:28:24 2009
New Revision: 764602

URL: http://svn.apache.org/viewvc?rev=764602&view=rev
Log:
Optimize DropShadowDecorator so it only creates a new shadow image when the component's size changes.

Modified:
    incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
    incubator/pivot/trunk/wtk/src/pivot/wtk/effects/DropShadowDecorator.java

Modified: incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java?rev=764602&r1=764601&r2=764602&view=diff
==============================================================================
--- incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java (original)
+++ incubator/pivot/trunk/tutorials/src/pivot/tutorials/Demo.java Mon Apr 13 20:28:24 2009
@@ -280,7 +280,7 @@
                     @Override
                     public boolean mouseDown(Component component, Mouse.Button button, int x, int y) {
                         if (button == Mouse.Button.RIGHT) {
-                            menuPopup.open(display, component.mapPointToAncestor(display, x, y));
+                            menuPopup.open(window, component.mapPointToAncestor(display, x, y));
                         }
 
                         return false;

Modified: incubator/pivot/trunk/wtk/src/pivot/wtk/effects/DropShadowDecorator.java
URL: http://svn.apache.org/viewvc/incubator/pivot/trunk/wtk/src/pivot/wtk/effects/DropShadowDecorator.java?rev=764602&r1=764601&r2=764602&view=diff
==============================================================================
--- incubator/pivot/trunk/wtk/src/pivot/wtk/effects/DropShadowDecorator.java (original)
+++ incubator/pivot/trunk/wtk/src/pivot/wtk/effects/DropShadowDecorator.java Mon Apr 13 20:28:24 2009
@@ -16,7 +16,6 @@
  */
 package pivot.wtk.effects;
 
-import java.awt.AlphaComposite;
 import java.awt.Color;
 import java.awt.Graphics2D;
 import java.awt.geom.AffineTransform;
@@ -43,9 +42,7 @@
     private Color shadowColor = Color.BLACK;
     private float shadowOpacity = 0.33f;
 
-    private Graphics2D graphics = null;
-    private BufferedImage componentImage = null;
-    private Graphics2D componentImageGraphics = null;
+    private BufferedImage shadowImage = null;
 
     public DropShadowDecorator() {
         this(5, 5, 5);
@@ -172,42 +169,29 @@
     }
 
     public Graphics2D prepare(Component component, Graphics2D graphics) {
-        this.graphics = graphics;
-
         int width = component.getWidth();
         int height = component.getHeight();
 
-        if (width > 0
-            && height > 0) {
-            if (componentImage == null
-                || componentImage.getWidth() != width
-                || componentImage.getHeight() != height) {
-                componentImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
-            }
-
-            componentImageGraphics = componentImage.createGraphics();
-            componentImageGraphics.setClip(graphics.getClip());
-
-            componentImageGraphics.setComposite(AlphaComposite.Clear);
-            componentImageGraphics.fillRect(0, 0, componentImage.getWidth(), componentImage.getHeight());
-
-            componentImageGraphics.setComposite(AlphaComposite.SrcOver);
+        if (shadowImage == null
+            || shadowImage.getWidth() != width + 2 * blurRadius
+            || shadowImage.getHeight() != height + 2 * blurRadius) {
+            // Recreate the shadow
+            BufferedImage rectangleImage = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
+            Graphics2D rectangleImageGraphics = rectangleImage.createGraphics();
+            rectangleImageGraphics.setColor(Color.BLACK);
+            rectangleImageGraphics.fillRect(0, 0, width, height);
+            rectangleImageGraphics.dispose();
 
-            graphics = componentImageGraphics;
+            shadowImage = createShadow(rectangleImage);
         }
 
+        graphics.drawImage(shadowImage, xOffset - blurRadius, yOffset - blurRadius, null);
+
         return graphics;
     }
 
     public void update() {
-        if (componentImage != null) {
-            componentImageGraphics.dispose();
-
-            BufferedImage shadowImage = createShadow(componentImage);
-
-            graphics.drawImage(shadowImage, xOffset - blurRadius, yOffset - blurRadius, null);
-            graphics.drawImage(componentImage, 0, 0, null);
-        }
+        // No-op
     }
 
     public Bounds getBounds(Component component) {