fixed bug 529
[org.ibex.core.git] / src / org / ibex / Box.java
index e3e30ec..7a16c49 100644 (file)
@@ -277,10 +277,9 @@ public final class Box extends JSScope implements Scheduler.Task {
     }
 
     private static float[] coeff = null;
-    private static Simplex lp_h = new Simplex(100, 100, 300);
-    private static Simplex lp = new Simplex(100, 100, 300);
+    private static Simplex lp_h = new Simplex(65535, 65535, 65535);
+    private static Simplex lp = new Simplex(65535, 65535, 65535);
 
-    // FIXME: numboxes^2, and damn ugly to boot
     private static int[] regions = new int[65535];
     private static int[] regions_v = new int[65535];
     private static int numregions = 0;
@@ -291,18 +290,18 @@ public final class Box extends JSScope implements Scheduler.Task {
     private void computeRegions() {
         numregions = 0;
         for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) {
-            int target = c.col;
-            for(boolean stop = false;;) {
-                for(int i=0; i<=numregions; i++) {
-                    if (i == numregions) { regions[numregions++] = target; break; }
-                    if (target == regions[i]) break;
-                    if (target < regions[i]) { int tmp = target; target = regions[i]; regions[i] = tmp; }
-                }
-                if (stop) break;
-                stop = true;
-                target = min(cols, c.col+c.colspan);
-            }
+            regions[numregions++] = c.col;
+            regions[numregions++] = min(cols, c.col+c.colspan);
+        }
+        Vec.sortInts(regions, 0, numregions);
+        int j = 0;
+        int newnumregions = numregions;
+        for(int i=1; i<numregions; i++) {
+            if (regions[j] != regions[i]) j++;
+            else newnumregions--;
+            regions[j] = regions[i];
         }
+        numregions = newnumregions;
         if (regions[numregions-1] == cols) numregions--;
         else regions[numregions] = cols;
     }
@@ -313,7 +312,7 @@ public final class Box extends JSScope implements Scheduler.Task {
         //#repeat col/row colspan/rowspan contentwidth/contentheight width/height HSHRINK/VSHRINK numregions/numregions_v \
         //        maxwidth/maxheight cols/rows minwidth/minheight lp_h/lp lp_h/lp easy_width/easy_height regions/regions_v \
         //        computeRegions/computeRegions_v
-        if (numkids > 0 && cols > 1) do {
+        if (numkids > 0) do {
             computeRegions();
             int nc = numregions * 3 + numkids * 2 + 3;
             if (coeff == null || nc+1>coeff.length) coeff = new float[nc+1];
@@ -321,7 +320,7 @@ public final class Box extends JSScope implements Scheduler.Task {
 
             for(int i=0; i<coeff.length; i++) coeff[i] = (float)0.0;
             if (!findMinimum) {
-                coeff[numregions*2+numkids] = (float)10000.0;               // priority 1: sum of columns no greater than parent
+                coeff[numregions*2+numkids] = (float)10000.0;           // priority 1: sum of columns no greater than parent
                 for(int i=numregions*2; i<numregions*2+numkids; i++) coeff[i] = (float)100.0;  // priority 2: honor maxwidths
                 for(int i=numregions; i<numregions*2; i++) coeff[i] = (float)(0.1);            // priority 3: equalize columns
             } else {
@@ -329,11 +328,6 @@ public final class Box extends JSScope implements Scheduler.Task {
             }
             lp_h.setObjective(coeff, false);
 
-            for(int i=0; i<numregions; i++) {
-                for(int j=0; j<coeff.length; j++) coeff[j] = j==i ? (float)1.0 : (float)0.0;
-                lp_h.add_constraint(coeff, Simplex.GE, (float)0.0);
-            }
-
             // priority 1: sum of columns as close to parent's width as possible
             for(int i=0; i<coeff.length; i++) coeff[i] = (i<numregions) ? (float)(regions[i+1] - regions[i]) : (float)0.0;
             coeff[numregions*2+numkids] = (float)-1.0;
@@ -540,8 +534,8 @@ public final class Box extends JSScope implements Scheduler.Task {
         case "hshrink": return B(test(HSHRINK));
         case "vshrink": return B(test(VSHRINK));
         case "aspect": return N(aspect);
-        case "x": return (parent == null || !test(VISIBLE)) ? N(0) : N(x);
-        case "y": return (parent == null || !test(VISIBLE)) ? N(0) : N(y);
+        case "x": return (parent == null || !test(VISIBLE)) ? N(0) : test(PACKED) ? N(x) : N(ax);
+        case "y": return (parent == null || !test(VISIBLE)) ? N(0) : test(PACKED) ? N(y) : N(ay);
         case "cols": return test(FIXED) == COLS ? N(cols) : N(0);
         case "rows": return test(FIXED) == ROWS ? N(rows) : N(0);
         case "colspan": return N(colspan);
@@ -829,7 +823,7 @@ public final class Box extends JSScope implements Scheduler.Task {
             }
 
         if (!obscured && !found)
-            if ("_Move".equals(name) || wasinside)
+            if ("_Move".equals(name) || name.startsWith("_Release") || wasinside)
                 if (name != null)
                     putAndTriggerTrapsAndCatchExceptions(name.substring(1), value);
     }