Revision: 4744 http://sourceforge.net/p/vexi/code/4744 Author: mkpg2 Date: 2014-11-10 21:07:42 +0000 (Mon, 10 Nov 2014) Log Message: ----------- ui:Canvas. Drawable area.
Modified Paths: -------------- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/BoxVisual.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Color.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/surface.t Added Paths: ----------- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Texture.java branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/core/canvas.t Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/BoxVisual.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/BoxVisual.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/BoxVisual.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -12,6 +12,7 @@ import org.vexi.graphics.Color; import org.vexi.graphics.Font; import org.vexi.graphics.Picture; +import org.vexi.graphics.Texture; /** * Amalgamates Box's visual properties for memory/runtime efficiency: @@ -30,7 +31,7 @@ short textheight = 0; Font font = DEFAULT_FONT; JSString text = EMPTY_STRING; - Picture texture = null; + Texture texture = null; //////// CONSTRUCTORS ///////////////////////////////////////////// @@ -295,7 +296,7 @@ return true; } - private boolean setTexture(Picture texture, Box box) { + private boolean setTexture(Texture texture, Box box) { if (texture == this.texture) { return false; } Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/core/Surface.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -17,6 +17,7 @@ import org.vexi.graphics.Font; import org.vexi.graphics.Picture; import org.vexi.graphics.PixelBuffer; +import org.vexi.graphics.Texture; import org.vexi.plat.Platform; import org.vexi.util.DirtyList; import org.vexi.util.Log; @@ -904,7 +905,7 @@ * (dx,dy) is the offset within the picture from where to start sampling * (cx1,cy1) to (cx2,cy2) describe the clipping box on the backbuffer which to draw */ - public void drawPicture(Picture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) { + public void drawPicture(Texture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) { backbuffer.drawPicture(source, dx, dy, cx1, cy1, cx2, cy2); } @@ -912,7 +913,7 @@ * (dx1,dy1) to (dx2,dy2) describe the destination area on the backbuffer in which to draw * (sx1,sy1) to (sx2,sy2) describe the source area from which to sample from the image */ - public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { + public void drawPicture(Texture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { backbuffer.drawPicture(source, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2); } Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Color.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Color.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Color.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -234,4 +234,8 @@ standard.put("yellow", new Integer((255 << 16) | (255 << 8) | 0)); standard.put("yellowgreen", new Integer((154 << 16) | (205 << 8) | 50)); } + static public java.awt.Color intToColor(int argb) { + return (argb & 0xFF000000) == 0 ? java.awt.Color.white : + new java.awt.Color((argb >> 16) & 0xff, (argb >> 8) & 0xff, (argb) & 0xff);// TODO Auto-generated method stub + } } Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Picture.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -30,7 +30,7 @@ * implementations may choose to implement caching strategies (for * example, using a Pixmap on X11). */ -public class Picture { +abstract public class Picture implements Texture{ static final SoftReferenceCache<String,Picture> cache = new SoftReferenceCache(); @@ -118,6 +118,13 @@ private Vec loadedCallbacks; ///< list of callbacks interested in this Picture + + public int getWidth(){ return width; } + public int getHeight(){ return height; } + public JS getStream(){ return stream; } + public boolean isLoaded(){ return isLoaded; } + public JSExn getLoadFailed(){ return loadFailed; } + /** invoked when an image is fully loaded; subclasses can use this to initialize platform-specific constructs */ protected synchronized void loaded() { if (loadedCallbacks == null) { @@ -135,6 +142,7 @@ Main.SCHEDULER.add(worker); } } + /** turns a stream into a Picture.Source and once loaded invokes the Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/PixelBuffer.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -20,8 +20,8 @@ public abstract void drawLine(int x1, int y1, int x2, int y2, int color); public abstract void fillTrapezoid(int x1, int x2, int y1, int x3, int x4, int y2, int color); public abstract void fillTriangle(int x1, int y1, int x2, int y2, int x3, int y3, int color); - 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 drawPicture(Texture p, int d1, int d2, int cx1, int cy1, int cx2, int cy2); + public abstract void drawPicture(Texture 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 Added: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Texture.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Texture.java (rev 0) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Texture.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -0,0 +1,19 @@ +package org.vexi.graphics; + +import org.ibex.js.JS; +import org.ibex.js.JSExn; + +public interface Texture { + /** Platform specific underlying object */ + public Object getImage(); + + public int getWidth(); + public int getHeight(); + public JS getStream(); + + public void init(); + + /* Picture loading related */ + public boolean isLoaded(); + public JSExn getLoadFailed(); +} Property changes on: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/graphics/Texture.java ___________________________________________________________________ Added: svn:mime-type ## -0,0 +1 ## +text/plain \ No newline at end of property Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWT.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -237,8 +237,7 @@ private Color rootcolor = null; private final void setBackgroundColor() { rootfill = root.getIntFillcolor(); - rootcolor = (rootfill & 0xFF000000) == 0 ? Color.white : - new Color((rootfill >> 16) & 0xff, (rootfill >> 8) & 0xff, (rootfill) & 0xff); + rootcolor = org.vexi.graphics.Color.intToColor(rootfill); window.setBackground(rootcolor); } Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/AWTBase.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -68,6 +68,7 @@ import org.vexi.graphics.Font; import org.vexi.graphics.Picture; import org.vexi.graphics.PixelBuffer; +import org.vexi.graphics.Texture; import org.vexi.util.Log; /** Shared AWT functionality between AWT and Swing implementations */ @@ -285,6 +286,7 @@ i = Toolkit.getDefaultToolkit().createImage(mis); checkImageIsReady(i); } + public Object getImage() { return i; } } protected static class AWTPixelBuffer implements PixelBuffer { @@ -335,17 +337,17 @@ 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) { - ((AWTPicture)source).init(); + public void drawPicture(Texture source, int dx, int dy, int cx1, int cy1, int cx2, int cy2) { + source.init(); g.setClip(cx1, cy1, cx2 - cx1, cy2 - cy1); - g.drawImage(((AWTPicture)source).i, dx, dy, null); + g.drawImage((Image)source.getImage(), dx, dy, null); g.setClip(0, 0, i.getWidth(null), i.getHeight(null)); } /** draw an scaled image */ - public void drawPicture(Picture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { + public void drawPicture(Texture source, int dx1, int dy1, int dx2, int dy2, int sx1, int sy1, int sx2, int sy2) { ((AWTPicture)source).init(); - g.drawImage(((AWTPicture)source).i, dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); + g.drawImage((Image)source.getImage(), dx1, dy1, dx2, dy2, sx1, sy1, sx2, sy2, null); } /** implemented with java.awt 1.1's setXORMode() */ @@ -589,8 +591,7 @@ private Color rootcolor = null; private final void setBackgroundColor() { rootfill = root.getIntFillcolor(); - rootcolor = (rootfill & 0xFF000000) == 0 ? Color.white : - new Color((rootfill >> 16) & 0xff, (rootfill >> 8) & 0xff, (rootfill) & 0xff); + rootcolor = org.vexi.graphics.Color.intToColor(rootfill); window.setBackground(rootcolor); } Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Platform.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -336,62 +336,6 @@ return p; } } - - - - /** Manages access to ~/.vexi */ - public static class LocalStorage { - - static String vexiDirName = System.getProperty("user.home") + File.separatorChar + ".ibex"; - - static File vexiDir = null; - static File cacheDir = null; - - static { - try { - vexiDir = new File(vexiDirName); - if (!vexiDir.mkdirs()) { - vexiDir = null; - } - try { - cacheDir = new File(vexiDirName + File.separatorChar + "cache"); - if (!cacheDir.mkdirs()) { - cacheDir = null; - } - } catch (Exception e) { - Log.system.warn(LocalStorage.class, "unable to create cache directory " + - vexiDirName + File.separatorChar + "cache"); - } - } catch (Exception e) { - Log.system.warn(LocalStorage.class, "unable to create ibex directory " + vexiDirName); - } - } - - // FEATURE: we ought to be able to do stuff like sha1-checking and date checking on cached resources - public static class Cache { - - private static void delTree(File f) throws IOException { - if (f.isDirectory()) { - String[] s = f.list(); - for (int i=0; i<s.length; i++) { - delTree(new File(f.getPath() + File.separatorChar + s[i])); - } - } - f.delete(); - } - - public static void flush() throws IOException { - delTree(cacheDir); - cacheDir.mkdirs(); - } - - public static File getCacheFileForKey(String key) { - // FEATURE: be smarter here - return new File(cacheDir.getPath() + File.separatorChar + new String(Encode.toBase64(key.getBytes()))); - } - - } - } } Modified: branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/java/org/vexi/plat/Swing.java 2014-11-10 21:07:42 UTC (rev 4744) @@ -419,8 +419,7 @@ return; } rootfill = root.getIntFillcolor(); - rootcolor = (rootfill & 0xFF000000) == 0 ? Color.white : - new Color((rootfill >> 16) & 0xff, (rootfill >> 8) & 0xff, (rootfill) & 0xff); + rootcolor = org.vexi.graphics.Color.intToColor(rootfill); window.setBackground(rootcolor); panel.setBackground(rootcolor); } Modified: branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Box.jpp 2014-11-10 21:07:42 UTC (rev 4744) @@ -156,7 +156,7 @@ * through Surface.abort; if rendering were done in the same pass, * rendering work done prior to the Surface.abort would be wasted.</p> */ -public final class Box extends JS.Obj implements JSArrayLike, Callable, Constants { +public class Box extends JS.Obj implements JSArrayLike, Callable, Constants { // Macros ////////////////////////////////////////////////////////////////////// @@ -369,8 +369,8 @@ // FEATURE: use cx2/cy2 format /** Adds the intersection of (x,y,w,h) and the node's current actual geometry to the Surface's dirty list */ private final void dirtyInPlace(boolean clean) { if (clean) { dirty(); clear(PLACE_CLEAN); } } - private final void dirty() { dirty(this, 0, 0, width, height); } - private static final void dirty(Box b, int x, int y, int w, int h) { + final protected void dirty() { dirty(this, 0, 0, width, height); } + static final public void dirty(Box b, int x, int y, int w, int h) { for (Box cur = b; cur != null; cur = cur.parent) { if (!cur.test(DISPLAY)) { return; @@ -418,17 +418,17 @@ // It is possible that the texture has been removed inbetween, // not an error though it may indicate bad Vexi code. Log.system.debug(Box.class, "Called run() on a Box with a null texture"); - } else if (visual.texture.isLoaded) { + } else if (visual.texture.isLoaded()) { dirty(); // Tiled images affect contentsize if (test(TILE_IMAGE)) { - setMinWidth(visual.texture.width, true); - setMinHeight(visual.texture.height, true); + setMinWidth(visual.texture.getWidth(), true); + setMinHeight(visual.texture.getHeight(), true); setConstrain(); } - } else if (visual.texture.loadFailed!=null) { + } else if (visual.texture.getLoadFailed()!=null) { //JS res = visual.texture.stream; - justTriggerTraps(SC_fill, visual.texture.loadFailed.asObject()); + justTriggerTraps(SC_fill, visual.texture.getLoadFailed().asObject()); visual.resetFill(); // just in case of previous image / fill dirty(); @@ -662,7 +662,7 @@ } } else { if (new_contentwidth < maxwidth && (new_contentwidth < minwidth || new_contentwidth < visual.textwidth || - (visual.texture!=null && new_contentwidth < visual.texture.width))) { + (visual.texture!=null && new_contentwidth < visual.texture.getWidth()))) { set(HAS_WIDTH_SLACK); } else { clear(HAS_WIDTH_SLACK); @@ -1040,9 +1040,9 @@ buf.fillTrapezoid(cx1, cx2, cy1, cx1, cx2, cy2, visual.fillcolor); } - if (visual.texture != null && visual.texture.isLoaded) { - int tw = visual.texture.width; - int th = visual.texture.height; + if (visual.texture != null && visual.texture.isLoaded()) { + int tw = visual.texture.getWidth(); + int th = visual.texture.getHeight(); if (test(TILE_IMAGE)) { for (int x = globalx; x < cx2; x += tw) { for (int y = globaly; y < cy2; y += th) { @@ -1826,7 +1826,7 @@ if (visual.texture == null) { return JSU.S(Color.colorToString(visual.fillcolor)); } - return visual.texture.stream; + return visual.texture.getStream(); /* <p>When an object is written to this property, its stream is read using the * <a href="http://www.freetype.org/" target="_top">freetype2 library</a>, and the @@ -2614,7 +2614,7 @@ case "tile": if (CHECKSET_FLAG(TILE_IMAGE)) { dirty(); - if (visual.texture != null && visual.texture.isLoaded) { + if (visual.texture != null && visual.texture.isLoaded()) { if (test(TILE_IMAGE)) { // this will cause the Box's minimum dimensions // to be set to the image dimensions when tiled Modified: branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp =================================================================== --- branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-core.main/src/main/jpp/org/vexi/core/Vexi.jpp 2014-11-10 21:07:42 UTC (rev 4744) @@ -456,6 +456,7 @@ /* Use to create a new box */ case "ui.Box": return Box.Constructor; + case "ui.Canvas": return Canvas.Constructor; /* Open a URL using the client system's default browser * @method Modified: branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/surface.t =================================================================== --- branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/surface.t 2014-10-31 02:07:32 UTC (rev 4743) +++ branches/vexi3/org.vexi-vexi.widgets/src_main/org/vexi/lib/role/surface.t 2014-11-10 21:07:42 UTC (rev 4744) @@ -139,8 +139,8 @@ } static.getIcons = function(){ - var r = .conf.icon..iconpath; - if(r==null) return [getIconResource()]; + var r = .conf.icon[""]?.iconpath; + if(r==null) return []; return r; }; Added: branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/core/canvas.t =================================================================== --- branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/core/canvas.t (rev 0) +++ branches/vexi3/org.vexi-vexi.widgets/src_poke/poke/core/canvas.t 2014-11-10 21:07:42 UTC (rev 4744) @@ -0,0 +1,58 @@ +<!-- public domain --> + +<vexi xmlns:ui="vexi://ui" xmlns:w="vexi.widget"> + <w:surface /> + <ui:box frameheight="500" framewidth="500"> + <ui:Canvas width="400" height="400"> + drawColor = "black"; + drawWidth = 2; + + var draw = false; + var x0; + var y0; + thisbox.Press1 ++= function(v){ + cascade = v; + draw = true; + const s = surface; + const frameToThis = s.frame.distanceto(thisbox); + const m = s.frame.mouse; + x0 = m.x-frameToThis.x; + y0 = m.y-frameToThis.y; + drawLine(x0,y0,x0,y0); + } + + thisbox.Release1 ++= function(v){ + cascade = v; + draw = false; + }; + + thisbox.Enter ++= function(v){ + cascade = v; + if(draw){ + const s = surface; + const frameToThis = s.frame.distanceto(thisbox); + const m = s.frame.mouse; + x0 = m.x-frameToThis.x; + y0 = m.y-frameToThis.y; + } + }; + + + thisbox.Move ++= function(v){ + cascade = v; + if(draw){ + const s = surface; + const frameToThis = s.frame.distanceto(thisbox); + const m = s.frame.mouse; + var x1 = m.x-frameToThis.x; + var y1 = m.y-frameToThis.y; + drawLine(x0,y0,x1,y1); + x0 = x1; + y0 = y1; + } + } + </ui:Canvas> + + vexi.ui.frame = thisbox; + </ui:box> +</vexi> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. ------------------------------------------------------------------------------ Comprehensive Server Monitoring with Site24x7. Monitor 10 servers for $9/Month. Get alerted through email, SMS, voice calls or mobile push notifications. Take corrective actions from your mobile device. http://pubads.g.doubleclick.net/gampad/clk?id=154624111&iu=/4140/ostg.clktrk _______________________________________________ Vexi-svn mailing list Vexi-svn@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/vexi-svn