Mercurial > projects > dwt-win
comparison dwt/graphics/Pattern.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 |
---|---|
41 * </p> | 41 * </p> |
42 * | 42 * |
43 * @since 3.1 | 43 * @since 3.1 |
44 */ | 44 */ |
45 public class Pattern : Resource { | 45 public class Pattern : Resource { |
46 | 46 alias Resource.init_ init_; |
47 /** | 47 /** |
48 * the OS resource for the Pattern | 48 * the OS resource for the Pattern |
49 * (Warning: This field is platform dependent) | 49 * (Warning: This field is platform dependent) |
50 * <p> | 50 * <p> |
51 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT | 51 * <b>IMPORTANT:</b> This field is <em>not</em> part of the DWT |
80 * </ul> | 80 * </ul> |
81 * | 81 * |
82 * @see #dispose() | 82 * @see #dispose() |
83 */ | 83 */ |
84 public this(Device device, Image image) { | 84 public this(Device device, Image image) { |
85 if (device is null) device = Device.getDevice(); | 85 super(device); |
86 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
87 if (image is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 86 if (image is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
88 if (image.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 87 if (image.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
89 this.device = device; | 88 this.device.checkGDIP(); |
90 device.checkGDIP(); | 89 int /*long*/[] gdipImage = image.createGdipImage(); |
91 int[] gdipImage = image.createGdipImage(); | 90 auto img = cast(Gdip.Image) gdipImage[0]; |
92 auto img = cast(Gdip.Image)gdipImage[0]; | |
93 int width = Gdip.Image_GetWidth(img); | 91 int width = Gdip.Image_GetWidth(img); |
94 int height = Gdip.Image_GetHeight(img); | 92 int height = Gdip.Image_GetHeight(img); |
95 handle = cast(Gdip.Brush)Gdip.TextureBrush_new(img, Gdip.WrapModeTile, 0, 0, width, height); | 93 handle = cast(Gdip.Brush)Gdip.TextureBrush_new(img, Gdip.WrapModeTile, 0, 0, width, height); |
96 Gdip.Bitmap_delete( cast(Gdip.Bitmap)img); | 94 Gdip.Bitmap_delete( cast(Gdip.Bitmap)img); |
97 if (gdipImage[1] !is 0) { | 95 if (gdipImage[1] !is 0) { |
98 auto hHeap = OS.GetProcessHeap (); | 96 auto hHeap = OS.GetProcessHeap (); |
99 OS.HeapFree(hHeap, 0, cast(void*)gdipImage[1]); | 97 OS.HeapFree(hHeap, 0, cast(void*)gdipImage[1]); |
100 } | 98 } |
101 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); | 99 if (handle is null) DWT.error(DWT.ERROR_NO_HANDLES); |
102 if (device.tracking) device.new_Object(this); | 100 init_(); |
103 } | 101 } |
104 | 102 |
105 /** | 103 /** |
106 * Constructs a new Pattern that represents a linear, two color | 104 * Constructs a new Pattern that represents a linear, two color |
107 * gradient. Drawing with the pattern will cause the resulting area to be | 105 * gradient. Drawing with the pattern will cause the resulting area to be |
173 * @see #dispose() | 171 * @see #dispose() |
174 * | 172 * |
175 * @since 3.2 | 173 * @since 3.2 |
176 */ | 174 */ |
177 public this(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) { | 175 public this(Device device, float x1, float y1, float x2, float y2, Color color1, int alpha1, Color color2, int alpha2) { |
178 if (device is null) device = Device.getDevice(); | 176 super(device); |
179 if (device is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | |
180 if (color1 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 177 if (color1 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
181 if (color1.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 178 if (color1.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
182 if (color2 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); | 179 if (color2 is null) DWT.error(DWT.ERROR_NULL_ARGUMENT); |
183 if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); | 180 if (color2.isDisposed()) DWT.error(DWT.ERROR_INVALID_ARGUMENT); |
184 this.device = device; | 181 this.device.checkGDIP(); |
185 device.checkGDIP(); | |
186 auto colorRef1 = color1.handle; | 182 auto colorRef1 = color1.handle; |
187 int rgb = ((colorRef1 >> 16) & 0xFF) | (colorRef1 & 0xFF00) | ((colorRef1 & 0xFF) << 16); | 183 int rgb = ((colorRef1 >> 16) & 0xFF) | (colorRef1 & 0xFF00) | ((colorRef1 & 0xFF) << 16); |
188 auto foreColor = Gdip.Color_new((alpha1 & 0xFF) << 24 | rgb); | 184 auto foreColor = Gdip.Color_new((alpha1 & 0xFF) << 24 | rgb); |
189 if (x1 is x2 && y1 is y2) { | 185 if (x1 is x2 && y1 is y2) { |
190 handle = cast(Gdip.Brush)Gdip.SolidBrush_new(foreColor); | 186 handle = cast(Gdip.Brush)Gdip.SolidBrush_new(foreColor); |
213 c[2] = backColor; | 209 c[2] = backColor; |
214 float[3] f; | 210 float[3] f; |
215 f[0] = 0; | 211 f[0] = 0; |
216 f[1] = 0.5f; | 212 f[1] = 0.5f; |
217 f[2] = 1; | 213 f[2] = 1; |
218 Gdip.LinearGradientBrush_SetInterpolationColors( cast(Gdip.LinearGradientBrush)handle, c, f, 3); | 214 Gdip.LinearGradientBrush_SetInterpolationColors( cast(Gdip.LinearGradientBrush)handle, c.ptr, f.ptr, 3); |
219 Gdip.Color_delete(midColor); | 215 Gdip.Color_delete(midColor); |
220 } | 216 } |
221 Gdip.Color_delete(backColor); | 217 Gdip.Color_delete(backColor); |
222 } | 218 } |
223 Gdip.Color_delete(foreColor); | 219 Gdip.Color_delete(foreColor); |
224 if (device.tracking) device.new_Object(this); | 220 init_(); |
225 } | 221 } |
226 | 222 |
227 /** | 223 void destroy() { |
228 * Disposes of the operating system resources associated with | |
229 * the Pattern. Applications must dispose of all Patterns that | |
230 * they allocate. | |
231 */ | |
232 override public void dispose() { | |
233 if (handle is null) return; | |
234 if (device.isDisposed()) return; | |
235 int type = Gdip.Brush_GetType(handle); | 224 int type = Gdip.Brush_GetType(handle); |
236 switch (type) { | 225 switch (type) { |
237 case Gdip.BrushTypeSolidColor: | 226 case Gdip.BrushTypeSolidColor: |
238 Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)handle); | 227 Gdip.SolidBrush_delete(cast(Gdip.SolidBrush)handle); |
239 break; | 228 break; |
247 Gdip.TextureBrush_delete(cast(Gdip.TextureBrush)handle); | 236 Gdip.TextureBrush_delete(cast(Gdip.TextureBrush)handle); |
248 break; | 237 break; |
249 default: | 238 default: |
250 } | 239 } |
251 handle = null; | 240 handle = null; |
252 if (device.tracking) device.dispose_Object(this); | |
253 device = null; | |
254 } | 241 } |
255 | 242 |
256 /** | 243 /** |
257 * Returns <code>true</code> if the Pattern has been disposed, | 244 * Returns <code>true</code> if the Pattern has been disposed, |
258 * and <code>false</code> otherwise. | 245 * and <code>false</code> otherwise. |