javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java
Started extracting GraphicsContext interface from JavaQuery API. First extracting methods with primitive parameters and return type.
2 * Back 2 Browser Bytecode Translator
3 * Copyright (C) 2012 Jaroslav Tulach <jaroslav.tulach@apidesign.org>
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2 of the License.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. Look for COPYING file in the top folder.
16 * If not, see http://opensource.org/licenses/GPL-2.0.
18 package org.apidesign.bck2brwsr.htmlpage.api;
20 import net.java.html.canvas.GraphicsContext;
21 import org.apidesign.bck2brwsr.core.JavaScriptBody;
25 * @author Anton Epple <toni.epple@eppleton.de>
27 public class HTML5GraphicsContext implements GraphicsContext {
31 HTML5GraphicsContext(Object contextImpl) {
32 this.context = contextImpl;
35 @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
36 body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
38 public native void arc(double centerX,
45 @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
46 body = "this._context().arcTo(x1,y1,x2,y2,r);")
48 public native void arcTo(double x1,
54 @JavaScriptBody(args = {"x", "y"},
55 body = "return this._context().isPointInPath(x,y);")
57 public native boolean isPointInPath(double x, double y);
59 @JavaScriptBody(args = {}, body = "this._context().fill();")
61 public native void fill();
63 @JavaScriptBody(args = {}, body = "this._context().stroke();")
65 public native void stroke();
67 @JavaScriptBody(args = {}, body = "this._context().beginPath();")
69 public native void beginPath();
71 @JavaScriptBody(args = {}, body = "this._context().closePath();")
73 public native void closePath();
75 @JavaScriptBody(args = {}, body = "this._context().clip();")
77 public native void clip();
79 @JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
81 public native void moveTo(double x, double y);
83 @JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
85 public native void lineTo(double x, double y);
87 @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
89 public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
91 @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
92 body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
94 public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
96 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
98 public native void fillRect(double x, double y, double width, double height);
100 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
102 public native void strokeRect(double x, double y, double width, double height);
104 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
106 public native void clearRect(double x, double y, double width, double height);
108 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
110 public native void rect(double x, double y, double width, double height);
112 @JavaScriptBody(args = {}, body = "this._context().save();")
114 public native void save();
116 @JavaScriptBody(args = {}, body = "this._context().restore();")
118 public native void restore();
120 @JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
122 public native void rotate(double angle);
124 @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
126 public native void transform(double a, double b, double c, double d, double e, double f);
128 @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
130 public native void setTransform(double a, double b, double c, double d, double e, double f);
132 @JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
134 public native void translate(double x, double y);
136 @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
138 public native void scale(double x, double y);
140 public void drawImage(Image image, double x, double y) {
141 drawImageImpl(context, Element.getElementById(image), x, y);
144 public void drawImage(Image image, double x, double y, double width, double height) {
145 drawImageImpl(context, Element.getElementById(image), x, y, width, height);
148 public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
149 drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
152 @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
153 private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
155 @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
156 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);
158 @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
159 private native static void drawImageImpl(Object ctx, Object img, double x, double y);
161 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style.valueOf();")
163 public native void setFillStyle(String style);
165 @JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
167 public native String getFillStyle();
169 public void setFillStyle(LinearGradient style) {
170 setFillStyleImpl(context, style.object());
173 public void setFillStyle(RadialGradient style) {
174 setFillStyleImpl(context, style.object());
177 public void setFillStyle(Pattern style) {
178 setFillStyleImpl(context, style.object());
181 @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;")
182 private native void setFillStyleImpl(Object context, Object obj);
184 @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
186 public native void setStrokeStyle(String style);
188 public void setStrokeStyle(LinearGradient style) {
189 setStrokeStyleImpl(context, style.object());
192 public void setStrokeStyle(RadialGradient style) {
193 setStrokeStyleImpl(context, style.object());
196 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
197 public void setStrokeStyle(Pattern style) {
198 setStrokeStyleImpl(context, style.object());
201 @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;")
202 private native void setStrokeStyleImpl(Object context, Object obj);
204 @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
206 public native void setShadowColor(String color);
208 @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
210 public native void setShadowBlur(double blur);
212 @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
214 public native void setShadowOffsetX(double x);
216 @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
218 public native void setShadowOffsetY(double y);
220 @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
222 public native String getStrokeStyle();
224 @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
226 public native String getShadowColor();
228 @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
230 public native double getShadowBlur();
232 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
234 public native double getShadowOffsetX();
236 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
238 public native double getShadowOffsetY();
240 @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
242 public native String getLineCap();
244 @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
246 public native void setLineCap(String style);
248 @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
250 public native String getLineJoin();
252 @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
254 public native void setLineJoin(String style);
256 @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
258 public native double getLineWidth();
260 @JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
262 public native void setLineWidth(double width);
264 @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
266 public native double getMiterLimit();
268 @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
270 public native void setMiterLimit(double limit);
272 @JavaScriptBody(args = {}, body = "return this._context().font;")
274 public native String getFont();
276 @JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
278 public native void setFont(String font);
280 @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
282 public native String getTextAlign();
284 @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
286 public native void setTextAlign(String textAlign);
288 @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
290 public native String getTextBaseline();
292 @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
294 public native void setTextBaseline(String textbaseline);
296 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
298 public native void fillText(String text, double x, double y);
300 @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
302 public void fillText(String text, double x, double y, double maxWidth) {
305 public TextMetrics measureText(String text) {
306 return new TextMetrics(measureTextImpl(text));
309 @JavaScriptBody(args = {"text"},
310 body = "return this._context().measureText(text);")
311 private native Object measureTextImpl(String text);
313 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
315 public native void strokeText(String text, double x, double y);
317 @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
319 public native void strokeText(String text, double x, double y, double maxWidth);
321 public ImageData createImageData(double x, double y) {
322 return new ImageData(createImageDataImpl(x, y));
325 @JavaScriptBody(args = {"x", "y"},
326 body = "return this._context().createImageData(x,y);")
327 private native Object createImageDataImpl(double x, double y);
329 public ImageData createImageData(ImageData imageData) {
330 return new ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
333 public ImageData getImageData(double x, double y, double width, double height) {
334 return new ImageData(getImageDataImpl(x, y, width, height));
337 @JavaScriptBody(args = {"x", "y", "width", "height"},
338 body = "return this._context().getImageData(x,y,width,height);")
339 private native Object getImageDataImpl(double x, double y, double width, double height);
341 public void putImageData(ImageData imageData, double x, double y) {
342 putImageDataImpl(imageData.object(), x, y);
345 @JavaScriptBody(args = {"imageData", "x", "y"},
346 body = "this._context().putImageData(imageData,x,y);")
347 private native void putImageDataImpl(Object imageData, double x, double y);
349 public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
350 putImageDataImpl(imageData.object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
353 @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
354 body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
355 private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
357 @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
359 public native void setGlobalAlpha(double alpha);
361 @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
363 public native double getGlobalAlpha();
365 @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
367 public native void setGlobalCompositeOperation(String operation);
369 @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
371 public native String getGlobalCompositeOperation();
373 public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
374 return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
377 @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
378 private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
380 public Pattern createPattern(Image image, String repeat) {
381 return new Pattern(createPatternImpl(context, image, repeat));
384 @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
385 private static native Object createPatternImpl(Object context, Image image, String repeat);
387 public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
388 return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
391 @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
392 private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);