Revision: 4033
          http://vexi.svn.sourceforge.net/vexi/?rev=4033&view=rev
Author:   clrg
Date:     2011-02-13 22:27:02 +0000 (Sun, 13 Feb 2011)

Log Message:
-----------
FEATURE: box.render()
- renders a box and it's content
- currently returns a box with fill set to the image
- FIXME: the constructed Picture is not reusable
- FIXME: currently (though supported by the code) does not honour the rendered 
box's alpha

Modified Paths:
--------------
    trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java
    trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java
    trunk/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java
    trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp

Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java
===================================================================
--- trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java   
2011-02-10 23:37:03 UTC (rev 4032)
+++ trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/GIF.java   
2011-02-13 22:27:02 UTC (rev 4033)
@@ -100,7 +100,7 @@
         // Loop through the blocks in the image.
         int block_identifier;
         while (true) {
-            if(!readIntoBuf(1)) throw new IOException("Unexpected EOF(1)");
+            if (!readIntoBuf(1)) throw new IOException("Unexpected EOF(1)");
             block_identifier = _buf[0];
             if (block_identifier == ';') throw new IOException("No image 
data");
             if (block_identifier == '!') {
@@ -432,14 +432,14 @@
     private int     bitsInWindow = 0;
 
     // Class-wide constants.
-    private static final int INTERLACE      = 0x40;
-    private static final int GLOBALCOLORMAP = 0x80;
-    private static final int LOCALCOLORMAP  = 0x80;
-    private static final int HASTRANSPARENCY    = 0x01;
-    private static final int MAX_LWZ_BITS   = 12;
-    private static final int BUFSIZE        = 280;
-    private static final int[] _interlaceStep   = { 8, 8, 4, 2 };
-    private static final int[] _interlaceStart  = { 0, 4, 2, 1 };
+    private static final int INTERLACE       = 0x40;
+    private static final int GLOBALCOLORMAP  = 0x80;
+    private static final int LOCALCOLORMAP   = 0x80;
+    private static final int HASTRANSPARENCY = 0x01;
+    private static final int MAX_LWZ_BITS    = 12;
+    private static final int BUFSIZE         = 280;
+    private static final int[] _interlaceStep  = { 8, 8, 4, 2 };
+    private static final int[] _interlaceStart = { 0, 4, 2, 1 };
 }
 
 

Modified: 
trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java
===================================================================
--- trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java   
2011-02-10 23:37:03 UTC (rev 4032)
+++ trunk/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java   
2011-02-13 22:27:02 UTC (rev 4033)
@@ -23,6 +23,7 @@
     public abstract void drawPicture(Picture p, int d1, int d2, int cx1, int 
cy1, int cx2, int cy2);
     public abstract void drawPicture(Picture p, int sx1, int sy1, int sx2, int 
sy2, int cx1, int cy1, int cx2, int cy2);
     public abstract void drawGlyph(Font.Glyph source, int dx, int dy, int cx1, 
int cy1, int cx2, int cy2, int argb);
+    public abstract Picture toPicture();
     // FIXME: SVG integration
     //public abstract void drawPicture(Picture p, Affine a, Mesh h);
     //public abstract void drawGlyph(Font.Glyph source, Affine a, Mesh h, int 
rgb, int bg);

Modified: trunk/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java
===================================================================
--- trunk/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java       
2011-02-10 23:37:03 UTC (rev 4032)
+++ trunk/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java       
2011-02-13 22:27:02 UTC (rev 4033)
@@ -241,6 +241,14 @@
         public Image i = null;
         private static ColorModel cmodel = new DirectColorModel(32, 
0x00FF0000, 0x0000FF00, 0x000000FF, 0xFF000000);
         
+        public AWTPicture(Image i) {
+            this.i = i;
+            height = i.getHeight(null);
+            width = i.getWidth(null);
+            isLoaded = true;
+            initialized = true;
+        }
+        
         boolean initialized = false;
         public AWTPicture(JS r) { super(r); }
         public void init() {
@@ -306,6 +314,7 @@
         
         public int getHeight() { return i == null ? 0 : i.getHeight(null); }
         public int getWidth() { return i == null ? 0 : i.getWidth(null); }
+        public Picture toPicture() { return new AWTPicture(i); }
 
         /** draw an unscaled image */
         public void drawPicture(Picture source, int dx, int dy, int cx1, int 
cy1, int cx2, int cy2) {
@@ -376,6 +385,8 @@
     
     protected static class AWTSurface extends Surface.DoubleBufferedSurface
         implements MouseListener, MouseMotionListener, MouseWheelListener, 
KeyListener, ComponentListener, WindowListener {
+        
+        public Picture toPicture() { return new 
AWTPicture(((AWTPixelBuffer)backbuffer).i); }
 
         /** synchronized as otherwise it is possible to blit before images 
have been rendered to the backbuffer */
         public synchronized void blit(PixelBuffer s, int sx, int sy, int dx, 
int dy, int dx2, int dy2) {
@@ -470,7 +481,8 @@
                         newDim.width = minimumSize.width + leftInset + 
rightInset;
                     }
                     frame.setSize(newDim);
-                    frame.repaint();
+                    blit(backbuffer, leftInset, topInset, leftInset, topInset, 
root.width + leftInset, root.height + topInset);
+//                    frame.repaint();
                 }
             };
             
@@ -486,7 +498,7 @@
                     int h = window.getHeight() - topInset - bottomInset;
                     AWTSurface.this.componentResized(w, h);
                 }
-
+                
                 refreshFromBackbuffer(r.x - leftInset, r.y - topInset, 
r.width, r.height);
             }
             public InputMethodRequests getInputMethodRequests() {
@@ -698,7 +710,7 @@
             // First we fill the expanded part of the buffer before
             // an old (dirty) copy of that buffer part gets painted
             // REMARK - synchronized so we won't fill during render
-            synchronized(this) {
+            synchronized (this) {
                 discoverInsets();
                 AWTPixelBuffer buf = (AWTPixelBuffer)backbuffer;
                 //int rootfill = root.getIntFillcolor();

Modified: trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp
===================================================================
--- trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2011-02-10 
23:37:03 UTC (rev 4032)
+++ trunk/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2011-02-13 
22:27:02 UTC (rev 4033)
@@ -18,7 +18,9 @@
 import org.ibex.util.Callable;
 import org.ibex.util.Logger;
 import org.vexi.graphics.Color;
+import org.vexi.graphics.Picture;
 import org.vexi.graphics.PixelBuffer;
+import org.vexi.plat.Platform;
 import org.vexi.util.BasicTree;
 import org.vexi.util.Log;
 
@@ -1645,6 +1647,25 @@
         }
         public JS type() { return SC_distanceto; }
     }
+    
+    /** Renders the content of a box to an image */
+    public Box toImage() { return toImage(0, 0, width, height); }
+    public Box toImage(int x, int y, int w, int h) {
+        PixelBuffer pb = Platform.createPixelBuffer(w, h, null);
+        // FIXME: hack
+        // this bizzare bit of parent manipulation is to get around
+        // the 'getX/YInParent()' look ups in render() for this box
+        Box p = parent;
+        parent = null;
+        render(0, 0, x, y, x+w, x+h, pb);
+        parent = p;
+        // FIXME: another hack
+        // we really should return a re-usable JS stream
+        Box b = new Box();
+        BoxRenderProperties r = b.renderprops = new BoxRenderProperties();
+        r.texture = pb.toPicture();
+        return b;
+    }
  
     /** implements functions that can be invoked on a box in JS */
     public JS callMethod(JS this_, JS method, JS[] args) throws JSExn {
@@ -1652,13 +1673,16 @@
             switch (args.length) {
             case 0:
                 //#switch(JSU.toString(method))
-                case "reflow":
-                    reflow();
-                    return null;
                 case "clear":
                     assertMethodRedirect(method);
                     clear(JSU.N(0));
                     return null;
+                case "reflow":
+                    reflow();
+                    return null;
+                case "render":
+                    reflow();
+                    return toImage();
                 //#end
                 break;
             case 1:
@@ -1722,6 +1746,21 @@
                     return null;
                 //#end
                 break;
+            case 4:
+                //#switch(JSU.toString(method))
+                case "render":
+                    reflow();
+                    int clipx, clipy, clipw, cliph;
+                    try {
+                        clipx = JSU.toInt(args[0]);
+                        clipy = JSU.toInt(args[1]);
+                        clipw = JSU.toInt(args[2]);
+                        cliph = JSU.toInt(args[3]);
+                    } catch (Exception e) {
+                        throw new JSExn("Illegal arguments for render; usage: 
render([<int>, <int>, <int>, <int>])");
+                    }
+                    return toImage(clipx, clipy, clipw, cliph);
+                //#end
             }
         } catch (NullPointerException npe) {
             throw new JSExn("Cannot call "+method+"() with null arguments");
@@ -2194,6 +2233,13 @@
             deprecated("forcereflow", "reflow");
             return get(SC_reflow);
         
+        /* <p>Renders a box and it's content to an image, returning a box 
containing the
+         * image as it's fill property.</p>
+         * 
+         * <p><b>WARNING: experimental; this function may change</b></p>
+         */
+        case "render": return METHOD;
+        
         /* <p>Returns an immutable object that dynamically represents the 
position between
          * of the mouse relative to the box that it was called upon.</p>
          * 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Vexi-svn mailing list
Vexi-svn@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/vexi-svn

Reply via email to