javaquery/api/src/main/java/org/apidesign/bck2brwsr/htmlpage/api/GraphicsContext.java
In order to support fields of the same name in subclasses we are now prefixing them with name of the class that defines them. To provide convenient way to access them from generated bytecode and also directly from JavaScript, there is a getter/setter function for each field. It starts with _ followed by the field name. If called with a parameter, it sets the field, with a parameter it just returns it.
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 org.apidesign.bck2brwsr.core.JavaScriptBody;
24 * @author Anton Epple <toni.epple@eppleton.de>
26 public class GraphicsContext {
30 GraphicsContext(Object contextImpl) {
31 this.context = contextImpl;
34 @JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
35 body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
36 public native void arc(double centerX,
43 @JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
44 body = "this._context().arcTo(x1,y1,x2,y2,r);")
45 public native void arcTo(double x1,
51 @JavaScriptBody(args = {"x", "y"},
52 body = "return this._context().isPointInPath(x,y);")
53 public native boolean isPointInPath(double x, double y);
55 @JavaScriptBody(args = {}, body = "this._context().fill();")
56 public native void fill();
58 @JavaScriptBody(args = {}, body = "this._context().stroke();")
59 public native void stroke();
61 @JavaScriptBody(args = {}, body = "this._context().beginPath();")
62 public native void beginPath();
64 @JavaScriptBody(args = {}, body = "this._context().closePath();")
65 public native void closePath();
67 @JavaScriptBody(args = {}, body = "this._context().clip();")
68 public native void clip();
70 @JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
71 public native void moveTo(double x, double y);
73 @JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
74 public native void lineTo(double x, double y);
76 @JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
77 public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
79 @JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
80 body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
81 public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
83 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
84 public native void fillRect(double x, double y, double width, double height);
86 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
87 public native void strokeRect(double x, double y, double width, double height);
89 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
90 public native void clearRect(double x, double y, double width, double height);
92 @JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
93 public native void rect(double x, double y, double width, double height);
95 @JavaScriptBody(args = {}, body = "this._context().save();")
96 public native void save();
98 @JavaScriptBody(args = {}, body = "this._context().restore();")
99 public native void restore();
101 @JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
102 public native void rotate(double angle);
104 @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
105 public native void transform(double a, double b, double c, double d, double e, double f);
107 @JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
108 public native void setTransform(double a, double b, double c, double d, double e, double f);
110 @JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
111 public native void translate(double x, double y);
113 @JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
114 public native void scale(double x, double y);
116 public void drawImage(Image image, double x, double y) {
117 drawImageImpl(context, Element.getElementById(image), x, y);
120 public void drawImage(Image image, double x, double y, double width, double height) {
121 drawImageImpl(context, Element.getElementById(image), x, y, width, height);
124 public void drawImage(Image image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
125 drawImageImpl(context, Element.getElementById(image), sx, sy, sWidth, sHeight, x, y, width, height);
128 @JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
129 private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
131 @JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
132 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);
134 @JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
135 private native static void drawImageImpl(Object ctx, Object img, double x, double y);
137 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
138 public native void setFillStyle(String style);
140 @JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
141 public native String getFillStyle();
143 public void setFillStyle(LinearGradient style) {
144 setFillStyleImpl(context, style.object());
147 public void setFillStyle(RadialGradient style) {
148 setFillStyleImpl(context, style.object());
151 public void setFillStyle(Pattern style) {
152 setFillStyleImpl(context, style.object());
155 @JavaScriptBody(args = {"context","obj"}, body = "context.fillStyle=obj;")
156 private native void setFillStyleImpl(Object context, Object obj);
158 @JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style;")
159 public native void setStrokeStyle(String style);
161 public void setStrokeStyle(LinearGradient style) {
162 setStrokeStyleImpl(context, style.object());
165 public void setStrokeStyle(RadialGradient style) {
166 setStrokeStyleImpl(context, style.object());
169 @JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style;")
170 public void setStrokeStyle(Pattern style) {
171 setStrokeStyleImpl(context, style.object());
174 @JavaScriptBody(args = {"context","obj"}, body = "context.strokeStyle=obj;")
175 private native void setStrokeStyleImpl(Object context, Object obj);
177 @JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color;")
178 public native void setShadowColor(String color);
180 @JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
181 public native void setShadowBlur(double blur);
183 @JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
184 public native void setShadowOffsetX(double x);
186 @JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
187 public native void setShadowOffsetY(double y);
189 @JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
190 public native String getStrokeStyle();
192 @JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
193 public native String getShadowColor();
195 @JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
196 public native double getShadowBlur();
198 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
199 public native double getShadowOffsetX();
201 @JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
202 public native double getShadowOffsetY();
204 @JavaScriptBody(args = {}, body = "return this._context().lineCap;")
205 public native String getLineCap();
207 @JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style;")
208 public native void setLineCap(String style);
210 @JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
211 public native String getLineJoin();
213 @JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style;")
214 public native void setLineJoin(String style) ;
216 @JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
217 public native double getLineWidth();
219 @JavaScriptBody(args = {"width"}, body = "this._context().lineJoin=width;")
220 public native void setLineWidth(double width);
222 @JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
223 public native double getMiterLimit();
225 @JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
226 public native void setMiterLimit(double limit);
228 @JavaScriptBody(args = {}, body = "return this._context().font;")
229 public native String getFont();
231 @JavaScriptBody(args = {"font"}, body = "this._context().font=font;")
232 public native void setFont(String font);
234 @JavaScriptBody(args = {}, body = "return this._context().textAlign;")
235 public native String getTextAlign();
237 @JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign;")
238 public native void setTextAlign(String textAlign);
240 @JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
241 public native String getTextBaseline();
243 @JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline;")
244 public native void setTextBaseline(String textbaseline);
246 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
247 public native void fillText(String text, double x, double y);
249 @JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
250 public void fillText(String text, double x, double y, double maxWidth) {
253 public TextMetrics measureText(String text) {
254 return new TextMetrics(measureTextImpl(text));
257 @JavaScriptBody(args = {"text"},
258 body = "return this._context().measureText(text);")
259 private native Object measureTextImpl(String text);
261 @JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
262 public native void strokeText(String text, double x, double y);
264 @JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
265 public native void strokeText(String text, double x, double y, double maxWidth) ;
267 public ImageData createImageData(double x, double y) {
268 return new ImageData(createImageDataImpl(x, y));
271 @JavaScriptBody(args = {"x", "y"},
272 body = "return this._context().createImageData(x,y);")
273 private native Object createImageDataImpl(double x, double y);
275 public ImageData createImageData(ImageData imageData) {
276 return new ImageData(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
279 public ImageData getImageData(double x, double y, double width, double height) {
280 return new ImageData(getImageDataImpl(x, y, width, height));
283 @JavaScriptBody(args = {"x", "y", "width", "height"},
284 body = "return this._context().getImageData(x,y,width,height);")
285 private native Object getImageDataImpl(double x, double y, double width, double height);
287 public void putImageData(ImageData imageData, double x, double y) {
288 putImageDataImpl(imageData.object(), x, y);
291 @JavaScriptBody(args = {"imageData", "x", "y"},
292 body = "this._context().putImageData(imageData,x,y);")
293 private native void putImageDataImpl(Object imageData, double x, double y);
295 public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
296 putImageDataImpl(imageData.object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
299 @JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
300 body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
301 private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
303 @JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
304 public native void setGlobalAlpha(double alpha) ;
306 @JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
307 public native double getGlobalAlpha();
309 @JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation;")
310 public native void setGlobalCompositeOperation(double alpha);
312 @JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
313 public native double getGlobalCompositeOperation();
315 public LinearGradient createLinearGradient(double x0, double y0, double x1, double y1) {
316 return new LinearGradient(createLinearGradientImpl(context, x0, y0, x1, y1));
319 @JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
320 private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
322 public Pattern createPattern(Image image, String repeat) {
323 return new Pattern(createPatternImpl(context, image, repeat));
326 @JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
327 private static native Object createPatternImpl(Object context, Image image, String repeat);
329 public RadialGradient createRadialGradient(double x0, double y0, double r0, double x1, double y1, double r1) {
330 return new RadialGradient(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
333 @JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
334 private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);