javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/HTML5GraphicsContext.java
Pulled up more methods to the interface...
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());
206 public void setStrokeStyle(RadialGradient style) {
207 setStrokeStyleImpl(context, ((HTML5RadialGradient)style).object());
210 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
212 public void setStrokeStyle(Pattern style) {
213 setStrokeStyleImpl(context, ((HTML5LinearGradient)style).object());
216 @JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
217 private native void setStrokeStyleImpl(Object context, Object obj);
219 @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
221 public native void setShadowColor(String color);
223 @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
225 public native void setShadowBlur(double blur);
227 @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
229 public native void setShadowOffsetX(double x);
231 @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
233 public native void setShadowOffsetY(double y);
235 @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
237 public native String getStrokeStyle();
239 @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
241 public native String getShadowColor();
243 @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
245 public native double getShadowBlur();
247 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
249 public native double getShadowOffsetX();
251 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
253 public native double getShadowOffsetY();
255 @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
257 public native String getLineCap();
259 @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
261 public native void setLineCap(String style);
263 @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
265 public native String getLineJoin();
267 @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
269 public native void setLineJoin(String style);
271 @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
273 public native double getLineWidth();
275 @JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
277 public native void setLineWidth(double width);
279 @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
281 public native double getMiterLimit();
283 @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
285 public native void setMiterLimit(double limit);
287 @JavaScriptBody(args = {}, body = "return this._context().font;")
289 public native String getFont();
291 @JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
293 public native void setFont(String font);
295 @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
297 public native String getTextAlign();
299 @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
301 public native void setTextAlign(String textAlign);
303 @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
305 public native String getTextBaseline();
307 @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
309 public native void setTextBaseline(String textbaseline);
311 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
313 public native void fillText(String text, double x, double y);
315 @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
317 public void fillText(String text, double x, double y, double maxWidth) {
321 public TextMetrics measureText(String text) {
322 return new HTML5TextMetrics(measureTextImpl(text));
325 @JavaScriptBody(args = {"text"},
326 body = "return this._context().measureText(text);")
327 private native Object measureTextImpl(String text);
329 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
331 public native void strokeText(String text, double x, double y);
333 @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
335 public native void strokeText(String text, double x, double y, double maxWidth);
338 public ImageData createImageData(double x, double y) {
339 return new HTML5ImageData(createImageDataImpl(x, y));
342 @JavaScriptBody(args = {"x", "y"},
343 body = "return this._context().createImageData(x,y);")
344 private native Object createImageDataImpl(double x, double y);
347 public ImageData createImageData(ImageData imageData) {
348 return new HTML5ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
352 public ImageData getImageData(double x, double y, double width, double height) {
353 return new HTML5ImageData(getImageDataImpl(x, y, width, height));
356 @JavaScriptBody(args = {"x", "y", "width", "height"},
357 body = "return this._context().getImageData(x,y,width,height);")
358 private native Object getImageDataImpl(double x, double y, double width, double height);
361 public void putImageData(ImageData imageData, double x, double y) {
362 putImageDataImpl(((HTML5ImageData)imageData).object(), x, y);
365 @JavaScriptBody(args = {"imageData", "x", "y"},
366 body = "this._context().putImageData(imageData,x,y);")
367 private native void putImageDataImpl(Object imageData, double x, double y);
370 public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
371 putImageDataImpl(((HTML5ImageData)imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
374 @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
375 body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
376 private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
378 @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
380 public native void setGlobalAlpha(double alpha);
382 @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
384 public native double getGlobalAlpha();
386 @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
388 public native void setGlobalCompositeOperation(String operation);
390 @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
392 public native String getGlobalCompositeOperation();
395 public HTML5LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
396 return new HTML5LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
399 @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
400 private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
403 public Pattern createPattern(Image image, String repeat) {
404 return new HTML5Pattern(createPatternImpl(context, image, repeat));
407 @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
408 private static native Object createPatternImpl(Object context, Image image, String repeat);
411 public HTML5RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
412 return new HTML5RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
415 @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
416 private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);