From 162fce11441e085eb084fef7b4ca8dd6006e9dfe Mon Sep 17 00:00:00 2001 From: adam Date: Sun, 11 Apr 2004 19:39:04 +0000 Subject: [PATCH] intelligent repacking/reconstrainig/replacing darcs-hash:20040411193904-5007d-08ecfa8c93f629d9c85cc7f4f58c7a2254b48432.gz --- src/org/ibex/Box.java | 195 +++++++++++++++++------------------ src/org/ibex/util/Preprocessor.java | 2 +- 2 files changed, 96 insertions(+), 101 deletions(-) diff --git a/src/org/ibex/Box.java b/src/org/ibex/Box.java index 6d74e69..faaabeb 100644 --- a/src/org/ibex/Box.java +++ b/src/org/ibex/Box.java @@ -43,13 +43,11 @@ public final class Box extends JSScope implements Scheduler.Task { // Macros ////////////////////////////////////////////////////////////////////// //#define LENGTH int - //#define MARK_REPACK for(Box b2 = this; b2 != null && !b2.test(REPACK); b2 = b2.parent) b2.set(REPACK); - //#define MARK_REPACK_b for(Box b2 = b; b2 != null && !b2.test(REPACK); b2 = b2.parent) b2.set(REPACK); - //#define MARK_REPACK_parent for(Box b2 = parent; b2 != null && !b2.test(REPACK); b2 = b2.parent) b2.set(REPACK); - //#define MARK_REFLOW for(Box b2 = this; b2 != null && !b2.test(REFLOW); b2 = b2.parent) b2.set(REFLOW); - //#define MARK_REFLOW_b for(Box b2 = b; b2 != null && !b2.test(REFLOW); b2 = b2.parent) b2.set(REFLOW); - //#define MARK_RESIZE for(Box b2 = this; b2 != null && !b2.test(RESIZE); b2 = b2.parent) b2.set(RESIZE); - //#define MARK_RESIZE_b for(Box b2 = b; b2 != null && !b2.test(RESIZE); b2 = b2.parent) b2.set(RESIZE); + + final void REPLACE() { for(Box b2 = this; b2 != null && !b2.test(REPLACE); b2 = b2.parent) b2.set(REPLACE); } + final void RECONSTRAIN() { for(Box b2 = this; b2 != null && !b2.test(RECONSTRAIN); b2 = b2.parent) b2.set(RECONSTRAIN); } + final void REPACK() { for(Box b2 = this; b2 != null && !b2.test(REPACK); b2 = b2.parent) b2.set(REPACK); } + //#define CHECKSET_SHORT(prop) short nu = (short)toInt(value); if (nu == prop) break; prop = nu; //#define CHECKSET_INT(prop) int nu = toInt(value); if (nu == prop) break; prop = nu; //#define CHECKSET_FLAG(flag) boolean nu = toBoolean(value); if (nu == test(flag)) break; if (nu) set(flag); else clear(flag); @@ -105,9 +103,9 @@ public final class Box extends JSScope implements Scheduler.Task { static final int ISROOT = 0x00000080; static final int REPACK = 0x00000100; - static final int REFLOW = 0x00000200; - static final int RESIZE = 0x00000400; - static final int RECONSTRAIN = 0x00000800; + 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; @@ -123,7 +121,7 @@ public final class Box extends JSScope implements Scheduler.Task { Box parent = null; Box redirect = this; - int flags = VISIBLE | PACKED | REPACK | REFLOW | RESIZE | FIXED /* ROWS */ | STOP_UPWARD_PROPAGATION | CLIP | MOVED; + int flags = VISIBLE | PACKED | REPACK | RECONSTRAIN | REPLACE | FIXED | STOP_UPWARD_PROPAGATION | CLIP | MOVED; private String text = null; private Font font = DEFAULT_FONT; @@ -163,6 +161,8 @@ public final class Box extends JSScope implements Scheduler.Task { private VectorGraphics.Affine rtransform = null; */ + //#define DIRTY dirty() + // Instance Methods ///////////////////////////////////////////////////////////////////// public final int fontSize() { return font == null ? DEFAULT_FONT.pointsize : font.pointsize; } @@ -170,7 +170,10 @@ public final class Box extends JSScope implements Scheduler.Task { /** invoked when a resource needed to render ourselves finishes loading */ public void perform() throws JSExn { if (texture == null) { Log.warn(Box.class, "perform() called with null texture"); return; } - if (texture.isLoaded) { setMinWidth(max(texture.width, maxwidth)); setMinHeight(max(texture.height, maxheight)); } + if (texture.isLoaded) { + setMinWidth(max(texture.width, maxwidth)); + setMinHeight(max(texture.height, maxheight)); + DIRTY; } else { JS res = texture.stream; texture = null; throw new JSExn("image not found: "+res.unclone()); } } @@ -199,8 +202,11 @@ public final class Box extends JSScope implements Scheduler.Task { private static Box[] frontier = new Box[65535]; /** pack the boxes into rows and columns, compute contentwidth */ void pack() { - for(Box child = getChild(0); child != null; child = child.nextSibling()) child.pack(); - int frontier_size = 0; contentwidth = 0; contentheight = 0; + if (!test(REPACK)) { constrain(); return; } + boolean haskid = false; + for(Box child = getChild(0); child != null; child = child.nextSibling()) { haskid = true; child.pack(); } + if (!haskid) { clear(REPACK); return; } + int frontier_size = 0; //#repeat COLS/ROWS rows/cols cols/rows col/row row/col colspan/rowspan rowspan/colspan \ // contentheight/contentwidth contentwidth/contentheight if (test(FIXED) == COLS) { @@ -228,6 +234,13 @@ public final class Box extends JSScope implements Scheduler.Task { for(int i=0; i 1) do { - computeRegions(); + + // FIXME: cache these? + // compute regions + numregions = 0; + for(Box c = firstPackedChild(); c != null; c = c.nextPackedSibling()) { + 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 0) { CHECKSET_SHORT(colspan); if (parent != null) parent.REPACK(); } + case "rowspan": if (toInt(value) > 0) { CHECKSET_SHORT(rowspan); if (parent != null) parent.REPACK(); } + 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(); + case "clip": CHECKSET_FLAG(CLIP); if (parent == null) DIRTY; else parent.DIRTY; + case "visible": CHECKSET_FLAG(VISIBLE); RECONSTRAIN(); DIRTY; + case "packed": CHECKSET_FLAG(PACKED); if (parent != null) parent.REPACK(); + case "align": clear(ALIGNS); setAlign(value == null ? "center" : value); REPLACE(); case "cursor": setCursor(value); case "fill": setFill(value); case "mouse": @@ -621,29 +618,27 @@ public final class Box extends JSScope implements Scheduler.Task { 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(); + RECONSTRAIN(); + DIRTY; + case "fontsize": font = Font.getFont(font == null ? null : font.stream, toInt(value)); RECONSTRAIN(); 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(); + CHECKSET_INT(ax); + REPLACE(); } 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(); + CHECKSET_INT(ay); + REPLACE(); } case "titlebar": if (getSurface() != null && value != null) getSurface().setTitleBarText(JS.toString(value)); super.put(name,value); - + case "Press1": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "Press2": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); case "Press3": if (!test(STOP_UPWARD_PROPAGATION) && parent != null) parent.putAndTriggerTraps(name, value); @@ -684,7 +679,7 @@ public final class Box extends JSScope implements Scheduler.Task { case "_VScroll": propagateDownward(name, value, false); case "SizeChange": return; - case "ChildChange": return; + case "ChildChange": return; case "Enter": return; case "Leave": return; @@ -753,7 +748,7 @@ public final class Box extends JSScope implements Scheduler.Task { } else { throw new JSExn("fill must be null, a String, or a stream, not a " + value.getClass()); } - dirty(); + DIRTY; } // FIXME: mouse move/release still needs to propagate to boxen in which the mouse was pressed and is still held down @@ -865,7 +860,7 @@ public final class Box extends JSScope implements Scheduler.Task { // Trivial Helper Methods (should be inlined) ///////////////////////////////////////// - void mark_for_repack() { MARK_REPACK; } + void mark_for_repack() { REPACK(); } public Enumeration keys() { throw new Error("you cannot apply for..in to a " + this.getClass().getName()); } public Box getRoot() { return parent == null ? this : parent.getRoot(); } public Surface getSurface() { return Surface.fromBox(getRoot()); } @@ -917,12 +912,12 @@ public final class Box extends JSScope implements Scheduler.Task { /** remove the i^th child */ public void removeChild(int i) { Box b = getChild(i); - MARK_REFLOW_b; - b.dirty(); + b.RECONSTRAIN(); + b.DIRTY; b.clear(MOUSEINSIDE); deleteNode(i); b.parent = null; - MARK_REFLOW; + RECONSTRAIN(); putAndTriggerTrapsAndCatchExceptions("ChildChange", b); } @@ -975,10 +970,10 @@ public final class Box extends JSScope implements Scheduler.Task { b.parent = this; // need both of these in case child was already uncalc'ed - MARK_REFLOW_b; - MARK_REFLOW; + b.RECONSTRAIN(); + RECONSTRAIN(); - b.dirty(); + b.DIRTY; putAndTriggerTrapsAndCatchExceptions("ChildChange", b); } } diff --git a/src/org/ibex/util/Preprocessor.java b/src/org/ibex/util/Preprocessor.java index 5f202fa..a226731 100644 --- a/src/org/ibex/util/Preprocessor.java +++ b/src/org/ibex/util/Preprocessor.java @@ -275,7 +275,7 @@ PROCESS: ret += tok; i = j - 1; } else if (val instanceof JSFunctionMacro) { - if (s.charAt(j) != '(') { err.add(new Error("open paren must follow macro binding for macro " + tok)); continue; } + if (s.charAt(j) != '(') { ret += tok; i = j - 1; continue; } ret += ((JSFunctionMacro)val).process(s.substring(j+1, s.indexOf(')', j))); i = s.indexOf(')', j); } else { -- 1.7.10.4