javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java
1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java Fri May 24 12:34:38 2013 +0200
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/HTML5GraphicsEnvironment.java Mon May 27 08:30:30 2013 +0200
1.3 @@ -20,13 +20,16 @@
1.4 import java.util.HashMap;
1.5 import java.util.Set;
1.6 import net.java.html.canvas.Dimension;
1.7 +import net.java.html.canvas.Image;
1.8 import net.java.html.canvas.LinearGradient;
1.9 import net.java.html.canvas.Pattern;
1.10 +import net.java.html.canvas.ImageData;
1.11 import net.java.html.canvas.RadialGradient;
1.12 import net.java.html.canvas.Style;
1.13 import net.java.html.canvas.spi.GraphicsEnvironment;
1.14 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.15 import org.apidesign.bck2brwsr.htmlpage.api.Canvas;
1.16 +import org.apidesign.bck2brwsr.htmlpage.api.Element;
1.17
1.18 /**
1.19 *
1.20 @@ -115,7 +118,7 @@
1.21 @Override
1.22 public native void clearRect(double x, double y, double width, double height);
1.23
1.24 - @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
1.25 + @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rect(x,y,width,height);")
1.26 @Override
1.27 public native void rect(double x, double y, double width, double height);
1.28
1.29 @@ -147,29 +150,39 @@
1.30 @Override
1.31 public native void scale(double x, double y);
1.32
1.33 -//// @Override
1.34 -//// public void drawImage(Image image, double x, double y) {
1.35 -//// drawImageImpl(context, Element.getElementById((Image) image), x, y);
1.36 -//// }
1.37 -////
1.38 -//// @Override
1.39 -//// public void drawImage(Image image, double x, double y, double width, double height) {
1.40 -//// drawImageImpl(context, Element.getElementById((Image) image), x, y, width, height);
1.41 -//// }
1.42 -////
1.43 -//// @Override
1.44 -//// public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
1.45 -//// drawImageImpl(context, Element.getElementById((Image) image), sx, sy, sWidth, sHeight, x, y, width, height);
1.46 -//// }
1.47 -//
1.48 -//// @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
1.49 -//// private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
1.50 -////
1.51 -//// @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
1.52 -//// private native static void drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
1.53 -////
1.54 -//// @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
1.55 -//// private native static void drawImageImpl(Object ctx, Object img, double x, double y);
1.56 + @Override
1.57 + public Object drawImage(Image image, double x, double y, Object nativeImage) {
1.58 + if (nativeImage == null) {
1.59 + nativeImage = createImage(image.getSrc());
1.60 + }
1.61 + return drawImageImpl(context, nativeImage, x, y);
1.62 + }
1.63 +
1.64 + @Override
1.65 + public Object drawImage(Image image, double x, double y, double width, double height, Object nativeImage) {
1.66 + if (nativeImage == null) {
1.67 + nativeImage = createImage(image.getSrc());
1.68 + }
1.69 + return drawImageImpl(context, nativeImage, x, y, width, height);
1.70 + }
1.71 +
1.72 + @Override
1.73 + public Object drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height, Object nativeImage) {
1.74 + if (nativeImage == null) {
1.75 + nativeImage = createImage(image.getSrc());
1.76 + }
1.77 + return drawImageImpl(context, nativeImage, sx, sy, sWidth, sHeight, x, y, width, height);
1.78 + }
1.79 +
1.80 + @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height); return img;")
1.81 + private native static Object drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
1.82 +
1.83 + @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height); return img;")
1.84 + private native static Object drawImageImpl(Object ctx, Object img, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height);
1.85 +
1.86 + @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y); return img;")
1.87 + private native static Object drawImageImpl(Object ctx, Object img, double x, double y);
1.88 +
1.89 public Object setFillStyle(Style style, Object nativeStyle) {
1.90 if (nativeStyle == null) {
1.91 nativeStyle = createNativeStyle(style);
1.92 @@ -225,7 +238,7 @@
1.93
1.94 @Override
1.95 public Object setStrokeStyle(Style style, Object nativeStyle) {
1.96 - if (nativeStyle == null){
1.97 + if (nativeStyle == null) {
1.98 nativeStyle = createNativeStyle(style);
1.99 }
1.100 setStrokeStyleImpl(context, nativeStyle);
1.101 @@ -354,45 +367,46 @@
1.102 @Override
1.103 public native void strokeText(String text, double x, double y, double maxWidth);
1.104
1.105 -//// @Override
1.106 -//// public ImageData createImageData(double x, double y) {
1.107 -//// return new ImageDataWrapper(createImageDataImpl(x, y));
1.108 -//// }
1.109 -////
1.110 -//// @JavaScriptBody(args = {"x", "y"},
1.111 -//// body = "return this._context().createImageData(x,y);")
1.112 -//// private native Object createImageDataImpl(double x, double y);
1.113 -////
1.114 -//// @Override
1.115 -//// public ImageData createImageData(ImageData imageData) {
1.116 -//// return new ImageDataWrapper(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
1.117 -//// }
1.118 -////
1.119 -//// @Override
1.120 -//// public ImageData getImageData(double x, double y, double width, double height) {
1.121 -//// return new ImageDataWrapper(getImageDataImpl(x, y, width, height));
1.122 -//// }
1.123 -//
1.124 -// @JavaScriptBody(args = {"x", "y", "width", "height"},
1.125 -// body = "return this._context().getImageData(x,y,width,height);")
1.126 -// private native Object getImageDataImpl(double x, double y, double width, double height);
1.127 -//
1.128 -//// @Override
1.129 -//// public void putImageData(ImageData imageData, double x, double y) {
1.130 -//// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y);
1.131 -//// }
1.132 -////
1.133 -//// @JavaScriptBody(args = {"imageData", "x", "y"},
1.134 -//// body = "this._context().putImageData(imageData,x,y);")
1.135 -//// private native void putImageDataImpl(Object imageData, double x, double y);
1.136 -////
1.137 -//// @Override
1.138 -//// public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
1.139 -//// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
1.140 -//// }
1.141 + @Override
1.142 + public ImageData createPixelMap(double x, double y) {
1.143 + return new ImageDataWrapper(createPixelMapImpl(x, y));
1.144 + }
1.145 +
1.146 + @JavaScriptBody(args = {"x", "y"},
1.147 + body = "return this._context().createImageData(x,y);")
1.148 + private native Object createPixelMapImpl(double x, double y);
1.149 +
1.150 + @Override
1.151 + public ImageData createPixelMap(ImageData imageData) {
1.152 + return new ImageDataWrapper(createPixelMapImpl(imageData.getWidth(), imageData.getHeight()));
1.153 + }
1.154 +
1.155 + @Override
1.156 + public ImageData getPixelMap(double x, double y, double width, double height) {
1.157 + return new ImageDataWrapper(getPixelMapImpl(x, y, width, height));
1.158 + }
1.159 +
1.160 + @JavaScriptBody(args = {"x", "y", "width", "height"},
1.161 + body = "return this._context().getImageData(x,y,width,height);")
1.162 + private native Object getPixelMapImpl(double x, double y, double width, double height);
1.163 +
1.164 + @Override
1.165 + public void putPixelMap(ImageData imageData, double x, double y) {
1.166 + putPixelMapImpl(((ImageDataWrapper) imageData).object(), x, y);
1.167 + }
1.168 +
1.169 + @JavaScriptBody(args = {"imageData", "x", "y"},
1.170 + body = "this._context().putImageData(imageData,x,y);")
1.171 + private native void putPixelMapImpl(Object imageData, double x, double y);
1.172 +
1.173 + @Override
1.174 + public void putPixelMap(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
1.175 + putPixelMapImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
1.176 + }
1.177 +
1.178 @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
1.179 body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
1.180 - private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
1.181 + private native void putPixelMapImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
1.182
1.183 @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
1.184 @Override
1.185 @@ -417,12 +431,13 @@
1.186 @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
1.187 private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
1.188
1.189 -// public PatternWrapper createPatternWrapper(Image image, String repeat) {
1.190 -// return new PatternWrapper(createPatternImpl(context, image, repeat));
1.191 -// }
1.192 -//
1.193 -// @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
1.194 -// private static native Object createPatternImpl(Object context, Image image, String repeat);
1.195 + public PatternWrapper createPatternWrapper(Image image, String repeat) {
1.196 + return new PatternWrapper(createPatternImpl(context, image, repeat));
1.197 + }
1.198 +
1.199 + @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
1.200 + private static native Object createPatternImpl(Object context, Image image, String repeat);
1.201 +
1.202 public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
1.203 return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
1.204 }
1.205 @@ -430,9 +445,9 @@
1.206 @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
1.207 private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
1.208
1.209 -////
1.210 -//// @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
1.211 -//// public native Image getImageForPath(String path);
1.212 + @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
1.213 + public native Image getImageForPath(String path);
1.214 +
1.215 @Override
1.216 public int getHeight() {
1.217 return canvas.getHeight();
1.218 @@ -452,4 +467,7 @@
1.219 public void setWidth(int width) {
1.220 canvas.setWidth(width);
1.221 }
1.222 +
1.223 + @JavaScriptBody(args = {"src"}, body = "var image = new Image(); image.src = src; return image;")
1.224 + private static native Object createImage(String src);
1.225 }