toni@1111
|
1 |
/**
|
toni@1111
|
2 |
* Back 2 Browser Bytecode Translator Copyright (C) 2012 Jaroslav Tulach
|
toni@1111
|
3 |
* <jaroslav.tulach@apidesign.org>
|
toni@1111
|
4 |
*
|
toni@1111
|
5 |
* This program is free software: you can redistribute it and/or modify it under
|
toni@1111
|
6 |
* the terms of the GNU General Public License as published by the Free Software
|
toni@1111
|
7 |
* Foundation, version 2 of the License.
|
toni@1111
|
8 |
*
|
toni@1111
|
9 |
* This program is distributed in the hope that it will be useful, but WITHOUT
|
toni@1111
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
toni@1111
|
11 |
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
toni@1111
|
12 |
* details.
|
toni@1111
|
13 |
*
|
toni@1111
|
14 |
* You should have received a copy of the GNU General Public License along with
|
toni@1111
|
15 |
* this program. Look for COPYING file in the top folder. If not, see
|
toni@1111
|
16 |
* http://opensource.org/licenses/GPL-2.0.
|
toni@521
|
17 |
*/
|
toni@1135
|
18 |
package org.apidesign.bck2brwsr.htmlpage;
|
toni@521
|
19 |
|
toni@1134
|
20 |
import java.awt.Dimension;
|
toni@1134
|
21 |
import java.util.HashMap;
|
toni@1134
|
22 |
import java.util.Set;
|
toni@1134
|
23 |
import net.java.html.canvas.GraphicsEnvironment;
|
toni@1135
|
24 |
import net.java.html.canvas.ImageData;
|
toni@1134
|
25 |
import net.java.html.canvas.LinearGradient;
|
toni@1134
|
26 |
import net.java.html.canvas.Pattern;
|
toni@1134
|
27 |
import net.java.html.canvas.RadialGradient;
|
toni@1134
|
28 |
import net.java.html.canvas.Style;
|
toni@521
|
29 |
import org.apidesign.bck2brwsr.core.JavaScriptBody;
|
toni@1135
|
30 |
import org.apidesign.bck2brwsr.htmlpage.api.Canvas;
|
toni@1135
|
31 |
import org.apidesign.bck2brwsr.htmlpage.api.Element;
|
toni@1135
|
32 |
import org.apidesign.bck2brwsr.htmlpage.api.Image;
|
toni@521
|
33 |
|
toni@521
|
34 |
/**
|
toni@521
|
35 |
*
|
toni@1112
|
36 |
* @author Anton Epple <toni.epple@eppleton.de>
|
toni@521
|
37 |
*/
|
toni@1134
|
38 |
public class HTML5GraphicsEnvironment implements GraphicsEnvironment {
|
toni@521
|
39 |
|
toni@1112
|
40 |
Object context;
|
toni@1134
|
41 |
Canvas canvas;
|
toni@1135
|
42 |
public HTML5GraphicsEnvironment(Object contextImpl, Canvas canvas) {
|
toni@1112
|
43 |
this.context = contextImpl;
|
toni@1134
|
44 |
this.canvas = canvas;
|
toni@1112
|
45 |
}
|
toni@1112
|
46 |
|
toni@1112
|
47 |
@JavaScriptBody(args = {"centerx", "centery", "radius", "startangle", "endangle", "ccw"},
|
toni@1112
|
48 |
body = "this._context().arc(centerx,centery, radius, startangle, endangle,ccw);")
|
toni@1112
|
49 |
@Override
|
toni@1112
|
50 |
public native void arc(double centerX,
|
toni@1111
|
51 |
double centerY,
|
toni@1111
|
52 |
double startAngle,
|
toni@1111
|
53 |
double radius,
|
toni@1111
|
54 |
double endAngle,
|
toni@1111
|
55 |
boolean ccw);
|
toni@521
|
56 |
|
toni@1112
|
57 |
@JavaScriptBody(args = {"x1", "y1", "x2", "y2", "r"},
|
toni@1112
|
58 |
body = "this._context().arcTo(x1,y1,x2,y2,r);")
|
toni@1112
|
59 |
@Override
|
toni@1112
|
60 |
public native void arcTo(double x1,
|
toni@1111
|
61 |
double y1,
|
toni@1111
|
62 |
double x2,
|
toni@1111
|
63 |
double y2,
|
toni@1111
|
64 |
double r);
|
toni@521
|
65 |
|
toni@1112
|
66 |
@JavaScriptBody(args = {"x", "y"},
|
toni@1112
|
67 |
body = "return this._context().isPointInPath(x,y);")
|
toni@1112
|
68 |
@Override
|
toni@1112
|
69 |
public native boolean isPointInPath(double x, double y);
|
toni@521
|
70 |
|
toni@1112
|
71 |
@JavaScriptBody(args = {}, body = "this._context().fill();")
|
toni@1112
|
72 |
@Override
|
toni@1112
|
73 |
public native void fill();
|
toni@521
|
74 |
|
toni@1112
|
75 |
@JavaScriptBody(args = {}, body = "this._context().stroke();")
|
toni@1112
|
76 |
@Override
|
toni@1112
|
77 |
public native void stroke();
|
toni@1109
|
78 |
|
toni@1112
|
79 |
@JavaScriptBody(args = {}, body = "this._context().beginPath();")
|
toni@1112
|
80 |
@Override
|
toni@1112
|
81 |
public native void beginPath();
|
toni@1109
|
82 |
|
toni@1112
|
83 |
@JavaScriptBody(args = {}, body = "this._context().closePath();")
|
toni@1112
|
84 |
@Override
|
toni@1112
|
85 |
public native void closePath();
|
toni@521
|
86 |
|
toni@1112
|
87 |
@JavaScriptBody(args = {}, body = "this._context().clip();")
|
toni@1112
|
88 |
@Override
|
toni@1112
|
89 |
public native void clip();
|
toni@1109
|
90 |
|
toni@1112
|
91 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().moveTo(x,y);")
|
toni@1112
|
92 |
@Override
|
toni@1112
|
93 |
public native void moveTo(double x, double y);
|
toni@1109
|
94 |
|
toni@1112
|
95 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().lineTo(x,y);")
|
toni@1112
|
96 |
@Override
|
toni@1112
|
97 |
public native void lineTo(double x, double y);
|
toni@1109
|
98 |
|
toni@1112
|
99 |
@JavaScriptBody(args = {"cpx", "cpy", "x", "y"}, body = "this._context().quadraticCurveTo(cpx,cpy,x,y);")
|
toni@1112
|
100 |
@Override
|
toni@1112
|
101 |
public native void quadraticCurveTo(double cpx, double cpy, double x, double y);
|
toni@1109
|
102 |
|
toni@1112
|
103 |
@JavaScriptBody(args = {"cp1x", "cp1y", "cp2x", "cp2y", "x", "y"},
|
toni@1112
|
104 |
body = "this._context().bezierCurveTo(cp1x,cp1y,cp2x,cp2y,x,y);")
|
toni@1112
|
105 |
@Override
|
toni@1112
|
106 |
public native void bezierCurveTo(double cp1x, double cp1y, double cp2x, double cp2y, double x, double y);
|
toni@1109
|
107 |
|
toni@1112
|
108 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().fillRect(x,y,width,height);")
|
toni@1112
|
109 |
@Override
|
toni@1112
|
110 |
public native void fillRect(double x, double y, double width, double height);
|
toni@1109
|
111 |
|
toni@1112
|
112 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().strokeRect(x,y,width,height);")
|
toni@1112
|
113 |
@Override
|
toni@1112
|
114 |
public native void strokeRect(double x, double y, double width, double height);
|
toni@1109
|
115 |
|
toni@1112
|
116 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().clearRect(x,y,width,height);")
|
toni@1112
|
117 |
@Override
|
toni@1112
|
118 |
public native void clearRect(double x, double y, double width, double height);
|
toni@1109
|
119 |
|
toni@1112
|
120 |
@JavaScriptBody(args = {"x", "y", "width", "height"}, body = "this._context().rectect(x,y,width,height);")
|
toni@1112
|
121 |
@Override
|
toni@1112
|
122 |
public native void rect(double x, double y, double width, double height);
|
toni@1109
|
123 |
|
toni@1112
|
124 |
@JavaScriptBody(args = {}, body = "this._context().save();")
|
toni@1112
|
125 |
@Override
|
toni@1112
|
126 |
public native void save();
|
toni@1109
|
127 |
|
toni@1112
|
128 |
@JavaScriptBody(args = {}, body = "this._context().restore();")
|
toni@1112
|
129 |
@Override
|
toni@1112
|
130 |
public native void restore();
|
toni@1109
|
131 |
|
toni@1112
|
132 |
@JavaScriptBody(args = {"angle"}, body = "this._context().rotate(angle);")
|
toni@1112
|
133 |
@Override
|
toni@1112
|
134 |
public native void rotate(double angle);
|
toni@1109
|
135 |
|
toni@1112
|
136 |
@JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().transform(a,b,c,d,e,f);")
|
toni@1112
|
137 |
@Override
|
toni@1112
|
138 |
public native void transform(double a, double b, double c, double d, double e, double f);
|
toni@1109
|
139 |
|
toni@1112
|
140 |
@JavaScriptBody(args = {"a", "b", "c", "d", "e", "f"}, body = "this._context().setTransform(a,b,c,d,e,f);")
|
toni@1112
|
141 |
@Override
|
toni@1112
|
142 |
public native void setTransform(double a, double b, double c, double d, double e, double f);
|
toni@1109
|
143 |
|
toni@1112
|
144 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().translate(x,y);")
|
toni@1112
|
145 |
@Override
|
toni@1112
|
146 |
public native void translate(double x, double y);
|
toni@1109
|
147 |
|
toni@1112
|
148 |
@JavaScriptBody(args = {"x", "y"}, body = "this._context().scale(x,y);")
|
toni@1112
|
149 |
@Override
|
toni@1112
|
150 |
public native void scale(double x, double y);
|
toni@1109
|
151 |
|
toni@1112
|
152 |
@Override
|
toni@1135
|
153 |
public void drawImage(ImageData image, double x, double y) {
|
toni@1135
|
154 |
drawImageImpl(context, Element.getElementById((Image) image), x, y);
|
toni@1112
|
155 |
}
|
toni@1109
|
156 |
|
toni@1112
|
157 |
@Override
|
toni@1135
|
158 |
public void drawImage(ImageData image, double x, double y, double width, double height) {
|
toni@1135
|
159 |
drawImageImpl(context, Element.getElementById((Image) image), x, y, width, height);
|
toni@1112
|
160 |
}
|
toni@1109
|
161 |
|
toni@1112
|
162 |
@Override
|
toni@1135
|
163 |
public void drawImage(ImageData image, double sx, double sy, double sWidth, double sHeight, double x, double y, double width, double height) {
|
toni@1135
|
164 |
drawImageImpl(context, Element.getElementById((Image) image), sx, sy, sWidth, sHeight, x, y, width, height);
|
toni@1112
|
165 |
}
|
toni@1109
|
166 |
|
toni@1112
|
167 |
@JavaScriptBody(args = {"ctx", "img", "x", "y", "width", "height"}, body = "ctx.drawImage(img,x,y,width,height);")
|
toni@1112
|
168 |
private native static void drawImageImpl(Object ctx, Object img, double x, double y, double width, double height);
|
toni@1109
|
169 |
|
toni@1112
|
170 |
@JavaScriptBody(args = {"ctx", "img", "sx", "sy", "swidth", "sheight", "x", "y", "width", "height"}, body = "ctx.drawImage(img,sx,sy,swidth,sheight,x,y,width,height);")
|
toni@1112
|
171 |
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);
|
toni@1109
|
172 |
|
toni@1112
|
173 |
@JavaScriptBody(args = {"ctx", "img", "x", "y"}, body = "ctx.drawImage(img,x,y);")
|
toni@1112
|
174 |
private native static void drawImageImpl(Object ctx, Object img, double x, double y);
|
toni@1109
|
175 |
|
toni@1112
|
176 |
@JavaScriptBody(args = {"style"}, body = "this._context().fillStyle=style.valueOf();")
|
toni@1112
|
177 |
@Override
|
toni@1112
|
178 |
public native void setFillStyle(String style);
|
toni@1109
|
179 |
|
toni@1112
|
180 |
@JavaScriptBody(args = {}, body = "return this._context().fillStyle;")
|
toni@1112
|
181 |
@Override
|
toni@1112
|
182 |
public native String getFillStyle();
|
toni@1109
|
183 |
|
toni@1112
|
184 |
@Override
|
toni@1134
|
185 |
public void setFillStyle(Style style) {
|
toni@1134
|
186 |
setFillStyleImpl(context, createFillStyle(style));
|
toni@1112
|
187 |
}
|
toni@1109
|
188 |
|
toni@1134
|
189 |
private Object createFillStyle(Style style) {
|
toni@1134
|
190 |
if (style instanceof RadialGradient) {
|
toni@1134
|
191 |
RadialGradientWrapper gradient = createRadialGradientWrapper(
|
toni@1134
|
192 |
((RadialGradient) style).getX0(),
|
toni@1134
|
193 |
((RadialGradient) style).getY0(),
|
toni@1134
|
194 |
((RadialGradient) style).getR0(),
|
toni@1134
|
195 |
((RadialGradient) style).getX1(),
|
toni@1134
|
196 |
((RadialGradient) style).getY1(),
|
toni@1134
|
197 |
((RadialGradient) style).getR1());
|
toni@1134
|
198 |
HashMap<Double, String> stops = ((LinearGradient) style).getStops();
|
toni@1134
|
199 |
Set<Double> keySet = stops.keySet();
|
toni@1134
|
200 |
for (Double double1 : keySet) {
|
toni@1134
|
201 |
addColorStopImpl(style, double1, stops.get(double1));
|
toni@1134
|
202 |
}
|
toni@1134
|
203 |
return gradient;
|
toni@1134
|
204 |
|
toni@1134
|
205 |
|
toni@1134
|
206 |
} else if (style instanceof LinearGradient) {
|
toni@1134
|
207 |
LinearGradientWrapper gradient = createLinearGradientWrapper(
|
toni@1134
|
208 |
((LinearGradient) style).getX0(),
|
toni@1134
|
209 |
((LinearGradient) style).getY0(),
|
toni@1134
|
210 |
((LinearGradient) style).getX1(),
|
toni@1134
|
211 |
((LinearGradient) style).getY1());
|
toni@1134
|
212 |
HashMap<Double, String> stops = ((LinearGradient) style).getStops();
|
toni@1134
|
213 |
Set<Double> keySet = stops.keySet();
|
toni@1134
|
214 |
for (Double double1 : keySet) {
|
toni@1134
|
215 |
addColorStopImpl(style, double1, stops.get(double1));
|
toni@1134
|
216 |
}
|
toni@1134
|
217 |
return gradient;
|
toni@1134
|
218 |
} else if (style instanceof Pattern) {
|
toni@1134
|
219 |
return createPatternWrapper(((Pattern) style).getImageData(), ((Pattern) style).getRepeat());
|
toni@1134
|
220 |
}
|
toni@1134
|
221 |
return null;
|
toni@1112
|
222 |
}
|
toni@1109
|
223 |
|
toni@1134
|
224 |
|
toni@1134
|
225 |
@JavaScriptBody(args = {"gradient", "position", "color"}, body =
|
toni@1134
|
226 |
"gradient.addColorStop(position,color)")
|
toni@1134
|
227 |
private static native void addColorStopImpl(Object gradient, double position, String color);
|
toni@1109
|
228 |
|
toni@1112
|
229 |
@JavaScriptBody(args = {"context", "obj"}, body = "context.fillStyle=obj;")
|
toni@1112
|
230 |
private native void setFillStyleImpl(Object context, Object obj);
|
toni@1109
|
231 |
|
toni@1112
|
232 |
@JavaScriptBody(args = {"style"}, body = "this._context().strokeStyle=style.valueOf();")
|
toni@1112
|
233 |
@Override
|
toni@1112
|
234 |
public native void setStrokeStyle(String style);
|
toni@1109
|
235 |
|
toni@1112
|
236 |
@Override
|
toni@1134
|
237 |
public void setStrokeStyle(Style style) {
|
toni@1134
|
238 |
setStrokeStyleImpl(context, createFillStyle(style));
|
toni@1112
|
239 |
}
|
toni@1109
|
240 |
|
toni@1112
|
241 |
@JavaScriptBody(args = {"context", "obj"}, body = "context.strokeStyle=obj;")
|
toni@1112
|
242 |
private native void setStrokeStyleImpl(Object context, Object obj);
|
toni@1109
|
243 |
|
toni@1112
|
244 |
@JavaScriptBody(args = {"color"}, body = "this._context().shadowColor=color.valueOf();")
|
toni@1112
|
245 |
@Override
|
toni@1112
|
246 |
public native void setShadowColor(String color);
|
toni@1109
|
247 |
|
toni@1112
|
248 |
@JavaScriptBody(args = {"blur"}, body = "this._context().shadowBlur=blur;")
|
toni@1112
|
249 |
@Override
|
toni@1112
|
250 |
public native void setShadowBlur(double blur);
|
toni@1109
|
251 |
|
toni@1112
|
252 |
@JavaScriptBody(args = {"x"}, body = "this._context().shadowOffsetX=x;")
|
toni@1112
|
253 |
@Override
|
toni@1112
|
254 |
public native void setShadowOffsetX(double x);
|
toni@1109
|
255 |
|
toni@1112
|
256 |
@JavaScriptBody(args = {"y"}, body = "this._context().shadowOffsetY=y;")
|
toni@1112
|
257 |
@Override
|
toni@1112
|
258 |
public native void setShadowOffsetY(double y);
|
toni@1109
|
259 |
|
toni@1112
|
260 |
@JavaScriptBody(args = {}, body = "return this._context().strokeStyle;")
|
toni@1112
|
261 |
@Override
|
toni@1112
|
262 |
public native String getStrokeStyle();
|
toni@1109
|
263 |
|
toni@1112
|
264 |
@JavaScriptBody(args = {}, body = "return this._context().shadowColor;")
|
toni@1112
|
265 |
@Override
|
toni@1112
|
266 |
public native String getShadowColor();
|
toni@1109
|
267 |
|
toni@1112
|
268 |
@JavaScriptBody(args = {}, body = "return this._context().shadowBlur;")
|
toni@1112
|
269 |
@Override
|
toni@1112
|
270 |
public native double getShadowBlur();
|
toni@1109
|
271 |
|
toni@1112
|
272 |
@JavaScriptBody(args = {}, body = "return this._context().shadowOffsetX;")
|
toni@1112
|
273 |
@Override
|
toni@1112
|
274 |
public native double getShadowOffsetX();
|
toni@1109
|
275 |
|
toni@1112
|
276 |
@JavaScriptBody(args = {}, body = "return this._context().shadowOffsetY;")
|
toni@1112
|
277 |
@Override
|
toni@1112
|
278 |
public native double getShadowOffsetY();
|
toni@1109
|
279 |
|
toni@1112
|
280 |
@JavaScriptBody(args = {}, body = "return this._context().lineCap;")
|
toni@1112
|
281 |
@Override
|
toni@1112
|
282 |
public native String getLineCap();
|
toni@1109
|
283 |
|
toni@1112
|
284 |
@JavaScriptBody(args = {"style"}, body = "this._context().lineCap=style.valueOf();")
|
toni@1112
|
285 |
@Override
|
toni@1112
|
286 |
public native void setLineCap(String style);
|
toni@521
|
287 |
|
toni@1112
|
288 |
@JavaScriptBody(args = {}, body = "return this._context().lineJoin;")
|
toni@1112
|
289 |
@Override
|
toni@1112
|
290 |
public native String getLineJoin();
|
toni@521
|
291 |
|
toni@1112
|
292 |
@JavaScriptBody(args = {"style"}, body = "this._context().lineJoin=style.valueOf();")
|
toni@1112
|
293 |
@Override
|
toni@1112
|
294 |
public native void setLineJoin(String style);
|
toni@521
|
295 |
|
toni@1112
|
296 |
@JavaScriptBody(args = {}, body = "return this._context().lineWidth;")
|
toni@1112
|
297 |
@Override
|
toni@1112
|
298 |
public native double getLineWidth();
|
toni@521
|
299 |
|
toni@1112
|
300 |
@JavaScriptBody(args = {"width"}, body = "this._context().lineWidth=width;")
|
toni@1112
|
301 |
@Override
|
toni@1112
|
302 |
public native void setLineWidth(double width);
|
toni@521
|
303 |
|
toni@1112
|
304 |
@JavaScriptBody(args = {}, body = "return this._context().miterLimit;")
|
toni@1112
|
305 |
@Override
|
toni@1112
|
306 |
public native double getMiterLimit();
|
toni@521
|
307 |
|
toni@1112
|
308 |
@JavaScriptBody(args = {"limit"}, body = "this._context().miterLimit=limit;")
|
toni@1112
|
309 |
@Override
|
toni@1112
|
310 |
public native void setMiterLimit(double limit);
|
toni@1111
|
311 |
|
toni@1112
|
312 |
@JavaScriptBody(args = {}, body = "return this._context().font;")
|
toni@1112
|
313 |
@Override
|
toni@1112
|
314 |
public native String getFont();
|
toni@1111
|
315 |
|
toni@1112
|
316 |
@JavaScriptBody(args = {"font"}, body = "this._context().font=font.valueOf();")
|
toni@1112
|
317 |
@Override
|
toni@1112
|
318 |
public native void setFont(String font);
|
toni@1111
|
319 |
|
toni@1112
|
320 |
@JavaScriptBody(args = {}, body = "return this._context().textAlign;")
|
toni@1112
|
321 |
@Override
|
toni@1112
|
322 |
public native String getTextAlign();
|
toni@1111
|
323 |
|
toni@1112
|
324 |
@JavaScriptBody(args = {"textalign"}, body = "this._context().textAlign=textalign.valueOf();")
|
toni@1112
|
325 |
@Override
|
toni@1112
|
326 |
public native void setTextAlign(String textAlign);
|
toni@1111
|
327 |
|
toni@1112
|
328 |
@JavaScriptBody(args = {}, body = "return this._context().textBaseline;")
|
toni@1112
|
329 |
@Override
|
toni@1112
|
330 |
public native String getTextBaseline();
|
toni@1111
|
331 |
|
toni@1112
|
332 |
@JavaScriptBody(args = {"textbaseline"}, body = "this._context().textBaseline=textbaseline.valueOf();")
|
toni@1112
|
333 |
@Override
|
toni@1112
|
334 |
public native void setTextBaseline(String textbaseline);
|
toni@1111
|
335 |
|
toni@1112
|
336 |
@JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().fillText(text,x,y);")
|
toni@1112
|
337 |
@Override
|
toni@1112
|
338 |
public native void fillText(String text, double x, double y);
|
toni@1111
|
339 |
|
toni@1112
|
340 |
@JavaScriptBody(args = {"text", "x", "y", "maxwidth"}, body = "this._context().fillText(text,x,y,maxwidth);")
|
toni@1112
|
341 |
@Override
|
toni@1112
|
342 |
public void fillText(String text, double x, double y, double maxWidth) {
|
toni@1112
|
343 |
}
|
toni@1111
|
344 |
|
toni@1112
|
345 |
@Override
|
toni@1134
|
346 |
public Dimension measureText(String text) {
|
toni@1134
|
347 |
TextMetrics textMetrics = new TextMetrics(measureTextImpl(text));
|
toni@1134
|
348 |
return new Dimension((int) textMetrics.getWidth(), (int) textMetrics.getHeight());
|
toni@1112
|
349 |
}
|
toni@1111
|
350 |
|
toni@1112
|
351 |
@JavaScriptBody(args = {"text"},
|
toni@1112
|
352 |
body = "return this._context().measureText(text);")
|
toni@1112
|
353 |
private native Object measureTextImpl(String text);
|
toni@1111
|
354 |
|
toni@1112
|
355 |
@JavaScriptBody(args = {"text", "x", "y"}, body = "this._context().strokeText(text,x,y);")
|
toni@1112
|
356 |
@Override
|
toni@1112
|
357 |
public native void strokeText(String text, double x, double y);
|
toni@1111
|
358 |
|
toni@1112
|
359 |
@JavaScriptBody(args = {"text", "x", "y", "maxWidth"}, body = "this._context().strokeText(text,x,y,maxWidth);")
|
toni@1112
|
360 |
@Override
|
toni@1112
|
361 |
public native void strokeText(String text, double x, double y, double maxWidth);
|
toni@1111
|
362 |
|
toni@1134
|
363 |
// @Override
|
toni@1135
|
364 |
// public ImageData createImageData(double x, double y) {
|
toni@1134
|
365 |
// return new ImageDataWrapper(createImageDataImpl(x, y));
|
toni@1134
|
366 |
// }
|
toni@1134
|
367 |
//
|
toni@1134
|
368 |
// @JavaScriptBody(args = {"x", "y"},
|
toni@1134
|
369 |
// body = "return this._context().createImageData(x,y);")
|
toni@1134
|
370 |
// private native Object createImageDataImpl(double x, double y);
|
toni@1134
|
371 |
//
|
toni@1134
|
372 |
// @Override
|
toni@1135
|
373 |
// public ImageData createImageData(ImageData imageData) {
|
toni@1134
|
374 |
// return new ImageDataWrapper(createImageDataImpl(imageData.getWidth(), imageData.getHeight()));
|
toni@1134
|
375 |
// }
|
toni@1134
|
376 |
//
|
toni@1134
|
377 |
// @Override
|
toni@1135
|
378 |
// public ImageData getImageData(double x, double y, double width, double height) {
|
toni@1134
|
379 |
// return new ImageDataWrapper(getImageDataImpl(x, y, width, height));
|
toni@1134
|
380 |
// }
|
toni@1111
|
381 |
|
toni@1112
|
382 |
@JavaScriptBody(args = {"x", "y", "width", "height"},
|
toni@1112
|
383 |
body = "return this._context().getImageData(x,y,width,height);")
|
toni@1112
|
384 |
private native Object getImageDataImpl(double x, double y, double width, double height);
|
toni@1111
|
385 |
|
toni@1134
|
386 |
// @Override
|
toni@1135
|
387 |
// public void putImageData(ImageData imageData, double x, double y) {
|
toni@1134
|
388 |
// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y);
|
toni@1134
|
389 |
// }
|
toni@1134
|
390 |
//
|
toni@1134
|
391 |
// @JavaScriptBody(args = {"imageData", "x", "y"},
|
toni@1134
|
392 |
// body = "this._context().putImageData(imageData,x,y);")
|
toni@1134
|
393 |
// private native void putImageDataImpl(Object imageData, double x, double y);
|
toni@1134
|
394 |
//
|
toni@1134
|
395 |
// @Override
|
toni@1135
|
396 |
// public void putImageData(ImageData imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight) {
|
toni@1134
|
397 |
// putImageDataImpl(((ImageDataWrapper) imageData).object(), x, y, dirtyx, dirtyy, dirtywidth, dirtyheight);
|
toni@1134
|
398 |
// }
|
toni@1112
|
399 |
|
toni@1112
|
400 |
@JavaScriptBody(args = {"imageData", "x", "y", "dirtyx", "dirtyy", "dirtywidth", "dirtyheight"},
|
toni@1112
|
401 |
body = "this._context().putImageData(imageData,x,y, dirtyx, dirtyy, dirtywidth,dirtyheight);")
|
toni@1112
|
402 |
private native void putImageDataImpl(Object imageData, double x, double y, double dirtyx, double dirtyy, double dirtywidth, double dirtyheight);
|
toni@1112
|
403 |
|
toni@1112
|
404 |
@JavaScriptBody(args = {"alpha"}, body = "this._context().globalAlpha=alpha;")
|
toni@1112
|
405 |
@Override
|
toni@1112
|
406 |
public native void setGlobalAlpha(double alpha);
|
toni@1112
|
407 |
|
toni@1112
|
408 |
@JavaScriptBody(args = {}, body = "return this._context().globalAlpha;")
|
toni@1112
|
409 |
@Override
|
toni@1112
|
410 |
public native double getGlobalAlpha();
|
toni@1112
|
411 |
|
toni@1112
|
412 |
@JavaScriptBody(args = {"operation"}, body = "this._context().globalCompositeOperation=operation.valueOf();")
|
toni@1112
|
413 |
@Override
|
toni@1112
|
414 |
public native void setGlobalCompositeOperation(String operation);
|
toni@1112
|
415 |
|
toni@1112
|
416 |
@JavaScriptBody(args = {}, body = "return this._context().globalCompositeOperation;")
|
toni@1112
|
417 |
@Override
|
toni@1112
|
418 |
public native String getGlobalCompositeOperation();
|
toni@1112
|
419 |
|
toni@1134
|
420 |
public LinearGradientWrapper createLinearGradientWrapper(double x0, double y0, double x1, double y1) {
|
toni@1134
|
421 |
return new LinearGradientWrapper(createLinearGradientImpl(context, x0, y0, x1, y1));
|
toni@1112
|
422 |
}
|
toni@1112
|
423 |
|
toni@1112
|
424 |
@JavaScriptBody(args = {"context", "x0", "y0", "x1", "y1"}, body = "return context.createLinearGradient(x0,y0,x1,y1);")
|
toni@1112
|
425 |
private native Object createLinearGradientImpl(Object context, double x0, double y0, double x1, double y1);
|
toni@1112
|
426 |
|
toni@1135
|
427 |
public PatternWrapper createPatternWrapper(ImageData image, String repeat) {
|
toni@1134
|
428 |
return new PatternWrapper(createPatternImpl(context, image, repeat));
|
toni@1112
|
429 |
}
|
toni@1112
|
430 |
|
toni@1112
|
431 |
@JavaScriptBody(args = {"context", "image", "repeat"}, body = "return context.createPattern(image, repeat);")
|
toni@1135
|
432 |
private static native Object createPatternImpl(Object context, ImageData image, String repeat);
|
toni@1112
|
433 |
|
toni@1134
|
434 |
public RadialGradientWrapper createRadialGradientWrapper(double x0, double y0, double r0, double x1, double y1, double r1) {
|
toni@1134
|
435 |
return new RadialGradientWrapper(createRadialGradientImpl(context, x0, y0, r0, x1, y1, r1));
|
toni@1112
|
436 |
}
|
toni@1112
|
437 |
|
toni@1112
|
438 |
@JavaScriptBody(args = {"context", "x0", "y0", "r0", "x1", "y1", "r1"}, body = "return context.createRadialGradient(x0,y0,r0,x1,y1,r1);")
|
toni@1112
|
439 |
private static native Object createRadialGradientImpl(Object context, double x0, double y0, double r0, double x1, double y1, double r1);
|
toni@1121
|
440 |
|
toni@1135
|
441 |
//
|
toni@1135
|
442 |
// @JavaScriptBody(args = {"path"}, body = "var b = new Image(); b.src=path; return b;")
|
toni@1135
|
443 |
// public native Image getImageForPath(String path);
|
toni@1134
|
444 |
|
toni@1134
|
445 |
|
toni@1134
|
446 |
|
toni@1121
|
447 |
@Override
|
toni@1134
|
448 |
public int getHeight() {
|
toni@1134
|
449 |
return canvas.getHeight();
|
toni@1121
|
450 |
}
|
toni@1134
|
451 |
|
toni@1134
|
452 |
@Override
|
toni@1134
|
453 |
public int getWidth() {
|
toni@1134
|
454 |
return canvas.getWidth();
|
toni@1134
|
455 |
}
|
toni@1134
|
456 |
|
toni@1134
|
457 |
@Override
|
toni@1134
|
458 |
public void setHeight(int height) {
|
toni@1134
|
459 |
canvas.setHeight(height);
|
toni@1134
|
460 |
}
|
toni@1134
|
461 |
|
toni@1134
|
462 |
@Override
|
toni@1134
|
463 |
public void setWidth(int width) {
|
toni@1134
|
464 |
canvas.setWidth(width);
|
toni@1134
|
465 |
}
|
toni@1134
|
466 |
|
toni@521
|
467 |
}
|