Show
Ignore:
Timestamp:
05/17/08 11:34:28 (8 months ago)
Author:
Frank Benoit <benoit@tionex.de>
branch:
default
Message:

Update to SWT 3.4M7

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • dwt/graphics/Path.d

    r212 r213  
    5050 */ 
    5151public class Path : Resource { 
     52 
     53    alias Resource.init_ init_; 
    5254 
    5355    /** 
     
    8890 */ 
    8991public this (Device device) { 
    90     if (device is null) device = Device.getDevice(); 
    91     if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
    92     this.device = device; 
    93     device.checkGDIP(); 
     92    super(device); 
     93    this.device.checkGDIP(); 
    9494    handle = Gdip.GraphicsPath_new(Gdip.FillModeAlternate); 
    9595    if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); 
    96     if (device.tracking) device.new_Object(this); 
     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 */ 
     130public 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 */ 
     166public this (Device device, PathData data) { 
     167    this(device); 
     168    if (data is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); 
     169    init_(data); 
    97170} 
    98171 
     
    322395} 
    323396 
    324 /** 
    325  * Disposes of the operating system resources associated with 
    326  * the Path. Applications must dispose of all Paths that 
    327  * they allocate. 
    328  */ 
    329 override public void dispose() { 
    330     if (handle is null) return; 
    331     if (device.isDisposed()) return; 
     397void destroy() { 
    332398    Gdip.GraphicsPath_delete(handle); 
    333399    handle = null; 
    334     if (device.tracking) device.dispose_Object(this); 
    335     device = null; 
    336400} 
    337401 
     
    401465    byte[] gdipTypes = new byte[count]; 
    402466    float[] points = new float[count * 2]; 
    403     Gdip.GraphicsPath_GetPathTypes(handle, gdipTypes, count); 
    404     Gdip.GraphicsPath_GetPathPoints(handle, cast(Gdip.PointF[])points, count); 
     467    Gdip.GraphicsPath_GetPathTypes(handle, gdipTypes.ptr, count); 
     468    Gdip.GraphicsPath_GetPathPoints(handle, cast(Gdip.PointF*)points.ptr, count); 
    405469    byte[] types = new byte[count * 2]; 
    406470    int index = 0, typesIndex = 0; 
     
    459523} 
    460524 
     525void 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 
    461552/** 
    462553 * Returns <code>true</code> if the Path has been disposed,