fix erroneous search-replace
[org.ibex.core.git] / src / org / ibex / core / Box.java
index 17323c1..b6dcdf5 100644 (file)
@@ -54,17 +54,13 @@ public final class Box extends JS.Obj implements Callable {
     //#define CHECKSET_SHORT(prop) short nu = (short)JSU.toInt(value); if (nu == prop) break; prop = nu;
     //#define CHECKSET_INT(prop) int nu = JSU.toInt(value); if (nu == prop) break; prop = nu;
     //#define CHECKSET_FLAG(flag) boolean nu = JSU.toBoolean(value); if (nu == test(flag)) break; if (nu) set(flag); else clear(flag);
-    //#define CHECKSET_BOOLEAJSU.N(prop) boolean nu = JSU.toBoolean(value); if (nu == prop) break; prop = nu;
+    //#define CHECKSET_BOOLEAN.N(prop) boolean nu = JSU.toBoolean(value); if (nu == prop) break; prop = nu;
     //#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&JSU.toString(value).equals(prop))) break; prop=JSU.toString(value);
 
     // FIXME memory leak
-    static Basket.Map boxToCursor = new Basket.HashMap(500, 3);
+    static Basket.Map boxToCursor = new Basket.Hash(500, 3);
 
-    static final Font DEFAULT_FONT;
-    static {
-        try { DEFAULT_FONT = Font.getFont((JS)Main.builtin.get(JSU.S("fonts/vera/Vera.ttf")), 10); }
-        catch(JSExn e) { throw new Error("Error loading default font: " + e); }
-    }
+    public static final Font DEFAULT_FONT = Font.getFont(Main.vera, 10);
 
 
     // Flags //////////////////////////////////////////////////////////////////////
@@ -85,11 +81,6 @@ public final class Box extends JS.Obj implements Callable {
     static final int RECONSTRAIN  = 0x00000200;
     static final int REPLACE      = 0x00000400;
 
-    static final int ALIGN_TOP    = 0x00001000;
-    static final int ALIGN_BOTTOM = 0x00002000;
-    static final int ALIGN_LEFT   = 0x00004000;
-    static final int ALIGN_RIGHT  = 0x00008000;
-    static final int ALIGNS       = 0x0000f000;
     static final int CURSOR       = 0x00010000;  // if true, this box has a cursor in the cursor hash; FEATURE: GC issues?
     static final int CLIP         = 0x00020000;
     static final int STOP_UPWARD_PROPAGATION    = 0x00040000;
@@ -118,6 +109,10 @@ public final class Box extends JS.Obj implements Callable {
     public int maxwidth = Integer.MAX_VALUE;
     public int minheight = 0;
     public int maxheight = Integer.MAX_VALUE;
+    public int minwidth() { return minwidth; }
+    public int minheight() { return minheight; }
+    public int maxwidth() { return maxwidth; }
+    public int maxheight() { return maxheight; }
     private short rows = 1;
     private short cols = 0;
     private short rowspan = 1;
@@ -369,13 +364,13 @@ public final class Box extends JS.Obj implements Callable {
                 child_height = max(child.minheight, child_height);
                 int gap_x = width - child_width;
                 int gap_y = height - child_height;
-                child_x = child.ax + (child.test(ALIGN_RIGHT) ? gap_x : !child.test(ALIGN_LEFT) ? gap_x / 2 : 0);
-                child_y = child.ay + (child.test(ALIGN_BOTTOM) ? gap_y : !child.test(ALIGN_TOP) ? gap_y / 2 : 0);
+                child_x = child.ax + gap_x / 2;
+                child_y = child.ay + gap_y / 2;
             } else {
                 int diff;
                 //#repeat col/row colspan/rowspan contentwidth/contentheight width/height colMaxWidth/rowMaxHeight \
                 //        child_x/child_y x/y HSHRINK/VSHRINK maxwidth/maxheight cols/rows minwidth/minheight x_slack/y_slack \
-                //        child_width/child_height ALIGN_RIGHT/ALIGN_BOTTOM ALIGN_LEFT/ALIGN_TOP lp_h/lp \
+                //        child_width/child_height lp_h/lp \
                 //        numregions/numregions_v regions/regions_v targetColumnSize/targetRowSize sizes/sizes_v
                 child_x = 0;
                 if (cols == 1) {
@@ -388,7 +383,7 @@ public final class Box extends JS.Obj implements Callable {
                     }
                 }
                 diff = (child_width - (child.test(HSHRINK) ? child.contentwidth : min(child_width, child.maxwidth)));
-                child_x += (child.test(ALIGN_RIGHT) ? diff : child.test(ALIGN_LEFT) ? 0 : diff / 2);
+                child_x += diff / 2;
                 child_width -= diff;
                 //#end
             }
@@ -432,8 +427,8 @@ public final class Box extends JS.Obj implements Callable {
         if (text != null && !text.equals("") && font != null) {
             int gap_x = width - font.textwidth(text);
             int gap_y = height - font.textheight(text);
-            int text_x = globalx + (test(ALIGN_RIGHT) ? gap_x : !test(ALIGN_LEFT) ? gap_x/2 : 0);
-            int text_y = globaly + (test(ALIGN_BOTTOM) ? gap_y : !test(ALIGN_TOP) ? gap_y/2 : 0);
+            int text_x = globalx + gap_x/2;
+            int text_y = globaly + gap_y/2;
             font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2);
         }
 
@@ -445,7 +440,6 @@ public final class Box extends JS.Obj implements Callable {
     
     
     // Methods to implement org.ibex.js.JS //////////////////////////////////////
-
   
     public JS call(JS method, JS[] args) throws JSExn {
         switch (args.length) {
@@ -494,7 +488,6 @@ public final class Box extends JS.Obj implements Callable {
         case "font": return font == null ? null : font.stream;
         case "fontsize": return font == null ? JSU.N(10) : JSU.N(font.pointsize);
         case "strokewidth": return JSU.N(strokewidth);
-        case "align": return JSU.S(alignToString());
         case "thisbox": return this;
         case "shrink": return JSU.B(test(HSHRINK) || test(VSHRINK));
         case "hshrink": return JSU.B(test(HSHRINK));
@@ -581,7 +574,6 @@ public final class Box extends JS.Obj implements Callable {
         case "rowspan":     if (JSU.toInt(value) > 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); }
         case "visible":     CHECKSET_FLAG(VISIBLE); RECONSTRAIN(); dirty();
         case "packed":      CHECKSET_FLAG(PACKED); if (parent != null) { parent.REPACK(); } else { REPACK(); }
-        case "align":       clear(ALIGNS); setAlign(value); REPLACE();
         case "cursor":      setCursor(JSU.toString(value));
         case "fill":        setFill(value);
         case "clip":        CHECKSET_FLAG(CLIP); if (parent == null) dirty(); else parent.dirty();
@@ -604,9 +596,9 @@ public final class Box extends JS.Obj implements Callable {
             JSU.error("redirect can only be set to a descendant of its current value");
         case "fontsize": font = Font.getFont(font == null ? null : font.stream, JSU.toInt(value)); RECONSTRAIN(); dirty();
         case "font":
-            if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property");
+            if(!(value instanceof Fountain)) throw new JSExn("You can only put streams to the font property");
             //FIXME: if (font == value) return;  // FIXME: unclone()
-            font = value == null ? null : Font.getFont((Stream)value, font == null ? 10 : font.pointsize);
+            font = value == null ? null : Font.getFont((Fountain)value, font == null ? 10 : font.pointsize);
             RECONSTRAIN();
             dirty();
         case "x": if (parent==null && Surface.fromBox(this)!=null) {
@@ -673,36 +665,6 @@ public final class Box extends JS.Obj implements Callable {
         //#end
     }
 
-    private String alignToString() {
-        switch(flags & ALIGNS) {
-            case (ALIGN_TOP | ALIGN_LEFT): return "topleft";
-            case (ALIGN_BOTTOM | ALIGN_LEFT): return "bottomleft";
-            case (ALIGN_TOP | ALIGN_RIGHT): return "topright";
-            case (ALIGN_BOTTOM | ALIGN_RIGHT): return "bottomright";
-            case ALIGN_TOP: return "top";
-            case ALIGN_BOTTOM: return "bottom";
-            case ALIGN_LEFT: return "left";
-            case ALIGN_RIGHT: return "right";
-            case 0: return "center";
-            default: throw new Error("invalid alignment flags: " + (flags & ALIGNS));
-        }
-    }
-
-    private void setAlign(JS value) throws JSExn {
-        clear(ALIGNS);
-        //#switch(JSU.toString(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);
-        default: JSU.log("invalid alignment \"" + JSU.str(value) + "\"");
-        //#end
-    }
-    
     private void setCursor(String value) throws JSExn {
         if (value == null) { clear(CURSOR); boxToCursor.remove(this); return; }
         if (value.equals(boxToCursor.get(this))) return;