diff 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
line wrap: on
line diff
--- a/dwt/graphics/Path.d	Mon May 05 00:12:38 2008 +0200
+++ b/dwt/graphics/Path.d	Sat May 17 17:34:28 2008 +0200
@@ -50,6 +50,8 @@
  */
 public class Path : Resource {
 
+    alias Resource.init_ init_;
+
     /**
      * the OS resource for the Path
      * (Warning: This field is platform dependent)
@@ -87,13 +89,84 @@
  * @see #dispose()
  */
 public this (Device device) {
-    if (device is null) device = Device.getDevice();
-    if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
-    this.device = device;
-    device.checkGDIP();
+    super(device);
+    this.device.checkGDIP();
     handle = Gdip.GraphicsPath_new(Gdip.FillModeAlternate);
     if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
-    if (device.tracking) device.new_Object(this);
+    init_();
+}
+
+/**
+ * Constructs a new Path that is a copy of <code>path</code>. If
+ * <code>flatness</code> is less than or equal to zero, an unflatten
+ * copy of the path is created. Otherwise, it specifies the maximum
+ * error between the path and its flatten copy. Smaller numbers give
+ * better approximation.
+ * <p>
+ * This operation requires the operating system's advanced
+ * graphics subsystem which may not be available on some
+ * platforms.
+ * </p>
+ *
+ * @param device the device on which to allocate the path
+ * @param path the path to make a copy
+ * @param flatness the flatness value
+ *
+ * @exception IllegalArgumentException <ul>
+ *    <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
+ *    <li>ERROR_NULL_ARGUMENT - if the path is null</li>
+ *    <li>ERROR_INVALID_ARGUMENT - if the path has been disposed</li>
+ * </ul>
+ * @exception DWTException <ul>
+ *    <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
+ * </ul>
+ * @exception DWTError <ul>
+ *    <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
+ * </ul>
+ *
+ * @see #dispose()
+ * @since 3.4
+ */
+public this (Device device, Path path, float flatness) {
+    super(device);
+    if (path is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
+    if (path.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+    flatness = Math.max(0, flatness);
+    handle = Gdip.GraphicsPath_Clone(path.handle);
+    if (flatness !is 0) Gdip.GraphicsPath_Flatten(handle, null, flatness);
+    if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES);
+    init_();
+}
+
+/**
+ * Constructs a new with the specifed PathData.
+ * <p>
+ * This operation requires the operating system's advanced
+ * graphics subsystem which may not be available on some
+ * platforms.
+ * </p>
+ *
+ * @param device the device on which to allocate the path
+ * @param data the data for the path
+ *
+ * @exception IllegalArgumentException <ul>
+ *    <li>ERROR_NULL_ARGUMENT - if the device is null and there is no current device</li>
+ *    <li>ERROR_NULL_ARGUMENT - if the data is null</li>
+ * </ul>
+ * @exception DWTException <ul>
+ *    <li>ERROR_NO_GRAPHICS_LIBRARY - if advanced graphics are not available</li>
+ * </ul>
+ * @exception DWTError <ul>
+ *    <li>ERROR_NO_HANDLES if a handle for the path could not be obtained</li>
+ * </ul>
+ *
+ * @see #dispose()
+ * @since 3.4
+ */
+public this (Device device, PathData data) {
+    this(device);
+    if (data is null) DWT.error(DWT.ERROR_NULL_ARGUMENT);
+    init_(data);
 }
 
 /**
@@ -321,18 +394,9 @@
     Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
 }
 
-/**
- * Disposes of the operating system resources associated with
- * the Path. Applications must dispose of all Paths that
- * they allocate.
- */
-override public void dispose() {
-    if (handle is null) return;
-    if (device.isDisposed()) return;
+void destroy() {
     Gdip.GraphicsPath_delete(handle);
     handle = null;
-    if (device.tracking) device.dispose_Object(this);
-    device = null;
 }
 
 /**
@@ -400,8 +464,8 @@
     int count = Gdip.GraphicsPath_GetPointCount(handle);
     byte[] gdipTypes = new byte[count];
     float[] points = new float[count * 2];
-    Gdip.GraphicsPath_GetPathTypes(handle, gdipTypes, count);
-    Gdip.GraphicsPath_GetPathPoints(handle, cast(Gdip.PointF[])points, count);
+    Gdip.GraphicsPath_GetPathTypes(handle, gdipTypes.ptr, count);
+    Gdip.GraphicsPath_GetPathPoints(handle, cast(Gdip.PointF*)points.ptr, count);
     byte[] types = new byte[count * 2];
     int index = 0, typesIndex = 0;
     while (index < count) {
@@ -458,6 +522,33 @@
     Gdip.GraphicsPath_GetLastPoint(handle, currentPoint);
 }
 
+void init_(PathData data) {
+    byte[] types = data.types;
+    float[] points = data.points;
+    for (int i = 0, j = 0; i < types.length; i++) {
+        switch (types[i]) {
+            case DWT.PATH_MOVE_TO:
+                moveTo(points[j++], points[j++]);
+                break;
+            case DWT.PATH_LINE_TO:
+                lineTo(points[j++], points[j++]);
+                break;
+            case DWT.PATH_CUBIC_TO:
+                cubicTo(points[j++], points[j++], points[j++], points[j++], points[j++], points[j++]);
+                break;
+            case DWT.PATH_QUAD_TO:
+                quadTo(points[j++], points[j++], points[j++], points[j++]);
+                break;
+            case DWT.PATH_CLOSE:
+                close();
+                break;
+            default:
+                dispose();
+                DWT.error(DWT.ERROR_INVALID_ARGUMENT);
+        }
+    }
+}
+
 /**
  * Returns <code>true</code> if the Path has been disposed,
  * and <code>false</code> otherwise.