X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2FBox.java;h=2ada11fffc1d619f9040748ceba98d1f300e1712;hb=a45a8fc2ca7e197f70a1e13ae22d2a49339722f8;hp=0e5d2a7b45b54e698a10ee147e6cb4deab3e00e6;hpb=39f90dcf231fe24e5e6c03b3368a33a648b148fa;p=org.ibex.core.git diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index 0e5d2a7..2ada11f 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -177,9 +177,10 @@ public final class Box extends JSScope implements Scheduler.Task { // as external events have occured, check the state of box if (texture != null) { if (texture.isLoaded) { minwidth = min(texture.width, maxwidth); minheight = min(texture.height, maxheight); } - else { JS res = texture.stream; texture = null; throw new JSExn("image not found: "+res); } + else { JS res = texture.stream; texture = null; throw new JSExn("image not found: "+res.unclone()); } + } else { + Log.warn(Box.class, "perform() called with null texture"); } - MARK_REPACK; MARK_REFLOW; MARK_RESIZE; @@ -213,13 +214,6 @@ public final class Box extends JSScope implements Scheduler.Task { // static stuff so we don't have to keep reallocating private static int[] numRowsInCol = new int[65535]; - private static LENGTH[] colWidth = new LENGTH[65535]; - private static LENGTH[] colMinWidth = new LENGTH[65535]; - private static LENGTH[] colMaxWidth = new LENGTH[65535]; - private static LENGTH[] rowHeight = new LENGTH[65535]; - private static LENGTH[] rowMinHeight = new LENGTH[65535]; - private static LENGTH[] rowMaxHeight = new LENGTH[65535]; - static { for(int i=0; i i)) + rowcontentwidth += child.contentwidth; + contentwidth = max(contentwidth, rowcontentwidth); } - for(int i=0; icoeff.length) coeff = new float[nc+1]; + lp_h.init(nc, nc); + + // objective function + for(int i=0; i=child.col && i=child.col && i 0 && cols > 0 && startslack != x_slack;) { - if (eligible == 0) break; - int increment = x_slack / eligible; - eligible = 0; - startslack = x_slack; - for(short col=0; col < cols; col++) { - // FIXME: double check this - int diff = min(min(colMaxWidth[col], colWidth[col] + increment) - colWidth[col], x_slack); - if (colWidth[col] + diff < colMinWidth[col]) diff = colMinWidth[col] - colWidth[col]; - if (diff == 0) continue; - eligible++; - x_slack -= diff; - colWidth[col] += diff; + + // priority 3: equalize columns + for(int i=0 ; i unbounded) child_x -= (child_width - unbounded) / 2; + // child_width/child_height ALIGN_RIGHT/ALIGN_BOTTOM ALIGN_LEFT/ALIGN_TOP lp_h/lp_v + child_width = 0; + child_x = 0; + for(int i=0; i < child.col; i++) child_x += Math.round(lp_h.solution[lp_h.rows+i+1]); + for(int i = child.col; i 0) + child.place_children(); } @@ -378,10 +392,9 @@ public final class Box extends JSScope implements Scheduler.Task { int globaly = parenty + (parent == null ? 0 : y); // intersect the x,y,w,h rendering window with ourselves; quit if it's empty - if (test(CLIP)) { - cx1 = max(cx1, parent == null ? 0 : globalx); - cy1 = max(cy1, parent == null ? 0 : globaly); + cx1 = max(cx1, globalx); + cy1 = max(cy1, globaly); cx2 = min(cx2, globalx + width); cy2 = min(cy2, globaly + height); if (cx2 <= cx1 || cy2 <= cy1) return; @@ -418,13 +431,28 @@ public final class Box extends JSScope implements Scheduler.Task { public int localToGlobalY(int y) { return parent == null ? y : parent.globalToLocalY(y + this.y); } public Object callMethod(Object method, Object a0, Object a1, Object a2, Object[] rest, int nargs) throws JSExn { - if (nargs != 1 || !"indexof".equals(method)) return super.callMethod(method, a0, a1, a2, rest, nargs); - Box b = (Box)a0; - if (b.parent != this) - return (redirect == null || redirect == this) ? - N(-1) : - redirect.callMethod(method, a0, a1, a2, rest, nargs); - return N(b.getIndexInParent()); + switch (nargs) { + case 1: { + //#switch(method) + case "indexof": + Box b = (Box)a0; + if (b.parent != this) + return (redirect == null || redirect == this) ? + N(-1) : + redirect.callMethod(method, a0, a1, a2, rest, nargs); + return N(b.getIndexInParent()); + + case "distanceto": + Box b = (Box)a0; + JS ret = new JS(); + ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0))); + ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0))); + return ret; + + //#end + } + } + return super.callMethod(method, a0, a1, a2, rest, nargs); } public Enumeration keys() { throw new Error("you cannot apply for..in to a " + this.getClass().getName()); } @@ -448,6 +476,7 @@ public final class Box extends JSScope implements Scheduler.Task { //#switch(name) case "surface": return parent == null ? null : parent.getAndTriggerTraps("surface"); case "indexof": return METHOD; + case "distanceto": return METHOD; case "text": return text; case "path": throw new JSExn("cannot read from the path property"); case "fill": return colorToString(fillcolor); @@ -557,15 +586,36 @@ public final class Box extends JSScope implements Scheduler.Task { case "Minimized": if (parent == null && getSurface() != null) getSurface().minimized = toBoolean(value); // FEATURE case "Maximized": if (parent == null && getSurface() != null) getSurface().maximized = toBoolean(value); // FEATURE case "Close": if (parent == null && getSurface() != null) getSurface().dispose(true); - case "redirect": if (redirect == this) redirect = (Box)value; else Log.info(this, "redirect can only be set once"); + case "redirect": + if (value == null) { redirect = null; return; } + for(Box cur = (Box)value; cur != null; cur = cur.parent) + if (cur == redirect) { + redirect = (Box)value; + return; + } + JS.error("redirect can only be set to a descendant of its current value"); case "font": if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property"); font = value == null ? null : Font.getFont((Stream)value, font == null ? 10 : font.pointsize); MARK_RESIZE; dirty(); case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); MARK_RESIZE; dirty(); - case "x": if (parent==null && Surface.fromBox(this)!=null) { CHECKSET_INT(x); } else { if (test(PACKED) && parent != null) return; dirty(); CHECKSET_INT(ax); dirty(); MARK_RESIZE; dirty(); } - case "y": if (parent==null && Surface.fromBox(this)!=null) { CHECKSET_INT(y); } else { if (test(PACKED) && parent != null) return; dirty(); CHECKSET_INT(ay); dirty(); MARK_RESIZE; dirty(); } + case "x": if (parent==null && Surface.fromBox(this)!=null) { + CHECKSET_INT(x); + } else { + if (test(PACKED) && parent != null) return; + dirty(); CHECKSET_INT(ax); + dirty(); MARK_RESIZE; + dirty(); + } + case "y": if (parent==null && Surface.fromBox(this)!=null) { + CHECKSET_INT(y); + } else { + if (test(PACKED) && parent != null) return; + dirty(); CHECKSET_INT(ay); + dirty(); MARK_RESIZE; + dirty(); + } case "titlebar": if (getSurface() != null && value != null) getSurface().setTitleBarText(JS.toString(value)); super.put(name,value);