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=c898d8e1cfb502749b2aa88234e56013cedfa506;hb=fffcafc33aa4066bdf85da7a32e1a1cdb9db2d6f;hpb=4daeeb4119b901d53b44913c86f8af3ce67db925 diff --git a/src/org/ibex/core/Box.java b/src/org/ibex/core/Box.java index c898d8e..bb8a27b 100644 --- a/src/org/ibex/core/Box.java +++ b/src/org/ibex/core/Box.java @@ -1,6 +1,6 @@ // FIXME // Copyright 2004 Adam Megacz, see the COPYING file for licensing [GPL] -package org.ibex; +package org.ibex.core; // FIXME: are traps on x/y meaningful? // FIXME: if we trap on cols, then set rows to 0 (forcing cols to 1), does the cols trap get triggered? @@ -17,7 +17,7 @@ package org.ibex; import java.util.*; import org.ibex.js.*; import org.ibex.util.*; -import org.ibex.translators.*; +import org.ibex.graphics.*; /** *
@@ -38,7 +38,7 @@ import org.ibex.translators.*;
* trigger a Surface.abort; if rendering were done in the same pass,
* rendering work done prior to the Surface.abort would be wasted.
*/
-public final class Box extends JSScope implements Scheduler.Task {
+public final class Box extends JSScope implements Task {
// Macros //////////////////////////////////////////////////////////////////////
@@ -52,7 +52,7 @@ public final class Box extends JSScope implements Scheduler.Task {
//#define CHECKSET_BOOLEAN(prop) boolean nu = toBoolean(value); if (nu == prop) break; prop = nu;
//#define CHECKSET_STRING(prop) if ((value==null&&prop==null)||(value!=null&&JS.toString(value).equals(prop))) break; prop=JS.toString(value);
- protected Box() { super(null); }
+ public Box() { super(null); }
// FIXME memory leak
static Hash boxToCursor = new Hash(500, 3);
@@ -65,8 +65,8 @@ public final class Box extends JSScope implements Scheduler.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 Scheduler.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 VectorGraphics.Affine transform = null;
+ private Affine transform = null;
private VectorGraphics.RasterPath rpath = null;
- private VectorGraphics.Affine rtransform = null;
+ private Affine rtransform = null;
*/
- //#define DIRTY dirty()
-
// Instance Methods /////////////////////////////////////////////////////////////////////
public final int fontSize() { return font == null ? DEFAULT_FONT.pointsize : font.pointsize; }
@@ -143,9 +141,9 @@ public final class Box extends JSScope implements Scheduler.Task {
public void perform() throws JSExn {
if (texture == null) { Log.warn(Box.class, "perform() called with null texture"); return; }
if (texture.isLoaded) {
- setWidth(max(texture.width, maxwidth), maxwidth);
- setHeight(max(texture.height, maxheight), maxheight);
- DIRTY; }
+ setWidth(max(texture.width, minwidth), maxwidth);
+ setHeight(max(texture.height, minheight), maxheight);
+ dirty(); }
else { JS res = texture.stream; texture = null; throw new JSExn("image not found: "+res.unclone()); }
}
@@ -172,11 +170,17 @@ public final class Box extends JSScope implements Scheduler.Task {
// Reflow ////////////////////////////////////////////////////////////////////////////////////////
/** should only be invoked on the root box */
- 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 */
- void pack() {
+ public void pack() {
if (!test(REPACK)) { constrain(); return; }
boolean haskid = false;
for(Box child = getChild(0); child != null; child = child.nextSibling()) { haskid = true; child.pack(); }
@@ -228,7 +232,7 @@ public final class Box extends JSScope implements Scheduler.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 Scheduler.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);
}
@@ -390,7 +394,7 @@ public final class Box extends JSScope implements Scheduler.Task {
// Rendering Pipeline /////////////////////////////////////////////////////////////////////
/** Renders self and children within the specified region. All rendering operations are clipped to xIn,yIn,wIn,hIn */
- void render(int parentx, int parenty, int cx1, int cy1, int cx2, int cy2, PixelBuffer buf, VectorGraphics.Affine a) {
+ public void render(int parentx, int parenty, int cx1, int cy1, int cx2, int cy2, PixelBuffer buf, Affine a) {
if (!test(VISIBLE)) return;
int globalx = parentx + (parent == null ? 0 : x);
int globaly = parenty + (parent == null ? 0 : y);
@@ -420,6 +424,8 @@ public final class Box extends JSScope implements Scheduler.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 Scheduler.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,10 +468,16 @@ public final class Box extends JSScope implements Scheduler.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 "fill": return colorToString(fillcolor);
- case "strokecolor": return colorToString(strokecolor);
- case "textcolor": return colorToString(strokecolor);
+ 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