Mercurial > projects > dwt2
comparison org.eclipse.swt.win32.win32.x86/src/org/eclipse/swt/graphics/Path.d @ 0:6dd524f61e62
add dwt win and basic java stuff
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 02 Mar 2009 14:44:16 +0100 |
parents | |
children | 6bf2837c50fe |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:6dd524f61e62 |
---|---|
1 /******************************************************************************* | |
2 * Copyright (c) 2000, 2008 IBM Corporation and others. | |
3 * All rights reserved. This program and the accompanying materials | |
4 * are made available under the terms of the Eclipse Public License v1.0 | |
5 * which accompanies this distribution, and is available at | |
6 * http://www.eclipse.org/legal/epl-v10.html | |
7 * | |
8 * Contributors: | |
9 * IBM Corporation - initial API and implementation | |
10 * Port to the D programming language: | |
11 * Frank Benoit <benoit@tionex.de> | |
12 *******************************************************************************/ | |
13 module org.eclipse.swt.graphics.Path; | |
14 | |
15 import org.eclipse.swt.internal.gdip.Gdip; | |
16 | |
17 import org.eclipse.swt.SWT; | |
18 import org.eclipse.swt.SWTError; | |
19 import org.eclipse.swt.SWTException; | |
20 import org.eclipse.swt.internal.gdip.Gdip; | |
21 import org.eclipse.swt.internal.win32.OS; | |
22 | |
23 import org.eclipse.swt.graphics.Resource; | |
24 import org.eclipse.swt.graphics.Device; | |
25 import org.eclipse.swt.graphics.Font; | |
26 import org.eclipse.swt.graphics.GC; | |
27 import org.eclipse.swt.graphics.GCData; | |
28 import org.eclipse.swt.graphics.PathData; | |
29 | |
30 import java.lang.System; | |
31 import tango.text.convert.Format; | |
32 import java.lang.all; | |
33 | |
34 /** | |
35 * Instances of this class represent paths through the two-dimensional | |
36 * coordinate system. Paths do not have to be continuous, and can be | |
37 * described using lines, rectangles, arcs, cubic or quadratic bezier curves, | |
38 * glyphs, or other paths. | |
39 * <p> | |
40 * Application code must explicitly invoke the <code>Path.dispose()</code> | |
41 * method to release the operating system resources managed by each instance | |
42 * when those instances are no longer required. | |
43 * </p> | |
44 * <p> | |
45 * This class requires the operating system's advanced graphics subsystem | |
46 * which may not be available on some platforms. | |
47 * </p> | |
48 * | |
49 * @see <a href="http://www.eclipse.org/swt/snippets/#path">Path, Pattern snippets</a> | |
50 * @see <a href="http://www.eclipse.org/swt/examples.php">SWT Example: GraphicsExample</a> | |
51 * @see <a href="http://www.eclipse.org/swt/">Sample code and further information</a> | |
52 * | |
53 * @since 3.1 | |
54 */ | |
55 public class Path : Resource { | |
56 | |
57 alias Resource.init_ init_; | |
58 | |
59 /** | |
60 * the OS resource for the Path | |
61 * (Warning: This field is platform dependent) | |
62 * <p> | |
63 * <b>IMPORTANT:</b> This field is <em>not</em> part of the SWT | |
64 * public API. It is marked public only so that it can be shared | |
65 * within the packages provided by SWT. It is not available on all | |
66 * platforms and should never be accessed from application code. | |
67 * </p> | |
68 */ | |
69 public Gdip.Path handle; | |
70 | |
71 Gdip.PointF currentPoint, startPoint; | |
72 | |
73 /** | |
74 * Constructs a new empty Path. | |
75 * <p> | |
76 * This operation requires the operating system's advanced | |
77 * graphics subsystem which may not be available on some | |
78 * platforms. | |
79 * </p> | |
80 * | |
81 * @param device the device on which to allocate the path | |
82 * | |
83 * @exception IllegalArgumentException <ul> | |
84 * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li> | |
85 * </ul> | |
86 * @exception SWTException <ul> | |
87 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
88 * </ul> | |
89 * @exception SWTError <ul> | |
90 * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li> | |
91 * </ul> | |
92 * | |
93 * @see #dispose() | |
94 */ | |
95 public this (Device device) { | |
96 super(device); | |
97 this.device.checkGDIP(); | |
98 handle = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); | |
99 if (handle is null) SWT.error(SWT.ERROR_NO_HANDLES); | |
100 init_(); | |
101 } | |
102 | |
103 /** | |
104 * Constructs a new Path that is a copy of <code>path</code>. If | |
105 * <code>flatness</code> is less than or equal to zero, an unflatten | |
106 * copy of the path is created. Otherwise, it specifies the maximum | |
107 * error between the path and its flatten copy. Smaller numbers give | |
108 * better approximation. | |
109 * <p> | |
110 * This operation requires the operating system's advanced | |
111 * graphics subsystem which may not be available on some | |
112 * platforms. | |
113 * </p> | |
114 * | |
115 * @param device the device on which to allocate the path | |
116 * @param path the path to make a copy | |
117 * @param flatness the flatness value | |
118 * | |
119 * @exception IllegalArgumentException <ul> | |
120 * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li> | |
121 * <li>ERROR_NULL_ARGUMENT - if the path is null</li> | |
122 * <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li> | |
123 * </ul> | |
124 * @exception SWTException <ul> | |
125 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
126 * </ul> | |
127 * @exception SWTError <ul> | |
128 * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li> | |
129 * </ul> | |
130 * | |
131 * @see #dispose() | |
132 * @since 3.4 | |
133 */ | |
134 public this (Device device, Path path, float flatness) { | |
135 super(device); | |
136 if (path is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
137 if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
138 flatness = Math.max(0, flatness); | |
139 handle = Gdip.GraphicsPath_Clone(path.handle); | |
140 if (flatness !is 0) Gdip.GraphicsPath_Flatten(handle, null, flatness); | |
141 if (handle is null) SWT.error(SWT.ERROR_NO_HANDLES); | |
142 init_(); | |
143 } | |
144 | |
145 /** | |
146 * Constructs a new Path with the specifed PathData. | |
147 * <p> | |
148 * This operation requires the operating system's advanced | |
149 * graphics subsystem which may not be available on some | |
150 * platforms. | |
151 * </p> | |
152 * | |
153 * @param device the device on which to allocate the path | |
154 * @param data the data for the path | |
155 * | |
156 * @exception IllegalArgumentException <ul> | |
157 * <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li> | |
158 * <li>ERROR_NULL_ARGUMENT - if the data is null</li> | |
159 * </ul> | |
160 * @exception SWTException <ul> | |
161 * <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li> | |
162 * </ul> | |
163 * @exception SWTError <ul> | |
164 * <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li> | |
165 * </ul> | |
166 * | |
167 * @see #dispose() | |
168 * @since 3.4 | |
169 */ | |
170 public this (Device device, PathData data) { | |
171 this(device); | |
172 if (data is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
173 init_(data); | |
174 } | |
175 | |
176 /** | |
177 * Adds to the receiver a circular or elliptical arc that lies within | |
178 * the specified rectangular area. | |
179 * <p> | |
180 * The resulting arc begins at <code>startAngle</code> and extends | |
181 * for <code>arcAngle</code> degrees. | |
182 * Angles are interpreted such that 0 degrees is at the 3 o'clock | |
183 * position. A positive value indicates a counter-clockwise rotation | |
184 * while a negative value indicates a clockwise rotation. | |
185 * </p><p> | |
186 * The center of the arc is the center of the rectangle whose origin | |
187 * is (<code>x</code>, <code>y</code>) and whose size is specified by the | |
188 * <code>width</code> and <code>height</code> arguments. | |
189 * </p><p> | |
190 * The resulting arc covers an area <code>width + 1</code> pixels wide | |
191 * by <code>height + 1</code> pixels tall. | |
192 * </p> | |
193 * | |
194 * @param x the x coordinate of the upper-left corner of the arc | |
195 * @param y the y coordinate of the upper-left corner of the arc | |
196 * @param width the width of the arc | |
197 * @param height the height of the arc | |
198 * @param startAngle the beginning angle | |
199 * @param arcAngle the angular extent of the arc, relative to the start angle | |
200 * | |
201 * @exception SWTException <ul> | |
202 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
203 * </ul> | |
204 */ | |
205 public void addArc(float x, float y, float width, float height, float startAngle, float arcAngle) { | |
206 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
207 if (width < 0) { | |
208 x = x + width; | |
209 width = -width; | |
210 } | |
211 if (height < 0) { | |
212 y = y + height; | |
213 height = -height; | |
214 } | |
215 if (width is 0 || height is 0 || arcAngle is 0) return; | |
216 if (width is height) { | |
217 Gdip.GraphicsPath_AddArcF(handle, x, y, width, height, -startAngle, -arcAngle); | |
218 } else { | |
219 auto path = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); | |
220 if (path is null) SWT.error(SWT.ERROR_NO_HANDLES); | |
221 auto matrix = Gdip.Matrix_new(width, 0, 0, height, x, y); | |
222 if (matrix is null) SWT.error(SWT.ERROR_NO_HANDLES); | |
223 Gdip.GraphicsPath_AddArc(path, 0, 0, 1, 1, -startAngle, -arcAngle); | |
224 Gdip.GraphicsPath_Transform(path, matrix); | |
225 Gdip.GraphicsPath_AddPath(handle, path, true); | |
226 Gdip.Matrix_delete(matrix); | |
227 Gdip.GraphicsPath_delete(path); | |
228 } | |
229 Gdip.GraphicsPath_GetLastPoint(handle, currentPoint); | |
230 } | |
231 | |
232 /** | |
233 * Adds to the receiver the path described by the parameter. | |
234 * | |
235 * @param path the path to add to the receiver | |
236 * | |
237 * @exception IllegalArgumentException <ul> | |
238 * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> | |
239 * <li>ERROR_INVALID_ARGUMENT - if the parameter has been disposed</li> | |
240 * </ul> | |
241 * @exception SWTException <ul> | |
242 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
243 * </ul> | |
244 */ | |
245 public void addPath(Path path) { | |
246 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
247 if (path is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
248 if (path.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
249 //TODO - expose connect? | |
250 Gdip.GraphicsPath_AddPath(handle, path.handle, false); | |
251 currentPoint.X = path.currentPoint.X; | |
252 currentPoint.Y = path.currentPoint.Y; | |
253 } | |
254 | |
255 /** | |
256 * Adds to the receiver the rectangle specified by x, y, width and height. | |
257 * | |
258 * @param x the x coordinate of the rectangle to add | |
259 * @param y the y coordinate of the rectangle to add | |
260 * @param width the width of the rectangle to add | |
261 * @param height the height of the rectangle to add | |
262 * | |
263 * @exception SWTException <ul> | |
264 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
265 * </ul> | |
266 */ | |
267 public void addRectangle(float x, float y, float width, float height) { | |
268 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
269 Gdip.RectF rect; | |
270 rect.X = x; | |
271 rect.Y = y; | |
272 rect.Width = width; | |
273 rect.Height = height; | |
274 Gdip.GraphicsPath_AddRectangle(handle, rect); | |
275 currentPoint.X = x; | |
276 currentPoint.Y = y; | |
277 } | |
278 | |
279 /** | |
280 * Adds to the receiver the pattern of glyphs generated by drawing | |
281 * the given string using the given font starting at the point (x, y). | |
282 * | |
283 * @param string the text to use | |
284 * @param x the x coordinate of the starting point | |
285 * @param y the y coordinate of the starting point | |
286 * @param font the font to use | |
287 * | |
288 * @exception IllegalArgumentException <ul> | |
289 * <li>ERROR_NULL_ARGUMENT - if the font is null</li> | |
290 * <li>ERROR_INVALID_ARGUMENT - if the font has been disposed</li> | |
291 * </ul> | |
292 * @exception SWTException <ul> | |
293 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
294 * </ul> | |
295 */ | |
296 public void addString(String string, float x, float y, Font font) { | |
297 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
298 if (font is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
299 if (font.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
300 wchar[] wstr = StrToWCHARs( string ); | |
301 wchar* buffer = wstr.ptr; | |
302 int length = wstr.length; | |
303 auto hDC = device.internal_new_GC(null); | |
304 auto gdipFont = GC.createGdipFont(hDC, font.handle); | |
305 Gdip.PointF point; | |
306 point.X = x - (Gdip.Font_GetSize(gdipFont) / 6); | |
307 point.Y = y; | |
308 auto family = Gdip.FontFamily_new(); | |
309 Gdip.Font_GetFamily(gdipFont, family); | |
310 int style = Gdip.Font_GetStyle(gdipFont); | |
311 float size = Gdip.Font_GetSize(gdipFont); | |
312 Gdip.GraphicsPath_AddString(handle, buffer, length, family, style, size, point, null); | |
313 Gdip.GraphicsPath_GetLastPoint(handle, currentPoint); | |
314 Gdip.FontFamily_delete(family); | |
315 Gdip.Font_delete(gdipFont); | |
316 device.internal_dispose_GC(hDC, null); | |
317 } | |
318 | |
319 /** | |
320 * Closes the current sub path by adding to the receiver a line | |
321 * from the current point of the path back to the starting point | |
322 * of the sub path. | |
323 * | |
324 * @exception SWTException <ul> | |
325 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
326 * </ul> | |
327 */ | |
328 public void close() { | |
329 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
330 Gdip.GraphicsPath_CloseFigure(handle); | |
331 /* | |
332 * Feature in GDI+. CloseFigure() does affect the last | |
333 * point, so GetLastPoint() does not return the starting | |
334 * point of the subpath after calling CloseFigure(). The | |
335 * fix is to remember the subpath starting point and use | |
336 * it instead. | |
337 */ | |
338 currentPoint.X = startPoint.X; | |
339 currentPoint.Y = startPoint.Y; | |
340 } | |
341 | |
342 /** | |
343 * Returns <code>true</code> if the specified point is contained by | |
344 * the receiver and false otherwise. | |
345 * <p> | |
346 * If outline is <code>true</code>, the point (x, y) checked for containment in | |
347 * the receiver's outline. If outline is <code>false</code>, the point is | |
348 * checked to see if it is contained within the bounds of the (closed) area | |
349 * covered by the receiver. | |
350 * | |
351 * @param x the x coordinate of the point to test for containment | |
352 * @param y the y coordinate of the point to test for containment | |
353 * @param gc the GC to use when testing for containment | |
354 * @param outline controls whether to check the outline or contained area of the path | |
355 * @return <code>true</code> if the path contains the point and <code>false</code> otherwise | |
356 * | |
357 * @exception IllegalArgumentException <ul> | |
358 * <li>ERROR_NULL_ARGUMENT - if the gc is null</li> | |
359 * <li>ERROR_INVALID_ARGUMENT - if the gc has been disposed</li> | |
360 * </ul> | |
361 * @exception SWTException <ul> | |
362 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
363 * </ul> | |
364 */ | |
365 public bool contains(float x, float y, GC gc, bool outline) { | |
366 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
367 if (gc is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
368 if (gc.isDisposed()) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
369 //TODO - should use GC transformation | |
370 gc.initGdip(); | |
371 gc.checkGC(GC.LINE_CAP | GC.LINE_JOIN | GC.LINE_STYLE | GC.LINE_WIDTH); | |
372 int mode = OS.GetPolyFillMode(gc.handle) is OS.WINDING ? Gdip.FillModeWinding : Gdip.FillModeAlternate; | |
373 Gdip.GraphicsPath_SetFillMode(handle, mode); | |
374 if (outline) { | |
375 return Gdip.GraphicsPath_IsOutlineVisible(handle, x, y, gc.data.gdipPen, gc.data.gdipGraphics); | |
376 } else { | |
377 return Gdip.GraphicsPath_IsVisible(handle, x, y, gc.data.gdipGraphics); | |
378 } | |
379 } | |
380 | |
381 /** | |
382 * Adds to the receiver a cubic bezier curve based on the parameters. | |
383 * | |
384 * @param cx1 the x coordinate of the first control point of the spline | |
385 * @param cy1 the y coordinate of the first control of the spline | |
386 * @param cx2 the x coordinate of the second control of the spline | |
387 * @param cy2 the y coordinate of the second control of the spline | |
388 * @param x the x coordinate of the end point of the spline | |
389 * @param y the y coordinate of the end point of the spline | |
390 * | |
391 * @exception SWTException <ul> | |
392 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
393 * </ul> | |
394 */ | |
395 public void cubicTo(float cx1, float cy1, float cx2, float cy2, float x, float y) { | |
396 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
397 Gdip.GraphicsPath_AddBezier(handle, currentPoint.X, currentPoint.Y, cx1, cy1, cx2, cy2, x, y); | |
398 Gdip.GraphicsPath_GetLastPoint(handle, currentPoint); | |
399 } | |
400 | |
401 void destroy() { | |
402 Gdip.GraphicsPath_delete(handle); | |
403 handle = null; | |
404 } | |
405 | |
406 /** | |
407 * Replaces the first four elements in the parameter with values that | |
408 * describe the smallest rectangle that will completely contain the | |
409 * receiver (i.e. the bounding box). | |
410 * | |
411 * @param bounds the array to hold the result | |
412 * | |
413 * @exception IllegalArgumentException <ul> | |
414 * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> | |
415 * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the bounding box</li> | |
416 * </ul> | |
417 * @exception SWTException <ul> | |
418 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
419 * </ul> | |
420 */ | |
421 public void getBounds(float[] bounds) { | |
422 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
423 if (bounds is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
424 if (bounds.length < 4) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
425 Gdip.RectF rect; | |
426 Gdip.GraphicsPath_GetBounds(handle, rect, null, null); | |
427 bounds[0] = rect.X; | |
428 bounds[1] = rect.Y; | |
429 bounds[2] = rect.Width; | |
430 bounds[3] = rect.Height; | |
431 } | |
432 | |
433 /** | |
434 * Replaces the first two elements in the parameter with values that | |
435 * describe the current point of the path. | |
436 * | |
437 * @param point the array to hold the result | |
438 * | |
439 * @exception IllegalArgumentException <ul> | |
440 * <li>ERROR_NULL_ARGUMENT - if the parameter is null</li> | |
441 * <li>ERROR_INVALID_ARGUMENT - if the parameter is too small to hold the end point</li> | |
442 * </ul> | |
443 * @exception SWTException <ul> | |
444 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
445 * </ul> | |
446 */ | |
447 public void getCurrentPoint(float[] point) { | |
448 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
449 if (point is null) SWT.error(SWT.ERROR_NULL_ARGUMENT); | |
450 if (point.length < 2) SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
451 point[0] = currentPoint.X; | |
452 point[1] = currentPoint.Y; | |
453 } | |
454 | |
455 /** | |
456 * Returns a device independent representation of the receiver. | |
457 * | |
458 * @return the PathData for the receiver | |
459 * | |
460 * @exception SWTException <ul> | |
461 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
462 * </ul> | |
463 * | |
464 * @see PathData | |
465 */ | |
466 public PathData getPathData() { | |
467 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
468 int count = Gdip.GraphicsPath_GetPointCount(handle); | |
469 byte[] gdipTypes = new byte[count]; | |
470 float[] points = new float[count * 2]; | |
471 Gdip.GraphicsPath_GetPathTypes(handle, gdipTypes.ptr, count); | |
472 Gdip.GraphicsPath_GetPathPoints(handle, cast(Gdip.PointF*)points.ptr, count); | |
473 byte[] types = new byte[count * 2]; | |
474 int index = 0, typesIndex = 0; | |
475 while (index < count) { | |
476 byte type = gdipTypes[index]; | |
477 bool close = false; | |
478 switch (type & Gdip.PathPointTypePathTypeMask) { | |
479 case Gdip.PathPointTypeStart: | |
480 types[typesIndex++] = SWT.PATH_MOVE_TO; | |
481 close = (type & Gdip.PathPointTypeCloseSubpath) !is 0; | |
482 index += 1; | |
483 break; | |
484 case Gdip.PathPointTypeLine: | |
485 types[typesIndex++] = SWT.PATH_LINE_TO; | |
486 close = (type & Gdip.PathPointTypeCloseSubpath) !is 0; | |
487 index += 1; | |
488 break; | |
489 case Gdip.PathPointTypeBezier: | |
490 types[typesIndex++] = SWT.PATH_CUBIC_TO; | |
491 close = (gdipTypes[index + 2] & Gdip.PathPointTypeCloseSubpath) !is 0; | |
492 index += 3; | |
493 break; | |
494 default: | |
495 index++; | |
496 } | |
497 if (close) { | |
498 types[typesIndex++] = SWT.PATH_CLOSE; | |
499 } | |
500 } | |
501 if (typesIndex !is types.length) { | |
502 byte[] newTypes = new byte[typesIndex]; | |
503 System.arraycopy(types, 0, newTypes, 0, typesIndex); | |
504 types = newTypes; | |
505 } | |
506 PathData result = new PathData(); | |
507 result.types = types; | |
508 result.points = points; | |
509 return result; | |
510 } | |
511 | |
512 /** | |
513 * Adds to the receiver a line from the current point to | |
514 * the point specified by (x, y). | |
515 * | |
516 * @param x the x coordinate of the end of the line to add | |
517 * @param y the y coordinate of the end of the line to add | |
518 * | |
519 * @exception SWTException <ul> | |
520 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
521 * </ul> | |
522 */ | |
523 public void lineTo(float x, float y) { | |
524 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
525 Gdip.GraphicsPath_AddLine(handle, currentPoint.X, currentPoint.Y, x, y); | |
526 Gdip.GraphicsPath_GetLastPoint(handle, currentPoint); | |
527 } | |
528 | |
529 void init_(PathData data) { | |
530 byte[] types = data.types; | |
531 float[] points = data.points; | |
532 for (int i = 0, j = 0; i < types.length; i++) { | |
533 switch (types[i]) { | |
534 case SWT.PATH_MOVE_TO: | |
535 moveTo(points[j++], points[j++]); | |
536 break; | |
537 case SWT.PATH_LINE_TO: | |
538 lineTo(points[j++], points[j++]); | |
539 break; | |
540 case SWT.PATH_CUBIC_TO: | |
541 cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]); | |
542 break; | |
543 case SWT.PATH_QUAD_TO: | |
544 quadTo(points[j++], points[j++], points[j++], points[j++]); | |
545 break; | |
546 case SWT.PATH_CLOSE: | |
547 close(); | |
548 break; | |
549 default: | |
550 dispose(); | |
551 SWT.error(SWT.ERROR_INVALID_ARGUMENT); | |
552 } | |
553 } | |
554 } | |
555 | |
556 /** | |
557 * Returns <code>true</code> if the Path has been disposed, | |
558 * and <code>false</code> otherwise. | |
559 * <p> | |
560 * This method gets the dispose state for the Path. | |
561 * When a Path has been disposed, it is an error to | |
562 * invoke any other method using the Path. | |
563 * | |
564 * @return <code>true</code> when the Path is disposed, and <code>false</code> otherwise | |
565 */ | |
566 override public bool isDisposed() { | |
567 return handle is null; | |
568 } | |
569 | |
570 /** | |
571 * Sets the current point of the receiver to the point | |
572 * specified by (x, y). Note that this starts a new | |
573 * sub path. | |
574 * | |
575 * @param x the x coordinate of the new end point | |
576 * @param y the y coordinate of the new end point | |
577 * | |
578 * @exception SWTException <ul> | |
579 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
580 * </ul> | |
581 */ | |
582 public void moveTo(float x, float y) { | |
583 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
584 Gdip.GraphicsPath_StartFigure(handle); | |
585 currentPoint.X = startPoint.X = x; | |
586 currentPoint.Y = startPoint.Y = y; | |
587 } | |
588 | |
589 /** | |
590 * Adds to the receiver a quadratic curve based on the parameters. | |
591 * | |
592 * @param cx the x coordinate of the control point of the spline | |
593 * @param cy the y coordinate of the control point of the spline | |
594 * @param x the x coordinate of the end point of the spline | |
595 * @param y the y coordinate of the end point of the spline | |
596 * | |
597 * @exception SWTException <ul> | |
598 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
599 * </ul> | |
600 */ | |
601 public void quadTo(float cx, float cy, float x, float y) { | |
602 if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED); | |
603 float cx1 = currentPoint.X + 2 * (cx - currentPoint.X) / 3; | |
604 float cy1 = currentPoint.Y + 2 * (cy - currentPoint.Y) / 3; | |
605 float cx2 = cx1 + (x - currentPoint.X) / 3; | |
606 float cy2 = cy1 + (y - currentPoint.Y) / 3; | |
607 Gdip.GraphicsPath_AddBezier(handle, currentPoint.X, currentPoint.Y, cx1, cy1, cx2, cy2, x, y); | |
608 Gdip.GraphicsPath_GetLastPoint(handle, currentPoint); | |
609 } | |
610 | |
611 /** | |
612 * Returns a string containing a concise, human-readable | |
613 * description of the receiver. | |
614 * | |
615 * @return a string representation of the receiver | |
616 */ | |
617 override public String toString() { | |
618 if (isDisposed()) return "Path {*DISPOSED*}"; | |
619 return Format( "Path {{{}}", handle ); | |
620 } | |
621 | |
622 } |