15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.canvas;
27
28 import javafx.beans.property.DoubleProperty;
29 import javafx.beans.property.DoublePropertyBase;
30 import javafx.geometry.NodeOrientation;
31 import javafx.scene.Node;
32 import com.sun.javafx.geom.BaseBounds;
33 import com.sun.javafx.geom.RectBounds;
34 import com.sun.javafx.geom.transform.BaseTransform;
35 import com.sun.javafx.jmx.MXNodeAlgorithm;
36 import com.sun.javafx.jmx.MXNodeAlgorithmContext;
37 import com.sun.javafx.scene.DirtyBits;
38 import com.sun.javafx.scene.NodeHelper;
39 import com.sun.javafx.scene.canvas.CanvasHelper;
40 import com.sun.javafx.sg.prism.GrowableDataBuffer;
41 import com.sun.javafx.sg.prism.NGCanvas;
42 import com.sun.javafx.sg.prism.NGNode;
43
44 /**
45 * {@code Canvas} is an image that can be drawn on using a set of graphics
46 * commands provided by a {@link GraphicsContext}.
47 *
48 * <p>
49 * A {@code Canvas} node is constructed with a width and height that specifies the size
50 * of the image into which the canvas drawing commands are rendered. All drawing
51 * operations are clipped to the bounds of that image.
52 * </p>
53 *
54 * <p>Example:</p>
55 *
56 * <pre>
79 @Override
80 public NGNode doCreatePeer(Node node) {
81 return ((Canvas) node).doCreatePeer();
82 }
83
84 @Override
85 public void doUpdatePeer(Node node) {
86 ((Canvas) node).doUpdatePeer();
87 }
88
89 @Override
90 public BaseBounds doComputeGeomBounds(Node node,
91 BaseBounds bounds, BaseTransform tx) {
92 return ((Canvas) node).doComputeGeomBounds(bounds, tx);
93 }
94
95 @Override
96 public boolean doComputeContains(Node node, double localX, double localY) {
97 return ((Canvas) node).doComputeContains(localX, localY);
98 }
99
100 @Override
101 public Object doProcessMXNode(Node node, MXNodeAlgorithm alg, MXNodeAlgorithmContext ctx) {
102 return ((Canvas) node).doProcessMXNode(alg, ctx);
103 }
104 });
105 }
106 static final int DEFAULT_VAL_BUF_SIZE = 1024;
107 static final int DEFAULT_OBJ_BUF_SIZE = 32;
108 private static final int SIZE_HISTORY = 5;
109
110 private GrowableDataBuffer current;
111 private boolean rendererBehind;
112 private int recentvalsizes[];
113 private int recentobjsizes[];
114 private int lastsizeindex;
115
116 private GraphicsContext theContext;
117
118 {
119 // To initialize the class helper at the begining each constructor of this class
120 CanvasHelper.initHelper(this);
121 }
122
123 /**
287 }
288
289 /*
290 * Note: This method MUST only be called via its accessor method.
291 */
292 private boolean doComputeContains(double localX, double localY) {
293 double w = getWidth();
294 double h = getHeight();
295 return (w > 0 && h > 0 &&
296 localX >= 0 && localY >= 0 &&
297 localX < w && localY < h);
298 }
299
300 /*
301 * Note: This method MUST only be called via its accessor method.
302 */
303 private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) {
304 bounds = new RectBounds(0f, 0f, (float) getWidth(), (float) getHeight());
305 bounds = tx.transform(bounds, bounds);
306 return bounds;
307 }
308
309 /*
310 * Note: This method MUST only be called via its accessor method.
311 */
312 private Object doProcessMXNode(MXNodeAlgorithm alg,
313 MXNodeAlgorithmContext ctx) {
314 return alg.processLeafNode(this, ctx);
315 }
316 }
|
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package javafx.scene.canvas;
27
28 import javafx.beans.property.DoubleProperty;
29 import javafx.beans.property.DoublePropertyBase;
30 import javafx.geometry.NodeOrientation;
31 import javafx.scene.Node;
32 import com.sun.javafx.geom.BaseBounds;
33 import com.sun.javafx.geom.RectBounds;
34 import com.sun.javafx.geom.transform.BaseTransform;
35 import com.sun.javafx.scene.DirtyBits;
36 import com.sun.javafx.scene.NodeHelper;
37 import com.sun.javafx.scene.canvas.CanvasHelper;
38 import com.sun.javafx.sg.prism.GrowableDataBuffer;
39 import com.sun.javafx.sg.prism.NGCanvas;
40 import com.sun.javafx.sg.prism.NGNode;
41
42 /**
43 * {@code Canvas} is an image that can be drawn on using a set of graphics
44 * commands provided by a {@link GraphicsContext}.
45 *
46 * <p>
47 * A {@code Canvas} node is constructed with a width and height that specifies the size
48 * of the image into which the canvas drawing commands are rendered. All drawing
49 * operations are clipped to the bounds of that image.
50 * </p>
51 *
52 * <p>Example:</p>
53 *
54 * <pre>
77 @Override
78 public NGNode doCreatePeer(Node node) {
79 return ((Canvas) node).doCreatePeer();
80 }
81
82 @Override
83 public void doUpdatePeer(Node node) {
84 ((Canvas) node).doUpdatePeer();
85 }
86
87 @Override
88 public BaseBounds doComputeGeomBounds(Node node,
89 BaseBounds bounds, BaseTransform tx) {
90 return ((Canvas) node).doComputeGeomBounds(bounds, tx);
91 }
92
93 @Override
94 public boolean doComputeContains(Node node, double localX, double localY) {
95 return ((Canvas) node).doComputeContains(localX, localY);
96 }
97 });
98 }
99 static final int DEFAULT_VAL_BUF_SIZE = 1024;
100 static final int DEFAULT_OBJ_BUF_SIZE = 32;
101 private static final int SIZE_HISTORY = 5;
102
103 private GrowableDataBuffer current;
104 private boolean rendererBehind;
105 private int recentvalsizes[];
106 private int recentobjsizes[];
107 private int lastsizeindex;
108
109 private GraphicsContext theContext;
110
111 {
112 // To initialize the class helper at the begining each constructor of this class
113 CanvasHelper.initHelper(this);
114 }
115
116 /**
280 }
281
282 /*
283 * Note: This method MUST only be called via its accessor method.
284 */
285 private boolean doComputeContains(double localX, double localY) {
286 double w = getWidth();
287 double h = getHeight();
288 return (w > 0 && h > 0 &&
289 localX >= 0 && localY >= 0 &&
290 localX < w && localY < h);
291 }
292
293 /*
294 * Note: This method MUST only be called via its accessor method.
295 */
296 private BaseBounds doComputeGeomBounds(BaseBounds bounds, BaseTransform tx) {
297 bounds = new RectBounds(0f, 0f, (float) getWidth(), (float) getHeight());
298 bounds = tx.transform(bounds, bounds);
299 return bounds;
300 }
301 }
|