X-Git-Url: http://git.megacz.com/?p=org.ibex.core.git;a=blobdiff_plain;f=src%2Forg%2Fibex%2Fcore%2FBox.java;h=bb8a27b94812b8bd954dbaa7ce2f9a445befe228;hp=c34948d5de03a6398aaf04a12e27149a596eb3b2;hb=fffcafc33aa4066bdf85da7a32e1a1cdb9db2d6f;hpb=042d893f039709d5b1f7220fc7ee0011ddccba96 diff --git a/src/org/ibex/core/Box.java b/src/org/ibex/core/Box.java index c34948d..bb8a27b 100644 --- a/src/org/ibex/core/Box.java +++ b/src/org/ibex/core/Box.java @@ -65,8 +65,8 @@ public final class Box extends JSScope implements Task { static final int MOUSEINSIDE = 0x00000001; static final int VISIBLE = 0x00000002; static final int PACKED = 0x00000004; - static final int HSHRINK = 0x00000008; - static final int VSHRINK = 0x00000010; + public static final int HSHRINK = 0x00000008; + public static final int VSHRINK = 0x00000010; static final int BLACK = 0x00000020; // for red-black code static final int FIXED = 0x00000040; @@ -123,18 +123,16 @@ public final class Box extends JSScope implements Task { public int ay = 0; // FEATURE: roll these into x/y; requires lots of changes; perhaps y()? public int width = 0; public int height = 0; - private int contentwidth = 0; // == max(minwidth, textwidth, sum(child.contentwidth)) - private int contentheight = 0; + public int contentwidth = 0; // == max(minwidth, textwidth, sum(child.contentwidth)) + public int contentheight = 0; + private Path path = null; /* - private VectorGraphics.VectorPath path = null; private Affine transform = null; private VectorGraphics.RasterPath rpath = null; private Affine rtransform = null; */ - //#define DIRTY dirty() - // Instance Methods ///////////////////////////////////////////////////////////////////// public final int fontSize() { return font == null ? DEFAULT_FONT.pointsize : font.pointsize; } @@ -145,7 +143,7 @@ public final class Box extends JSScope implements Task { if (texture.isLoaded) { setWidth(max(texture.width, minwidth), maxwidth); setHeight(max(texture.height, minheight), maxheight); - DIRTY; } + dirty(); } else { JS res = texture.stream; texture = null; throw new JSExn("image not found: "+res.unclone()); } } @@ -172,8 +170,14 @@ public final class Box extends JSScope implements Task { // Reflow //////////////////////////////////////////////////////////////////////////////////////// /** should only be invoked on the root box */ - public void reflow() { pack(); resize(x, y, maxwidth, maxheight); place(); } - + public void reflow() { + pack(); + resize(x, y, + test(HSHRINK) ? contentwidth : maxwidth, + test(VSHRINK) ? contentheight : maxheight); + place(); + } + private static Box[] frontier = new Box[65535]; /** pack the boxes into rows and columns, compute contentwidth */ public void pack() { @@ -228,7 +232,7 @@ public final class Box extends JSScope implements Task { void resize(int x, int y, int width, int height) { if (x == this.x && y == this.y && width == this.width && height == this.height) return; - boolean sizechange = (this.width != width || this.height != height) && getTrap("SizeChange") != null; + boolean sizechange = (this.width != width || this.height != height) && hasTrap("SizeChange"); int thisx = parent == null ? 0 : this.x; int thisy = parent == null ? 0 : this.y; Box who = (parent == null ? this : parent); @@ -242,7 +246,7 @@ public final class Box extends JSScope implements Task { } else { who.dirty(thisx, thisy, this.width, this.height); this.width = width; this.height = height; this.x = x; this.y = y; - DIRTY; + dirty(); } if (sizechange) putAndTriggerTrapsAndCatchExceptions("SizeChange", T); } @@ -420,6 +424,8 @@ public final class Box extends JSScope implements Task { font.rasterizeGlyphs(text, buf, strokecolor, text_x, text_y, cx1, cy1, cx2, cy2); } + if (path != null) path.realize(Affine.translate(globalx, globaly)).stroke(buf, 1, strokecolor); + for(Box b = getChild(0); b != null; b = b.nextSibling()) b.render(globalx, globaly, cx1, cy1, cx2, cy2, buf, null); } @@ -442,7 +448,7 @@ public final class Box extends JSScope implements Task { case "distanceto": Box b = (Box)a0; - JS ret = new JS(); + JS ret = new JS.O(); ret.put("x", N(b.localToGlobalX(0) - localToGlobalX(0))); ret.put("y", N(b.localToGlobalY(0) - localToGlobalY(0))); return ret; @@ -462,7 +468,13 @@ public final class Box extends JSScope implements Task { case "indexof": return METHOD; case "distanceto": return METHOD; case "text": return text; - case "path": throw new JSExn("cannot read from the path property"); + case "path": + if (path != null) return path.toString(); + if (text == null) return null; + if (font == null) return null; + String ret = ""; + for(int i=0; i 0) { CHECKSET_SHORT(colspan); if (parent != null) parent.REPACK(); } case "rowspan": if (toInt(value) > 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); } - case "visible": CHECKSET_FLAG(VISIBLE); RECONSTRAIN(); DIRTY; + 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 == null ? "center" : value); REPLACE(); case "cursor": setCursor(value); case "fill": setFill(value); - case "clip": CHECKSET_FLAG(CLIP); if (parent == null) DIRTY; else parent.DIRTY; + case "clip": CHECKSET_FLAG(CLIP); if (parent == null) dirty(); else parent.dirty(); case "rows": CHECKSET_SHORT(rows); if (rows==0){set(FIXED, COLS);if(cols==0)cols=1;} else set(FIXED, ROWS); REPACK(); case "cols": CHECKSET_SHORT(cols); if (cols==0){set(FIXED, ROWS);if(rows==0)rows=1;} else set(FIXED, COLS); REPACK(); @@ -576,13 +589,13 @@ public final class Box extends JSScope implements Task { for(Box cur = (Box)value; cur != null || cur == redirect; 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 "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); DIRTY; + case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); dirty(); case "font": if(!(value instanceof Stream)) throw new JSExn("You can only put streams to the font property"); if (font == value) return; // FIXME: unclone() font = value == null ? null : Font.getFont((Stream)value, font == null ? 10 : font.pointsize); RECONSTRAIN(); - DIRTY; + dirty(); case "x": if (parent==null && Surface.fromBox(this)!=null) { CHECKSET_INT(x); } else { @@ -708,7 +721,7 @@ public final class Box extends JSScope implements Task { } else { throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass()); } - DIRTY; + dirty(); } /** @@ -818,7 +831,7 @@ public final class Box extends JSScope implements Task { void set(int mask) { flags |= mask; } void set(int mask, boolean setclear) { if (setclear) set(mask); else clear(mask); } void clear(int mask) { flags &= ~mask; } - boolean test(int mask) { return ((flags & mask) == mask); } + public boolean test(int mask) { return ((flags & mask) == mask); } // Tree Handling ////////////////////////////////////////////////////////////////////// @@ -844,7 +857,7 @@ public final class Box extends JSScope implements Task { public void removeChild(int i) { Box b = getChild(i); b.RECONSTRAIN(); - b.DIRTY; + b.dirty(); b.clear(MOUSEINSIDE); deleteNode(i); b.parent = null; @@ -904,7 +917,7 @@ public final class Box extends JSScope implements Task { b.REPACK(); REPACK(); - b.DIRTY; + b.dirty(); putAndTriggerTrapsAndCatchExceptions("ChildChange", b); } }