Revision: 3454
          http://vexi.svn.sourceforge.net/vexi/?rev=3454&view=rev
Author:   clrg
Date:     2009-03-26 15:11:27 +0000 (Thu, 26 Mar 2009)

Log Message:
-----------
Improve align setting code + dirty on fill

Modified Paths:
--------------
    trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp

Modified: trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp
===================================================================
--- trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2009-03-26 15:10:10 UTC 
(rev 3453)
+++ trunk/core/org.vexi.core/src/org/vexi/core/Box.jpp  2009-03-26 15:11:27 UTC 
(rev 3454)
@@ -152,6 +152,10 @@
     private static final int ALIGN_LEFT              = 0x00040000;
     private static final int ALIGN_RIGHT             = 0x00080000;
     private static final int ALIGNS = ALIGN_TOP | ALIGN_BOTTOM | ALIGN_LEFT | 
ALIGN_RIGHT;
+    private static final int ALIGN_TOPLEFT = ALIGN_TOP|ALIGN_LEFT;
+    private static final int ALIGN_TOPRIGHT = ALIGN_TOP|ALIGN_RIGHT;
+    private static final int ALIGN_BOTTOMLEFT = ALIGN_BOTTOM|ALIGN_LEFT;
+    private static final int ALIGN_BOTTOMRIGHT = ALIGN_BOTTOM|ALIGN_RIGHT;
 
     private static final int ENTER_TRAP              = 0x00100000;
     private static final int LEAVE_TRAP              = 0x00200000;
@@ -961,20 +965,30 @@
     }
 
     /** set the align flags according to 'value' */
-    private void setAlign(String value) throws JSExn {
-        clear(ALIGNS);
-        //#switch (value)
-            case "topleft":     set(ALIGN_TOP | ALIGN_LEFT);
-            case "bottomleft":  set(ALIGN_BOTTOM | ALIGN_LEFT);
-            case "topright":    set(ALIGN_TOP | ALIGN_RIGHT);
-            case "bottomright": set(ALIGN_BOTTOM | ALIGN_RIGHT);
-            case "top":         set(ALIGN_TOP);
-            case "bottom":      set(ALIGN_BOTTOM);
-            case "left":        set(ALIGN_LEFT);
-            case "right":       set(ALIGN_RIGHT);
-            case "center":      set(0);
+    private boolean setAlign(JS value) throws JSExn {
+        int curalign = ALIGNS&flags;
+        int newalign = 0;
+        // special case null value
+        if (value==null) {
+            if (curalign==0) return false;
+            clear(ALIGNS);
+            return true;
+        }
+        //#switch (JSU.toString(value))
+            case "topleft":     if (curalign == ALIGN_TOPLEFT) return false; 
newalign = ALIGN_TOPLEFT;
+            case "topright":    if (curalign == ALIGN_TOPRIGHT) return false; 
newalign = ALIGN_TOPRIGHT;
+            case "bottomleft":  if (curalign == ALIGN_BOTTOMLEFT) return 
false; newalign = ALIGN_BOTTOMLEFT;
+            case "bottomright": if (curalign == ALIGN_BOTTOMRIGHT) return 
false; newalign = ALIGN_BOTTOMRIGHT;
+            case "top":         if (curalign == ALIGN_TOP) return false; 
newalign = ALIGN_TOP;
+            case "left":        if (curalign == ALIGN_LEFT) return false; 
newalign = ALIGN_LEFT;
+            case "right":       if (curalign == ALIGN_RIGHT) return false; 
newalign = ALIGN_RIGHT;
+            case "bottom":      if (curalign == ALIGN_BOTTOM) return false; 
newalign = ALIGN_BOTTOM;
+            case "center":      if (curalign == 0) return false; newalign = 0;
             default: throw new JSExn("Invalid alignment \"" + value + "\" put 
to a box");
         //#end
+        clear(ALIGNS);
+        set(newalign);
+        return true;
     }
     
     /** set the fill of a box according to 'value' */
@@ -1406,12 +1420,6 @@
         case "sendEvent":   throw new JSExn("Attempt to put to read-only 
'"+JSU.toString(name)+"'");
         case "indexof":     throw new JSExn("Attempt to put to read-only 
'"+JSU.toString(name)+"'");
         case "distanceto":  throw new JSExn("Attempt to put to read-only 
'"+JSU.toString(name)+"'");
-        case "align":
-            // TODO optimize; check if align does not change
-            dirty();
-            setAlign(value == null ? "center" : JSU.toString(value));
-            setPlace();
-            dirty();
         case "cursor":
             super.put(name, value);
             if (value == null) clear(CURSOR);
@@ -1425,7 +1433,8 @@
                     if (!s.cursor.equals(oldcursor)) s.syncCursor();
                 }
             }
-        case "fill":        setFill(value);
+        case "align":       if (setAlign(value)) { setPlace(); dirty(); }
+        case "fill":        setFill(value); dirty(); // FEATURE: only dirty if 
fill changes
         case "tile":
             if (CHECKSET_FLAG(TILE_IMAGE)) {
                 dirty();


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to