javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java
1.1 --- a/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java Fri May 17 12:06:36 2013 +0200
1.2 +++ b/javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java Fri May 17 12:06:55 2013 +0200
1.3 @@ -1,23 +1,29 @@
1.4 /**
1.5 - * Back 2 Browser Bytecode Translator
1.6 - * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
1.7 + * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
1.8 + * <jaroslav.tulach@apidesign.org>
1.9 *
1.10 - * This program is free software: you can redistribute it and/or modify
1.11 - * it under the terms of the GNU General Public License as published by
1.12 - * the Free Software Foundation, version 2 of the License.
1.13 + * This program is free software: you can redistribute it and/or modify it under
1.14 + * the terms of the GNU General Public License as published by the Free Software
1.15 + * Foundation, version 2 of the License.
1.16 *
1.17 - * This program is distributed in the hope that it will be useful,
1.18 - * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 - * GNU General Public License for more details.
1.21 + * This program is distributed in the hope that it will be useful, but WITHOUT
1.22 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.23 + * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.24 + * details.
1.25 *
1.26 - * You should have received a copy of the GNU General Public License
1.27 - * along with this program. Look for COPYING file in the top folder.
1.28 - * If not, see http://opensource.org/licenses/GPL-2.0.
1.29 + * You should have received a copy of the GNU General Public License along with
1.30 + * this program. Look for COPYING file in the top folder. If not, see
1.31 + * http://opensource.org/licenses/GPL-2.0.
1.32 */
1.33 package org.apidesign.bck2brwsr.htmlpage.api;
1.34
1.35 import net.java.html.canvas.GraphicsContext;
1.36 +import net.java.html.canvas.Image;
1.37 +import net.java.html.canvas.ImageData;
1.38 +import net.java.html.canvas.LinearGradient;
1.39 +import net.java.html.canvas.Pattern;
1.40 +import net.java.html.canvas.RadialGradient;
1.41 +import net.java.html.canvas.TextMetrics;
1.42 import org.apidesign.bck2brwsr.core.JavaScriptBody;
1.43
1.44 /**
1.45 @@ -137,16 +143,19 @@
1.46 @Override
1.47 public native void scale(double x, double y);
1.48
1.49 + @Override
1.50 public void drawImage(Image image, double x, double y) {
1.51 - drawImageImpl(context, Element.getElementById(image), x, y);
1.52 + drawImageImpl(context, Element.getElementById((HTML5Image)image), x, y);
1.53 }
1.54
1.55 + @Override
1.56 public void drawImage(Image image, double x, double y, double width, double height) {
1.57 - drawImageImpl(context, Element.getElementById(image), x, y, width, height);
1.58 + drawImageImpl(context, Element.getElementById((HTML5Image)image), x, y, width, height);
1.59 }
1.60
1.61 + @Override
1.62 public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
1.63 - drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
1.64 + drawImageImpl(context, Element.getElementById((HTML5Image)image), sx, sy, sWidth, sHeight, x, y, width, height);
1.65 }
1.66
1.67 @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
1.68 @@ -166,39 +175,44 @@
1.69 @Override
1.70 public native String getFillStyle();
1.71
1.72 + @Override
1.73 public void setFillStyle(LinearGradient style) {
1.74 - setFillStyleImpl(context, style.object());
1.75 + setFillStyleImpl(context, ((HTML5LinearGradient)style).object());
1.76 }
1.77
1.78 + @Override
1.79 public void setFillStyle(RadialGradient style) {
1.80 - setFillStyleImpl(context, style.object());
1.81 + setFillStyleImpl(context, ((HTML5RadialGradient)style).object());
1.82 }
1.83
1.84 + @Override
1.85 public void setFillStyle(Pattern style) {
1.86 - setFillStyleImpl(context, style.object());
1.87 + setFillStyleImpl(context, ((HTML5Pattern)style).object());
1.88 }
1.89
1.90 - @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;")
1.91 + @JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;")
1.92 private native void setFillStyleImpl(Object context, Object obj);
1.93
1.94 @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
1.95 @Override
1.96 public native void setStrokeStyle(String style);
1.97
1.98 + @Override
1.99 public void setStrokeStyle(LinearGradient style) {
1.100 - setStrokeStyleImpl(context, style.object());
1.101 + setStrokeStyleImpl(context, ((HTML5LinearGradient)style).object());
1.102 }
1.103
1.104 public void setStrokeStyle(RadialGradient style) {
1.105 - setStrokeStyleImpl(context, style.object());
1.106 + setStrokeStyleImpl(context, ((HTML5RadialGradient)style).object());
1.107 }
1.108
1.109 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
1.110 + @Override
1.111 public void setStrokeStyle(Pattern style) {
1.112 - setStrokeStyleImpl(context, style.object());
1.113 + setStrokeStyleImpl(context, ((HTML5LinearGradient)style).object());
1.114 }
1.115
1.116 - @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;")
1.117 + @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
1.118 private native void setStrokeStyleImpl(Object context, Object obj);
1.119
1.120 @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
1.121 @@ -208,7 +222,7 @@
1.122 @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
1.123 @Override
1.124 public native void setShadowBlur(double blur);
1.125 -
1.126 +
1.127 @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
1.128 @Override
1.129 public native void setShadowOffsetX(double x);
1.130 @@ -302,8 +316,9 @@
1.131 public void fillText(String text, double x, double y, double maxWidth) {
1.132 }
1.133
1.134 + @Override
1.135 public TextMetrics measureText(String text) {
1.136 - return new TextMetrics(measureTextImpl(text));
1.137 + return new HTML5TextMetrics(measureTextImpl(text));
1.138 }
1.139
1.140 @JavaScriptBody(args = {"text"},
1.141 @@ -318,36 +333,41 @@
1.142 @Override
1.143 public native void strokeText(String text, double x, double y, double maxWidth);
1.144
1.145 + @Override
1.146 public ImageData createImageData(double x, double y) {
1.147 - return new ImageData(createImageDataImpl(x, y));
1.148 + return new HTML5ImageData(createImageDataImpl(x, y));
1.149 }
1.150
1.151 @JavaScriptBody(args = {"x", "y"},
1.152 body = "return this._context().createImageData(x,y);")
1.153 private native Object createImageDataImpl(double x, double y);
1.154
1.155 + @Override
1.156 public ImageData createImageData(ImageData imageData) {
1.157 - return new ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
1.158 + return new HTML5ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
1.159 }
1.160
1.161 + @Override
1.162 public ImageData getImageData(double x, double y, double width, double height) {
1.163 - return new ImageData(getImageDataImpl(x, y, width, height));
1.164 + return new HTML5ImageData(getImageDataImpl(x, y, width, height));
1.165 }
1.166
1.167 @JavaScriptBody(args = {"x", "y", "width", "height"},
1.168 body = "return this._context().getImageData(x,y,width,height);")
1.169 private native Object getImageDataImpl(double x, double y, double width, double height);
1.170
1.171 + @Override
1.172 public void putImageData(ImageData imageData, double x, double y) {
1.173 - putImageDataImpl(imageData.object(), x, y);
1.174 + putImageDataImpl(((HTML5ImageData)imageData).object(), x, y);
1.175 }
1.176
1.177 @JavaScriptBody(args = {"imageData", "x", "y"},
1.178 body = "this._context().putImageData(imageData,x,y);")
1.179 private native void putImageDataImpl(Object imageData, double x, double y);
1.180
1.181 + @Override
1.182 public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
1.183 - putImageDataImpl(imageData.object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
1.184 + putImageDataImpl(((HTML5ImageData)imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
1.185 }
1.186
1.187 @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
1.188 @@ -370,22 +390,25 @@
1.189 @Override
1.190 public native String getGlobalCompositeOperation();
1.191
1.192 - public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
1.193 - return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
1.194 + @Override
1.195 + public HTML5LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
1.196 + return new HTML5LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
1.197 }
1.198
1.199 @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
1.200 - private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
1.201 + private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
1.202
1.203 + @Override
1.204 public Pattern createPattern(Image image, String repeat) {
1.205 - return new Pattern(createPatternImpl(context, image, repeat));
1.206 + return new HTML5Pattern(createPatternImpl(context, image, repeat));
1.207 }
1.208
1.209 @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
1.210 private static native Object createPatternImpl(Object context, Image image, String repeat);
1.211
1.212 - public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
1.213 - return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
1.214 + @Override
1.215 + public HTML5RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
1.216 + return new HTML5RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
1.217 }
1.218
1.219 @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")