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