Mercurial > projects > dwt-win
comparison dwt/graphics/Transform.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 |
comparison
equal
deleted
inserted
replaced
212:ab60f3309436 | 213:36f5cb12e1a2 |
---|---|
37 * </p> | 37 * </p> |
38 * | 38 * |
39 * @since 3.1 | 39 * @since 3.1 |
40 */ | 40 */ |
41 public class Transform : Resource { | 41 public class Transform : Resource { |
42 | 42 alias Resource.init_ init_; |
43 /** | 43 /** |
44 * the OS resource for the Transform | 44 * the OS resource for the Transform |
45 * (Warning: This field is platform dependent) | 45 * (Warning: This field is platform dependent) |
46 * <p> | 46 * <p> |
47 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | 47 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT |
135 * </ul> | 135 * </ul> |
136 * | 136 * |
137 * @see #dispose() | 137 * @see #dispose() |
138 */ | 138 */ |
139 public this (Device device, float m11, float m12, float m21, float m22, float dx, float dy) { | 139 public this (Device device, float m11, float m12, float m21, float m22, float dx, float dy) { |
140 if (device is null) device = Device.getDevice(); | 140 super(device); |
141 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 141 this.device.checkGDIP(); |
142 this.device = device; | |
143 device.checkGDIP(); | |
144 handle = Gdip.Matrix_new(m11, m12, m21, m22, dx, dy); | 142 handle = Gdip.Matrix_new(m11, m12, m21, m22, dx, dy); |
145 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | 143 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); |
146 if (device.tracking) device.new_Object(this); | 144 init_(); |
147 } | 145 } |
148 | 146 |
149 static float[] checkTransform(float[] elements) { | 147 static float[] checkTransform(float[] elements) { |
150 if (elements is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 148 if (elements is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
151 if (elements.length < 6) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 149 if (elements.length < 6) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
152 return elements; | 150 return elements; |
153 } | 151 } |
154 | 152 |
155 /** | 153 void destroy() { |
156 * Disposes of the operating system resources associated with | |
157 * the Transform. Applications must dispose of all Transforms that | |
158 * they allocate. | |
159 */ | |
160 override public void dispose() { | |
161 if (handle is null) return; | |
162 if (device.isDisposed()) return; | |
163 Gdip.Matrix_delete(handle); | 154 Gdip.Matrix_delete(handle); |
164 handle = null; | 155 handle = null; |
165 if (device.tracking) device.dispose_Object(this); | |
166 device = null; | |
167 } | 156 } |
168 | 157 |
169 /** | 158 /** |
170 * Fills the parameter with the values of the transformation matrix | 159 * Fills the parameter with the values of the transformation matrix |
171 * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}. | 160 * that the receiver represents, in the order {m11, m12, m21, m22, dx, dy}. |
182 */ | 171 */ |
183 public void getElements(float[] elements) { | 172 public void getElements(float[] elements) { |
184 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 173 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
185 if (elements is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 174 if (elements is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
186 if (elements.length < 6) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 175 if (elements.length < 6) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
187 Gdip.Matrix_GetElements(handle, elements); | 176 Gdip.Matrix_GetElements(handle, elements.ptr); |
188 } | 177 } |
189 | 178 |
190 /** | 179 /** |
191 * Modifies the receiver such that the matrix it represents becomes the | 180 * Modifies the receiver such that the matrix it represents becomes the |
181 * identity matrix. | |
182 * | |
183 * @exception DWTException <ul> | |
184 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
185 * </ul> | |
186 * | |
187 * @since 3.4 | |
188 */ | |
189 public void identity() { | |
190 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
191 Gdip.Matrix_SetElements(handle, 1, 0, 0, 1, 0, 0); | |
192 } | |
193 | |
194 /** | |
195 * Modifies the receiver such that the matrix it represents becomes | |
192 * the mathematical inverse of the matrix it previously represented. | 196 * the mathematical inverse of the matrix it previously represented. |
193 * | 197 * |
194 * @exception DWTException <ul> | 198 * @exception DWTException <ul> |
195 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | 199 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> |
196 * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li> | 200 * <li>ERROR_CANNOT_INVERT_MATRIX - if the matrix is not invertible</li> |
301 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 305 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
302 Gdip.Matrix_SetElements(handle, m11, m12, m21, m22, dx, dy); | 306 Gdip.Matrix_SetElements(handle, m11, m12, m21, m22, dx, dy); |
303 } | 307 } |
304 | 308 |
305 /** | 309 /** |
310 * Modifies the receiver so that it represents a transformation that is | |
311 * equivalent to its previous transformation sheared by (shearX, shearY). | |
312 * | |
313 * @param shearX the shear factor in the X direction | |
314 * @param shearY the shear factor in the Y direction | |
315 * | |
316 * @exception DWTException <ul> | |
317 * <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed</li> | |
318 * </ul> | |
319 * | |
320 * @since 3.4 | |
321 */ | |
322 public void shear(float shearX, float shearY) { | |
323 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | |
324 Gdip.Matrix_Shear(handle, shearX, shearY, Gdip.MatrixOrderPrepend); | |
325 } | |
326 | |
327 /** | |
306 * Given an array containing points described by alternating x and y values, | 328 * Given an array containing points described by alternating x and y values, |
307 * modify that array such that each point has been replaced with the result of | 329 * modify that array such that each point has been replaced with the result of |
308 * applying the transformation represented by the receiver to that point. | 330 * applying the transformation represented by the receiver to that point. |
309 * | 331 * |
310 * @param pointArray an array of alternating x and y values to be transformed | 332 * @param pointArray an array of alternating x and y values to be transformed |
317 * </ul> | 339 * </ul> |
318 */ | 340 */ |
319 public void transform(float[] pointArray) { | 341 public void transform(float[] pointArray) { |
320 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); | 342 if (isDisposed()) DWT.error(DWT.ERROR_GRAPHIC_DISPOSED); |
321 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 343 if (pointArray is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
322 Gdip.Matrix_TransformPoints(handle, cast(Gdip.PointF[])pointArray, pointArray.length / 2); | 344 Gdip.Matrix_TransformPoints(handle, cast(Gdip.PointF*)pointArray.ptr, pointArray.length / 2); |
323 } | 345 } |
324 | 346 |
325 /** | 347 /** |
326 * Modifies the receiver so that it represents a transformation that is | 348 * Modifies the receiver so that it represents a transformation that is |
327 * equivalent to its previous transformation translated by (offsetX, offsetY). | 349 * equivalent to its previous transformation translated by (offsetX, offsetY). |