javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java
Extracting interfaces from JavaQuery API. Removed first (automatic) refactoring attempt and redid it manually.
2 * Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
3 * <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
14 * You should have received a copy of the GNU General Public License along with
15 * this program. Look for COPYING file in the top folder. If not, see
16 * http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.htmlpage.api;
20 import net.java.html.canvas.GraphicsContext;
21 import net.java.html.canvas.Image;
22 import net.java.html.canvas.ImageData;
23 import net.java.html.canvas.LinearGradient;
24 import net.java.html.canvas.Pattern;
25 import net.java.html.canvas.RadialGradient;
26 import net.java.html.canvas.TextMetrics;
27 import org.apidesign.bck2brwsr.core.JavaScriptBody;
31 * @author Anton Epple <toni.epple@eppleton.de>
33 public class HTML5GraphicsContext implements GraphicsContext {
37 HTML5GraphicsContext(Object contextImpl) {
38 this.context = contextImpl;
41 @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
42 body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
44 public native void arc(double centerX,
51 @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
52 body = "this._context().arcTo(x1,y1,x2,y2,r);")
54 public native void arcTo(double x1,
60 @JavaScriptBody(args = {"x", "y"},
61 body = "return this._context().isPointInPath(x,y);")
63 public native boolean isPointInPath(double x, double y);
65 @JavaScriptBody(args = {}, body = "this._context().fill();")
67 public native void fill();
69 @JavaScriptBody(args = {}, body = "this._context().stroke();")
71 public native void stroke();
73 @JavaScriptBody(args = {}, body = "this._context().beginPath();")
75 public native void beginPath();
77 @JavaScriptBody(args = {}, body = "this._context().closePath();")
79 public native void closePath();
81 @JavaScriptBody(args = {}, body = "this._context().clip();")
83 public native void clip();
85 @JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
87 public native void moveTo(double x, double y);
89 @JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
91 public native void lineTo(double x, double y);
93 @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
95 public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
97 @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
98 body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
100 public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
102 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
104 public native void fillRect(double x, double y, double width, double height);
106 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
108 public native void strokeRect(double x, double y, double width, double height);
110 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
112 public native void clearRect(double x, double y, double width, double height);
114 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
116 public native void rect(double x, double y, double width, double height);
118 @JavaScriptBody(args = {}, body = "this._context().save();")
120 public native void save();
122 @JavaScriptBody(args = {}, body = "this._context().restore();")
124 public native void restore();
126 @JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
128 public native void rotate(double angle);
130 @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
132 public native void transform(double a, double b, double c, double d, double e, double f);
134 @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
136 public native void setTransform(double a, double b, double c, double d, double e, double f);
138 @JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
140 public native void translate(double x, double y);
142 @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
144 public native void scale(double x, double y);
147 public void drawImage(Image image, double x, double y) {
148 drawImageImpl(context, Element.getElementById((HTML5Image)image), x, y);
152 public void drawImage(Image image, double x, double y, double width, double height) {
153 drawImageImpl(context, Element.getElementById((HTML5Image)image), x, y, width, height);
157 public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
158 drawImageImpl(context, Element.getElementById((HTML5Image)image), sx, sy, sWidth, sHeight, x, y, width, height);
161 @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
162 private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
164 @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
165 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);
167 @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
168 private native static void drawImageImpl(Object ctx, Object img, double x, double y);
170 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style.valueOf();")
172 public native void setFillStyle(String style);
174 @JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
176 public native String getFillStyle();
179 public void setFillStyle(LinearGradient style) {
180 setFillStyleImpl(context, ((HTML5LinearGradient)style).object());
184 public void setFillStyle(RadialGradient style) {
185 setFillStyleImpl(context, ((HTML5RadialGradient)style).object());
189 public void setFillStyle(Pattern style) {
190 setFillStyleImpl(context, ((HTML5Pattern)style).object());
193 @JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;")
194 private native void setFillStyleImpl(Object context, Object obj);
196 @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
198 public native void setStrokeStyle(String style);
201 public void setStrokeStyle(LinearGradient style) {
202 setStrokeStyleImpl(context, ((HTML5LinearGradient)style).object());
205 public void setStrokeStyle(RadialGradient style) {
206 setStrokeStyleImpl(context, ((HTML5RadialGradient)style).object());
209 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
211 public void setStrokeStyle(Pattern style) {
212 setStrokeStyleImpl(context, ((HTML5LinearGradient)style).object());
215 @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
216 private native void setStrokeStyleImpl(Object context, Object obj);
218 @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
220 public native void setShadowColor(String color);
222 @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
224 public native void setShadowBlur(double blur);
226 @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
228 public native void setShadowOffsetX(double x);
230 @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
232 public native void setShadowOffsetY(double y);
234 @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
236 public native String getStrokeStyle();
238 @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
240 public native String getShadowColor();
242 @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
244 public native double getShadowBlur();
246 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
248 public native double getShadowOffsetX();
250 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
252 public native double getShadowOffsetY();
254 @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
256 public native String getLineCap();
258 @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
260 public native void setLineCap(String style);
262 @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
264 public native String getLineJoin();
266 @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
268 public native void setLineJoin(String style);
270 @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
272 public native double getLineWidth();
274 @JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
276 public native void setLineWidth(double width);
278 @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
280 public native double getMiterLimit();
282 @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
284 public native void setMiterLimit(double limit);
286 @JavaScriptBody(args = {}, body = "return this._context().font;")
288 public native String getFont();
290 @JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
292 public native void setFont(String font);
294 @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
296 public native String getTextAlign();
298 @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
300 public native void setTextAlign(String textAlign);
302 @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
304 public native String getTextBaseline();
306 @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
308 public native void setTextBaseline(String textbaseline);
310 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
312 public native void fillText(String text, double x, double y);
314 @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
316 public void fillText(String text, double x, double y, double maxWidth) {
320 public TextMetrics measureText(String text) {
321 return new HTML5TextMetrics(measureTextImpl(text));
324 @JavaScriptBody(args = {"text"},
325 body = "return this._context().measureText(text);")
326 private native Object measureTextImpl(String text);
328 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
330 public native void strokeText(String text, double x, double y);
332 @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
334 public native void strokeText(String text, double x, double y, double maxWidth);
337 public ImageData createImageData(double x, double y) {
338 return new HTML5ImageData(createImageDataImpl(x, y));
341 @JavaScriptBody(args = {"x", "y"},
342 body = "return this._context().createImageData(x,y);")
343 private native Object createImageDataImpl(double x, double y);
346 public ImageData createImageData(ImageData imageData) {
347 return new HTML5ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
351 public ImageData getImageData(double x, double y, double width, double height) {
352 return new HTML5ImageData(getImageDataImpl(x, y, width, height));
355 @JavaScriptBody(args = {"x", "y", "width", "height"},
356 body = "return this._context().getImageData(x,y,width,height);")
357 private native Object getImageDataImpl(double x, double y, double width, double height);
360 public void putImageData(ImageData imageData, double x, double y) {
361 putImageDataImpl(((HTML5ImageData)imageData).object(), x, y);
364 @JavaScriptBody(args = {"imageData", "x", "y"},
365 body = "this._context().putImageData(imageData,x,y);")
366 private native void putImageDataImpl(Object imageData, double x, double y);
369 public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
370 putImageDataImpl(((HTML5ImageData)imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
373 @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
374 body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
375 private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
377 @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
379 public native void setGlobalAlpha(double alpha);
381 @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
383 public native double getGlobalAlpha();
385 @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
387 public native void setGlobalCompositeOperation(String operation);
389 @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
391 public native String getGlobalCompositeOperation();
394 public HTML5LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
395 return new HTML5LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
398 @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
399 private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
402 public Pattern createPattern(Image image, String repeat) {
403 return new HTML5Pattern(createPatternImpl(context, image, repeat));
406 @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
407 private static native Object createPatternImpl(Object context, Image image, String repeat);
410 public HTML5RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
411 return new HTML5RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
414 @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
415 private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);