1 /**********************************************
2 * Copyright (C) 2010 Lukas Laag
3 * This file is part of lib-gwt-svg-edu.
4 *
5 * libgwtsvg-edu 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, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * libgwtsvg-edu is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with libgwtsvg-edu. If not, see http://www.gnu.org/licenses/
17 **********************************************/
18 package org.vectomatic.svg.edu.client.maze;
19
20 import com.google.gwt.core.client.JavaScriptObject;
21
22 /**
23 * A Canvas wrapper
24 * @author Lukas Laag (laaglu@gmail.com)
25 */
26 public class Canvas {
27 @SuppressWarnings("unused")
28 private JavaScriptObject context;
29 @SuppressWarnings("unused")
30 private JavaScriptObject element;
31
32 private Canvas() {
33 }
34
35 public static Canvas createCanvas(int width, int height) {
36 Canvas canvas = new Canvas();
37 canvas.element = createCanvas_(width, height);
38 canvas.context = canvas.getContext();
39 return canvas;
40 }
41
42 private final native JavaScriptObject getContext() /*-{
43 return this.@org.vectomatic.svg.edu.client.maze.Canvas::element.getContext("2d");
44 }-*/;
45
46 private static final native JavaScriptObject createCanvas_(int width, int height) /*-{
47 var elt = $doc.createElement("canvas");
48 elt.width = width;
49 elt.height = height;
50 return elt;
51 }-*/;
52
53 public final native int getWidth() /*-{
54 return this.width;
55 }-*/;
56
57 public final native void setWidth(int width) /*-{
58 return this.width = width;
59 }-*/;
60
61 public final native int getHeight() /*-{
62 return this.height;
63 }-*/;
64
65 public final native void setHeight(int height) /*-{
66 return this.height = height;
67 }-*/;
68
69 public final native void beginPath() /*-{
70 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.beginPath();
71 }-*/;
72
73 public final native void closePath() /*-{
74 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.closePath();
75 }-*/;
76
77 public final native void moveTo(float x, float y) /*-{
78 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.moveTo(x,y);
79 }-*/;
80
81 public final native void lineTo(float x, float y) /*-{
82 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.lineTo(x,y);
83 }-*/;
84
85 public final native void quadraticCurveTo(float cpx, float cpy, float x, float y) /*-{
86 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.quadraticCurveTo(cpx, cpy, x, y);
87 }-*/;
88
89 public final native void bezierCurveTo(float cp1x, float cp1y, float cp2x,
90 float cp2y, float x, float y) /*-{
91 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.bezierCurveTo(
92 cp1x, cp1y, cp2x, cp2y, x, y);
93 }-*/;
94
95 public final native void arcTo(float x1, float y1, float x2, float y2,
96 float radius) /*-{
97 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.arcTo(x1, y1, x2, y2, radius);
98 }-*/;
99
100 public final native void rect(float x, float y, float w, float h) /*-{
101 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.rect(x, y, w, h);
102 }-*/;
103
104 public final native void clearRect(float x, float y, float w, float h) /*-{
105 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.clearRect(x, y, w, h);
106 }-*/;
107
108 public final native void arc(float x, float y, float radius, float startAngle,
109 float endAngle, boolean anticlockwise) /*-{
110 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.arc(
111 x, y, radius, startAngle, endAngle, anticlockwise);
112 }-*/;
113
114 public final native boolean isPointInPath(float x, float y) /*-{
115 return this.@org.vectomatic.svg.edu.client.maze.Canvas::context.isPointInPath(x, y);
116 }-*/;
117
118 public final native void fill() /*-{
119 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.fill();
120 }-*/;
121
122 public native void scale(float x, float y) /*-{
123 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.scale(x, y);
124 }-*/;
125
126 public native void rotate(float angle)/*-{
127 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.rotate(angle);
128 }-*/;
129
130 public native void translate(float x, float y) /*-{
131 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.translate(x, y);
132 }-*/;
133
134 public native void transform(float m11, float m12, float m21, float m22,
135 float dx, float dy) /*-{
136 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.transform(
137 m11, m12, m21, m22, dx, dy);
138 }-*/;
139
140 public native void setTransform(float m11, float m12, float m21, float m22,
141 float dx, float dy) /*-{
142 this.@org.vectomatic.svg.edu.client.maze.Canvas::context.setTransform(
143 m11, m12, m21, m22, dx, dy);
144 }-*/;
145
146 }