2003/09/27 07:08:01
authormegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:38:21 +0000 (07:38 +0000)
committermegacz <megacz@xwt.org>
Fri, 30 Jan 2004 07:38:21 +0000 (07:38 +0000)
darcs-hash:20040130073821-2ba56-5c421d3a378f9330dd2cd3881d30d1ce303524dd.gz

src/org/xwt/Box.java.pp

index 71da82f..aac3bd1 100644 (file)
@@ -134,7 +134,7 @@ public final class Box extends JS.Scope {
 
     // Rendering Properties ///////////////////////////////////////////////////////////
 
-    //private SVG.VP path = null;
+    private VectorGraphics.VectorPath path = null;
     //private SVG.Paint fill = null;
     //private SVG.Paint stroke = null;
 
@@ -148,7 +148,10 @@ public final class Box extends JS.Scope {
     // Instance Methods /////////////////////////////////////////////////////////////////////
 
     /** Adds the intersection of (x,y,w,h) and the node's current actual geometry to the Surface's dirty list */
-    public final void dirty() { dirty(0, 0, width, height); }
+    public final void dirty() {
+        if ((flags & NOCLIP_FLAG) != 0 && parent != null) parent.dirty();
+        else dirty(0, 0, width, height);
+    }
     public final void dirty(int x, int y, int w, int h) {
         for(Box cur = this; cur != null; cur = cur.parent) {
             if ((flags & NOCLIP_FLAG) == 0) {
@@ -212,6 +215,10 @@ public final class Box extends JS.Scope {
         if (numChildren() == 0) {
            contentwidth = max(textwidth + 2 * hpad, minwidth);
            contentheight = max(textheight + 2 * vpad, minheight);
+            if (path != null) {
+                contentwidth = max(contentwidth, path.boundingBoxWidth());
+                contentheight = max(contentheight, path.boundingBoxHeight());
+            }
            return;
        }
 
@@ -270,6 +277,10 @@ public final class Box extends JS.Scope {
         for(int col=0; col<numCols; col++) contentwidth += colWidth[col];
         contentwidth = max(textwidth + 2 * hpad, contentwidth);
         contentwidth = bound(minwidth, contentwidth, maxwidth);
+        if (path != null) {
+            contentwidth = max(contentwidth, path.boundingBoxWidth());
+            contentheight = max(contentheight, path.boundingBoxHeight());
+        }
         //#end
     }
 
@@ -388,7 +399,7 @@ public final class Box extends JS.Scope {
     // 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 clipx, int clipy, int clipw, int cliph, PixelBuffer buf) {
+    void render(int parentx, int parenty, int clipx, int clipy, int clipw, int cliph, PixelBuffer buf, VectorGraphics.Affine a) {
         if (Surface.abort || (flags & INVISIBLE_FLAG) != 0) return;
         int globalx = parentx + (parent == null ? 0 : x);
         int globaly = parenty + (parent == null ? 0 : y);
@@ -412,6 +423,12 @@ public final class Box extends JS.Scope {
        if (text != null && !text.equals(""))
             renderText(globalx, globaly, clipx, clipy, clipw, cliph, buf);
 
+        if (path != null) {
+            VectorGraphics.RasterPath rp = path.realize(a);
+            if ((strokecolor & 0xff000000) != 0) rp.stroke(buf, 1, strokecolor);
+            if ((fillcolor & 0xff000000) != 0) rp.fill(buf, new VectorGraphics.SingleColorPaint(fillcolor));
+        }
+
         // now subtract the pad region from the clip region before proceeding
         if ((flags & NOCLIP_FLAG) == 0) {
             clipw = min(max(clipx, globalx + hpad) + clipw, globalx + width - hpad) - clipx;
@@ -420,8 +437,11 @@ public final class Box extends JS.Scope {
             clipy = max(clipy, globaly + vpad);
         }
 
-        for(Box b = getChild(0); b != null; b = b.nextSibling())
-            b.render(globalx, globaly, clipx, clipy, clipw, cliph, buf);   
+        for(Box b = getChild(0); b != null; b = b.nextSibling()) {
+            a.translate(b.x, b.y);
+            b.render(globalx, globaly, clipx, clipy, clipw, cliph, buf, a);
+            a.translate(-1 * b.x, -1 * b.y);
+        }
     }
 
     void renderStretchedImage(int globalx, int globaly, int clipx, int clipy, int clipw, int cliph, PixelBuffer buf) {
@@ -921,6 +941,15 @@ public final class Box extends JS.Scope {
                        b.dirty();
                     } });
 
+            specialBoxProperties.put("path", new SpecialBoxProperty() {
+                    public Object get(Box b) { throw new JS.Exn("cannot read from the path property"); }
+                    public void put(Box b, Object value) {
+                        String t = value == null ? "null" : value.toString();
+                        b.path = value == null ? null : VectorGraphics.parseVectorPath(value.toString());
+                        MARK_FOR_REFLOW_b;
+                       b.dirty();
+                    } });
+
             specialBoxProperties.put("font", new SpecialBoxProperty() {
                     public Object get(Box b) { return b.font; }
                     public void put(Box b, Object value) {