X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2FBox.java;h=e8c3d35da608ca66af48de77f9f6fbfaad977d8f;hb=66204595a29d1ac52c97211a6567d1f0b76234a9;hp=90fd4997893a1e5318a021e929abbd31d44a64f2;hpb=e2dab289d7adfebb01adf5ce782e7fa1b122cded;p=org.ibex.core.git diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index 90fd499..e8c3d35 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -152,6 +152,8 @@ public final class Box extends JSScope implements Scheduler.Task { private short col = 0; public LENGTH x = 0; public LENGTH y = 0; + public LENGTH ax = 0; // FEATURE: roll these into x/y; requires lots of changes + public LENGTH ay = 0; // FEATURE: roll these into x/y; requires lots of changes; perhaps y()? public LENGTH width = 0; public LENGTH height = 0; private LENGTH contentwidth = 0; // == max(minwidth, textwidth, sum(child.contentwidth)) @@ -175,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; @@ -212,8 +215,10 @@ 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 0 && cols > 0 && startslack != x_slack;) { - int increment = max(1, x_slack / cols); + 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; } @@ -320,12 +335,14 @@ public final class Box extends JSScope implements Scheduler.Task { if (!child.test(VISIBLE)) continue; int child_width, child_height, child_x, child_y; if (!child.test(PACKED)) { - child_x = child.x; - child_y = child.y; - child_width = child.test(HSHRINK) ? child.contentwidth : min(child.maxwidth, width - child_x); - child_height = child.test(VSHRINK) ? child.contentheight : min(child.maxheight, height - child_y); + child_width = child.test(HSHRINK) ? child.contentwidth : min(child.maxwidth, width - Math.abs(child.ax)); + child_height = child.test(VSHRINK) ? child.contentheight : min(child.maxheight, height - Math.abs(child.ay)); child_width = max(child.minwidth, child_width); 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); } else { int unbounded; //#repeat col/row colspan/rowspan contentwidth/contentheight width/height colMaxWidth/rowMaxHeight \ @@ -362,10 +379,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; @@ -379,10 +395,15 @@ public final class Box extends JSScope implements Scheduler.Task { for(int x = globalx; x < cx2; x += texture.width) for(int y = globaly; y < cy2; y += texture.height) buf.drawPicture(texture, x, y, cx1, cy1, cx2, cy2); - - if (text != null && !text.equals("") && font != null) - if (font.rasterizeGlyphs(text, buf, strokecolor, globalx, globaly, cx1, cy1, cx2, cy2, null) == -1) - font.rasterizeGlyphs(text, buf, strokecolor, globalx, globaly, cx1, cy1, cx2, cy2, this); + + 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); + if (font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2, null) == -1) + font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2, this); + } for(Box b = getChild(0); b != null; b = b.nextSibling()) b.render(globalx, globaly, cx1, cy1, cx2, cy2, buf, null); @@ -536,15 +557,35 @@ 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": + 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(x); 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(y); 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); @@ -564,8 +605,6 @@ public final class Box extends JSScope implements Scheduler.Task { case "KeyPressed": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "KeyReleased": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "Move": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); - case "Enter": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); - case "Leave": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "HScroll": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, N(((Number)value).floatValue() * ((float)parent.fontSize()) / ((float)fontSize()))); @@ -594,6 +633,8 @@ public final class Box extends JSScope implements Scheduler.Task { case "SizeChange": return; case "childadded": return; case "childremoved": return; + case "Enter": return; + case "Leave": return; case "thisbox": if (value == null) removeSelf();