From a7bc8922080f56017b141a3835c722344fa4cffc Mon Sep 17 00:00:00 2001 From: megacz Date: Fri, 30 Jan 2004 07:41:24 +0000 Subject: [PATCH] 2003/11/16 02:40:43 darcs-hash:20040130074124-2ba56-0f560ac4cb009c075ef7b664187af4cdf57c451a.gz --- src/org/xwt/Box.java | 103 +++++++++++++++++++++++---------------- src/org/xwt/BoxTree.java | 5 +- src/org/xwt/Font.java | 13 +++-- src/org/xwt/PixelBuffer.java | 14 +++--- src/org/xwt/Surface.java | 17 +++++-- src/org/xwt/Template.java | 2 +- src/org/xwt/VectorGraphics.java | 10 ++-- src/org/xwt/XWT.java | 20 ++++++-- src/org/xwt/builtin/splash.xwt | 21 ++++---- 9 files changed, 124 insertions(+), 81 deletions(-) diff --git a/src/org/xwt/Box.java b/src/org/xwt/Box.java index 60f1fbd..3ac48d4 100644 --- a/src/org/xwt/Box.java +++ b/src/org/xwt/Box.java @@ -93,7 +93,7 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { Box parent = null; Box redirect = this; - int flags = VISIBLE | PACKED; + int flags = VISIBLE | PACKED | REPACK | REFLOW | RESIZE | FIXED /* ROWS */; private String text = null; private Font font = null; @@ -104,9 +104,9 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { // specified directly by user public LENGTH minwidth = 0; - public LENGTH maxwidth = 0; + public LENGTH maxwidth = MAX_LENGTH; public LENGTH minheight = 0; - public LENGTH maxheight = 0; + public LENGTH maxheight = MAX_LENGTH; private short rows = 1; private short cols = 0; private short rowspan = 1; @@ -152,7 +152,9 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { } } + // fixme public void putAndTriggerJSTraps(Object key, Object value) { + put(key, value); } /** update MOUSEINSIDE, check for Enter/Leave/Move */ @@ -191,8 +193,10 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { /** only for use on the root box */ void reflow(int new_width, int new_height) { repack(); + /* new_width = bound(max(contentwidth, minwidth), new_width, test(HSHRINK) ? max(contentwidth, minwidth) : maxwidth); new_height = bound(max(contentheight, minheight), new_height, test(VSHRINK) ? max(contentheight, minheight) : maxheight); + */ resize(x, y, new_width, new_height); resize_children(); } @@ -203,17 +207,18 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { //#repeat COLS/ROWS rows/cols cols/rows col/row row/col colspan/rowspan rowspan/colspan if (test(FIXED) == COLS) { - short r = 0; short rows = 0; - for(Box child = firstPackedChild(); child != null; r++) + short r = 0; + for(Box child = firstPackedChild(); child != null; r++) { for(short col=0, numclear=0; child != null && col < cols;) { if (numRowsInCol[col] > r) continue; if (col != 0 && col + min(cols, child.colspan) > cols) break; if (++numclear < min(cols, child.colspan)) continue; for(int i=col - numclear + 1; i <= col; i++) numRowsInCol[i] += child.rowspan; child.col = col; child.row = r; - child = child.nextPackedSibling(); rows = (short)max(rows, child.row + child.rowspan); + child = child.nextPackedSibling(); } + } for(int i=0; i 0 && startslack != slack;) { - int increment = max(1, slack / cols); - startslack = slack; - for(short col=0; col < cols && slack > 0; col++) { + for(int startslack = 0; x_slack > 0 && cols > 0 && startslack != x_slack;) { + int increment = max(1, x_slack / cols); + startslack = x_slack; + for(short col=0; col < cols; col++) { int diff = min(colMaxWidth[col], colWidth[col] + increment) - colWidth[col]; - slack -= diff; + x_slack -= diff; colWidth[col] += diff; } } @@ -274,22 +279,27 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { // Phase 3: assign childrens' actual sizes for(Box child = getChild(0); child != null; child = child.nextSibling()) { if (!child.test(VISIBLE)) continue; + int child_width, child_height, child_x, child_y; if (!child.test(PACKED)) { - child.resize(child.x, child.y, - child.test(HSHRINK) ? child.contentwidth : min(child.maxwidth, width - child.x), - child.test(VSHRINK) ? child.contentheight : min(child.maxheight, height - child.y)); - continue; + 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 = max(child.minwidth, child_width); + child_height = max(child.minheight, child_height); + } else { + int unbounded; + //#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 \ + // colWidth/rowHeight child_width/child_height ALIGN_RIGHT/ALIGN_BOTTOM ALIGN_LEFT/ALIGN_TOP + unbounded = 0; + for(int i = child.col; i < child.col + child.colspan; i++) unbounded += colWidth[i]; + child_width = bound(child.contentwidth, unbounded, child.test(HSHRINK) ? child.contentwidth : child.maxwidth); + child_x = test(ALIGN_RIGHT) ? x_slack : test(ALIGN_LEFT) ? 0 : x_slack / 2; + for(int i=0; i < child.col; i++) child_x += colWidth[i]; + if (child_width > unbounded) child_x -= (child_width - unbounded) / 2; + //#end } - int unbounded; - //#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 colWidth/rowHeight child_width/child_height - unbounded = 0; - for(int i = child.col; i < child.col + child.colspan; i++) unbounded += colWidth[i]; - int child_width = bound(child.contentwidth, unbounded, child.test(HSHRINK) ? child.contentwidth : child.maxwidth); - int child_x = test(ALIGN_RIGHT) ? slack : test(ALIGN_LEFT) ? slack / 2 : 0; - for(int i=0; i < child.col; i++) child_x += colWidth[i]; - if (child_width < unbounded) child_x += (child_width - unbounded) / 2; - //#end child.resize(child_x, child_y, child_width, child_height); } @@ -318,22 +328,22 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { cy1 = max(cy1, parent == null ? 0 : globaly); cx2 = min(cx2, globalx + width); cy2 = min(cy2, globaly + height); - //if (cx2 <= cx1 || cy2 <= cy1) return; + if (cx2 <= cx1 || cy2 <= cy1) return; } if ((fillcolor & 0xFF000000) != 0x00000000) - buf.fillJSTrapezoid(globalx, globalx + width, globaly, globalx, globalx + width, globaly + height, fillcolor); + buf.fillTrapezoid(globalx, globalx + width, globaly, globalx, globalx + width, globaly + height, fillcolor); if (texture != null) for(int x = globalx; x < cx2; x += texture.getWidth()) for(int y = globaly; y < cy2; y += texture.getHeight()) 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, new Scheduler.Task() { public void perform() { Box b = Box.this; MARK_REFLOW_b; dirty(); }}); - + for(Box b = getChild(0); b != null; b = b.nextSibling()) b.render(globalx, globaly, cx1, cy1, cx2, cy2, buf, null); } @@ -417,21 +427,24 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { //#switch(name) case "text": CHECKSET_STRING(text); MARK_RESIZE; dirty(); + case "strokecolor": value = N(stringToColor((String)value)); CHECKSET_INT(strokecolor); MARK_RESIZE; dirty(); + case "textcolor": value = N(stringToColor((String)value)); CHECKSET_INT(strokecolor); MARK_RESIZE; dirty(); + case "text": CHECKSET_STRING(text); MARK_RESIZE; dirty(); case "strokewidth": CHECKSET_SHORT(strokewidth); dirty(); case "thisbox": if (value == null) remove(); case "shrink": put("hshrink", value); put("vshrink", value); case "hshrink": CHECKSET_FLAG(HSHRINK); MARK_RESIZE; case "vshrink": CHECKSET_FLAG(VSHRINK); MARK_RESIZE; - case "width": CHECKSET_INT(width); MARK_RESIZE; + case "width": if (parent==null&&Surface.fromBox(this)!=null) { CHECKSET_INT(width); } else { put("maxwidth", value); put("minwidth", value); MARK_RESIZE; } + case "height": if (parent == null&&Surface.fromBox(this)!=null) { CHECKSET_INT(height); } else { put("maxheight", value); put("minheight", value); MARK_RESIZE; } case "maxwidth": CHECKSET_INT(maxwidth); MARK_RESIZE; case "minwidth": CHECKSET_INT(minwidth); MARK_RESIZE; - case "height": CHECKSET_INT(height); MARK_RESIZE; case "maxheight": CHECKSET_INT(maxheight); MARK_RESIZE; case "minheight": CHECKSET_INT(minheight); MARK_RESIZE; case "colspan": CHECKSET_SHORT(colspan); MARK_REPACK_parent; case "rowspan": CHECKSET_SHORT(colspan); MARK_REPACK_parent; - case "rows": CHECKSET_SHORT(rows); MARK_REPACK; // FEATURE: error checking - case "cols": CHECKSET_SHORT(cols); MARK_REPACK; // FEATURE: error checking + case "rows": CHECKSET_SHORT(rows); if (rows==0){set(FIXED, COLS);if(cols==0)cols=1;} else set(FIXED, ROWS); MARK_REPACK; + case "cols": CHECKSET_SHORT(cols); if (cols==0){set(FIXED, ROWS);if(rows==0)rows=1;} else set(FIXED, COLS); MARK_REPACK; case "noclip": CHECKSET_FLAG(NOCLIP); if (parent == null) dirty(); else parent.dirty(); case "visible": CHECKSET_FLAG(VISIBLE); dirty(); MARK_RESIZE; dirty(); case "packed": CHECKSET_FLAG(PACKED); MARK_REPACK_parent; @@ -513,7 +526,12 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { } private void setFill(Object value) { - if (value == null || !(value instanceof Res)) return; + if (value == null) return; + if (value instanceof String) { + // FIXME check double set + fillcolor = stringToColor((String)value); + } + if (!(value instanceof Res)) return; Picture pic = Picture.fromRes((Res)value, null); if (pic != null) { texture = pic; @@ -612,6 +630,7 @@ public abstract class Box extends JSScope implements JSTrap.JSTrappable { final boolean inside(int x, int y) { return test(VISIBLE) && x >= 0 && y >= 0 && x < width && y < height; } protected final void set(int mask) { flags |= mask; } + protected final void set(int mask, boolean setclear) { if (setclear) set(mask); else clear(mask); } protected final void clear(int mask) { flags &= ~mask; } protected final boolean test(int mask) { return ((flags & mask) == mask); } diff --git a/src/org/xwt/BoxTree.java b/src/org/xwt/BoxTree.java index 9f89ece..7d2d3d5 100644 --- a/src/org/xwt/BoxTree.java +++ b/src/org/xwt/BoxTree.java @@ -412,7 +412,10 @@ public final class BoxTree extends Box { numchildren++; Box before = getChild(i); - if (before == null) rootChild.peerTree_rightmost().insertAfterMe(b); + if (before == null) { + if (rootChild == null) rootChild = b; + else rootChild.peerTree_rightmost().insertAfterMe(b); + } else before.insertBeforeMe(b); // need both of these in case child was already uncalc'ed diff --git a/src/org/xwt/Font.java b/src/org/xwt/Font.java index 2eef1f1..9f1fad4 100644 --- a/src/org/xwt/Font.java +++ b/src/org/xwt/Font.java @@ -14,7 +14,7 @@ public class Font { public final Res res; public int max_ascent; public int max_descent; - boolean latinCharsPreloaded = false; ///< true if a request to preload ASCII 32-127 has begun + boolean latinCharsPreloaded = true; ///< true if a request to preload ASCII 32-127 has begun Glyph[] glyphs = new Glyph[65535]; public static class Glyph { @@ -59,18 +59,18 @@ public class Font { for(int i=0; i>> 16L); } + public int textwidth(String s) { return (int)((textsize(s) >>> 32) & 0xffffffff); } public int textheight(String s) { return (int)(textsize(s) & 0xffffffffL); } public long textsize(String s) { Long l = (Long)sizeCache.get(s); diff --git a/src/org/xwt/PixelBuffer.java b/src/org/xwt/PixelBuffer.java index 8285f41..740f224 100644 --- a/src/org/xwt/PixelBuffer.java +++ b/src/org/xwt/PixelBuffer.java @@ -25,7 +25,7 @@ public abstract class PixelBuffer { public abstract void drawPicture(Picture source, int dx1, int dy1, int cx1, int cy1, int cx2, int cy2); /** fill a trapezoid whose top and bottom edges are horizontal */ - public abstract void fillJSTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color); + public abstract void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color); /** * Same as drawPicture, but only uses the alpha channel of the Picture, and is allowed to destructively modify the RGB @@ -41,7 +41,7 @@ public abstract class PixelBuffer { if (y1 > y2) { int t = x1; x1 = x2; x2 = t; t = y1; y1 = y2; y2 = t; } if (x1 == x2) { - fillJSTrapezoid(x1 - w / 2, x2 + w / 2, y1 - (capped ? w / 2 : 0), x1 - w / 2, x2 + w / 2, y2 + (capped ? w / 2 : 0), color); + fillTrapezoid(x1 - w / 2, x2 + w / 2, y1 - (capped ? w / 2 : 0), x1 - w / 2, x2 + w / 2, y2 + (capped ? w / 2 : 0), color); return; } @@ -51,9 +51,9 @@ public abstract class PixelBuffer { int last_x = x1; for(int y=y1; y<=y2; y++) { int new_x = (int)((float)(y - y1) / slope) + x1; - if (slope >= 0) fillJSTrapezoid(last_x + 1, y != y2 ? new_x + 1 : new_x, y, + if (slope >= 0) fillTrapezoid(last_x + 1, y != y2 ? new_x + 1 : new_x, y, last_x + 1, y != y2 ? new_x + 1 : new_x, y + 1, color); - else fillJSTrapezoid(y != y2 ? new_x : new_x + 1, last_x, y, + else fillTrapezoid(y != y2 ? new_x : new_x + 1, last_x, y, y != y2 ? new_x : new_x + 1, last_x, y + 1, color); last_x = new_x; } @@ -80,9 +80,9 @@ public abstract class PixelBuffer { y2 += width * Math.sin(phi); } - fillJSTrapezoid(x1 + dx, x1 + dx, y1 - dy, x1 - dx, x1 - dx + slice, y1 + dy, color); // top corner - fillJSTrapezoid(x2 + dx - slice, x2 + dx, y2 - dy, x2 - dx, x2 - dx, y2 + dy, color); // bottom corner - fillJSTrapezoid(x1 - dx, x1 - dx + slice, y1 + dy, x2 + dx - slice, x2 + dx, y2 - dy, color); // middle + fillTrapezoid(x1 + dx, x1 + dx, y1 - dy, x1 - dx, x1 - dx + slice, y1 + dy, color); // top corner + fillTrapezoid(x2 + dx - slice, x2 + dx, y2 - dy, x2 - dx, x2 - dx, y2 + dy, color); // bottom corner + fillTrapezoid(x1 - dx, x1 - dx + slice, y1 + dy, x2 + dx - slice, x2 + dx, y2 - dy, color); // middle } } diff --git a/src/org/xwt/Surface.java b/src/org/xwt/Surface.java index 1ba2d65..36c82ee 100644 --- a/src/org/xwt/Surface.java +++ b/src/org/xwt/Surface.java @@ -84,13 +84,19 @@ public abstract class Surface extends PixelBuffer { public void setLimits(int min_width, int min_height, int max_width, int max_height) { } protected abstract void _setSize(int width, int height); ///< Sets the surface's width and height. + + private int platform_window_width = 0; + private int platform_window_height = 0; protected final void setSize(int width, int height) { if (root.width != width || root.height != height) { + /* root.dirty(0, root.height - Main.scarImage.getHeight(), Main.scarImage.getWidth(), Main.scarImage.getHeight()); + */ root.width = Math.max(Main.scarImage.getWidth(), width); root.height = Math.max(Main.scarImage.getHeight(), height); } - _setSize(root.width, root.height); + if (root.width > 0 && root.height > 0 && platform_window_width != root.width && platform_window_height != root.height) + _setSize(root.width, root.height); } // Helper methods for subclasses //////////////////////////////////////////////////////////// @@ -233,6 +239,8 @@ public abstract class Surface extends PixelBuffer { Scheduler.add(new Message() { public void perform() { if (width == root.width && height == root.height) return; root.set(root.REFLOW); + platform_window_width = width; + platform_window_height = height; do { abort = false; root.reflow(width, height); } while(abort); }}); abort = true; @@ -331,7 +339,7 @@ public abstract class Surface extends PixelBuffer { if (y+h > root.height) h = root.height - y; if (w <= 0 || h <= 0) continue; - root.render(0, 0, x, y, w, h, this, identity); + root.render(0, 0, x, y, x + w, y + h, this, identity); drawPicture(Main.scarImage, 0, root.height - Main.scarImage.getHeight(), x, y, w, h); @@ -391,9 +399,10 @@ public abstract class Surface extends PixelBuffer { backbuffer.drawPictureAlphaOnly(source, dx, dy, cx1, cy1, cx2, cy2, argb); } - public void fillJSTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color) { + public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color) { screenDirtyRegions.dirty(Math.min(x1, x3), y1, Math.max(x2, x4) - Math.min(x1, x3), y2 - y1); - backbuffer.fillJSTrapezoid(x1, x2, y1, x3, x4, y2, color); } + backbuffer.fillTrapezoid(x1, x2, y1, x3, x4, y2, color); + } public void render() { super.render(); diff --git a/src/org/xwt/Template.java b/src/org/xwt/Template.java index 4cd3851..c45134c 100644 --- a/src/org/xwt/Template.java +++ b/src/org/xwt/Template.java @@ -62,7 +62,7 @@ public class Template { new TemplateHelper().parseit(r.getInputStream(), r.t); return r.t; } catch (Exception e) { - if (Log.on) Log.log(r.t.fileName, e); + if (Log.on) Log.log(r.t == null ? "null" : r.t.fileName, e); return null; } } diff --git a/src/org/xwt/VectorGraphics.java b/src/org/xwt/VectorGraphics.java index 212052e..4b29e47 100644 --- a/src/org/xwt/VectorGraphics.java +++ b/src/org/xwt/VectorGraphics.java @@ -620,7 +620,7 @@ public final class VectorGraphics { if (leftSegment == rightSegment || rightSegment == Integer.MAX_VALUE) break; if (leftSegment != -1) if ((useEvenOdd && count % 2 != 0) || (!useEvenOdd && count != 0)) - paint.fillJSTrapezoid(intercept(edges[leftSegment], y0, true, true), + paint.fillTrapezoid(intercept(edges[leftSegment], y0, true, true), intercept(edges[rightSegment], y0, true, true), y0, intercept(edges[leftSegment], y1, true, true), intercept(edges[rightSegment], y1, true, true), y1, @@ -709,14 +709,14 @@ public final class VectorGraphics { public static interface Paint { public abstract void - fillJSTrapezoid(int tx1, int tx2, int ty1, int tx3, int tx4, int ty2, PixelBuffer buf); + fillTrapezoid(int tx1, int tx2, int ty1, int tx3, int tx4, int ty2, PixelBuffer buf); } public static class SingleColorPaint implements Paint { int color; public SingleColorPaint(int color) { this.color = color; } - public void fillJSTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, PixelBuffer buf) { - buf.fillJSTrapezoid(x1, x2, y1, x3, x4, y2, color); + public void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, PixelBuffer buf) { + buf.fillTrapezoid(x1, x2, y1, x3, x4, y2, color); } } @@ -749,7 +749,7 @@ public final class VectorGraphics { int[] stop_colors; float[] stop_offsets; - public void fillJSTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) { + public void fillTrapezoid(float tx1, float tx2, float ty1, float tx3, float tx4, float ty2, PixelBuffer buf) { Affine a = buf.a; Affine inverse = a.copy().invert(); float slope1 = (tx3 - tx1) / (ty2 - ty1); diff --git a/src/org/xwt/XWT.java b/src/org/xwt/XWT.java index bd9ebaf..e14d386 100644 --- a/src/org/xwt/XWT.java +++ b/src/org/xwt/XWT.java @@ -20,12 +20,13 @@ public final class XWT extends JSCallable { private class Sub extends JSCallable { String key; Sub(String key) { this.key = key; } + public String toString() { return "XWTSUB " + key; } public void put(Object key, Object val) { XWT.this.put(this.key + "." + key, val); } - public Object get(Object key) { return XWT.this.get(this.key + "." + key); } + public Object get(Object key) { return XWT.this._get(this.key + "." + key); } public Object call(Object method, JSArray args) { return XWT.this.call(method == null ? key : this.key + "." + method, args); } } - public Object get(Object name) { + public Object _get(Object name) { //#switch(name) case "math": return xwtMath; case "string": return xwtString; @@ -58,13 +59,23 @@ public final class XWT extends JSCallable { case "undocumented": return new Sub("undocumented"); case "undocumented.internal": return new Sub("undocumented.internal"); //#end - return rr.get(name); + + return null; + } + + public Object get(Object name) { + Object ret = _get(name); + if (ret != null) return ret; + return !name.equals("clone") && !name.equals("apply") ? rr.get(name) : null; } public void put(Object name, final Object value) { //#switch(name) case "thread": - Scheduler.add(new Scheduler.Task() { public void perform() { JSContext.invokePauseable((JSFunction)value); } }); + System.out.println("new thread " + value); + Scheduler.add(new Scheduler.Task() { + public String toString() { return "thread task"; } + public void perform() { JSContext.invokePauseable((JSFunction)value); } }); case "ui.clipboard": Platform.setClipBoard((String)value); case "ui.frame": Platform.createSurface((Box)value, true, true); case "ui.window": Platform.createSurface((Box)value, false, true); @@ -138,6 +149,7 @@ public final class XWT extends JSCallable { public static final JSMath xwtMath = new JSMath() { private JS gs = new JSScope.Global(null); + public String toString() { return "XWTMATH"; } public Object get(Object key) { //#switch(key) case "isNaN": return gs.get("isNaN"); diff --git a/src/org/xwt/builtin/splash.xwt b/src/org/xwt/builtin/splash.xwt index 40ed34e..bef5995 100644 --- a/src/org/xwt/builtin/splash.xwt +++ b/src/org/xwt/builtin/splash.xwt @@ -1,24 +1,26 @@ -