PageRenderTime 29ms CodeModel.GetById 2ms app.highlight 24ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdiplusregion.d

http://github.com/wilkie/djehuty
D | 417 lines | 291 code | 99 blank | 27 comment | 5 complexity | 18c127e957e99e15e4090836a0ba59c7 MD5 | raw file
  1/*
  2 * gdiplusregion.d
  3 *
  4 * This module implements GdiPlusRegion.h for D. The original
  5 * copyright info is given below.
  6 *
  7 * Author: Dave Wilkinson
  8 * Originated: November 25th, 2009
  9 *
 10 */
 11
 12module binding.win32.gdiplusregion;
 13
 14import binding.win32.windef;
 15import binding.win32.winbase;
 16import binding.win32.winnt;
 17import binding.win32.wingdi;
 18import binding.win32.guiddef;
 19import binding.win32.gdiplusbase;
 20import binding.win32.gdiplustypes;
 21import binding.win32.gdiplusenums;
 22import binding.win32.gdipluspixelformats;
 23import binding.win32.gdiplusgpstubs;
 24import binding.win32.gdiplusmetaheader;
 25import binding.win32.gdipluspixelformats;
 26import binding.win32.gdipluscolor;
 27import binding.win32.gdipluscolormatrix;
 28import binding.win32.gdiplusflat;
 29import binding.win32.gdiplusimaging;
 30import binding.win32.gdiplusbitmap;
 31import binding.win32.gdiplusimageattributes;
 32import binding.win32.gdiplusmatrix;
 33import binding.win32.gdipluspath;
 34import binding.win32.gdiplusgraphics;
 35
 36/**************************************************************************\
 37*
 38* Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
 39*
 40* Module Name:
 41*
 42*   GdiplusRegion.h
 43*
 44* Abstract:
 45*
 46*   GDI+ Region class implementation
 47*
 48\**************************************************************************/
 49
 50class Region : GdiplusBase {
 51public:
 52    this() {
 53      GpRegion *region = null;
 54  
 55      lastResult = GdipCreateRegion(&region);
 56  
 57      SetNativeRegion(region);
 58    }
 59    
 60    this(in RectF rect) {
 61      GpRegion *region = null;
 62  
 63      lastResult = GdipCreateRegionRect(&rect, &region);
 64  
 65      SetNativeRegion(region);
 66    }
 67    
 68    this(in Rect rect) {
 69      GpRegion *region = null;
 70  
 71      lastResult = GdipCreateRegionRectI(&rect, &region);
 72  
 73      SetNativeRegion(region);      
 74    }
 75    
 76    this(in GraphicsPath path) {
 77      GpRegion *region = null;
 78  
 79      lastResult = GdipCreateRegionPath(path.nativePath, &region);
 80  
 81      SetNativeRegion(region);      
 82    }
 83    
 84    this(in BYTE* regionData, in INT size) {
 85      GpRegion *region = null;
 86  
 87      lastResult = GdipCreateRegionRgnData(regionData, size, 
 88                                                       &region);
 89  
 90      SetNativeRegion(region);      
 91    }
 92    
 93    this(in HRGN hRgn) {
 94      GpRegion *region = null;
 95  
 96      lastResult = GdipCreateRegionHrgn(hRgn, &region);
 97  
 98      SetNativeRegion(region);      
 99    }
100    
101    static Region FromHRGN(in HRGN hRgn) {
102      GpRegion *region = null;
103  
104      if (GdipCreateRegionHrgn(hRgn, &region) == Status.Ok) {
105          Region newRegion = new Region(region);
106  
107          if (newRegion is null) {
108              GdipDeleteRegion(region);
109          }
110  
111          return newRegion;
112      }
113      else
114          return null;      
115    }
116
117    ~this() {
118      GdipDeleteRegion(nativeRegion);
119    }
120    
121    Region Clone() {
122      GpRegion *region = null;
123  
124      SetStatus(GdipCloneRegion(nativeRegion, &region));
125  
126      return new Region(region);
127    }
128    
129    alias Clone dup;
130
131    Status MakeInfinite() {
132      return SetStatus(GdipSetInfinite(nativeRegion));      
133    }
134    
135    Status MakeEmpty() {
136      return SetStatus(GdipSetEmpty(nativeRegion));
137    }
138
139    UINT GetDataSize() {
140      UINT     bufferSize = 0;
141      
142      SetStatus(GdipGetRegionDataSize(nativeRegion, &bufferSize));
143      
144      return bufferSize;      
145    }
146
147    // buffer     - where to put the data
148    // bufferSize - how big the buffer is (should be at least as big as GetDataSize())
149    // sizeFilled - if not null, this is an param that says how many bytes
150    //              of data were written to the buffer.
151
152    Status GetData(BYTE* buffer, in UINT bufferSize, UINT* sizeFilled = null) {
153      return SetStatus(GdipGetRegionData(nativeRegion, buffer, bufferSize, sizeFilled));                     
154    }
155
156    Status Intersect(in Rect rect) {
157      return SetStatus(GdipCombineRegionRectI(nativeRegion, &rect, CombineMode.CombineModeIntersect));
158    }
159    
160    Status Intersect(in RectF rect) {
161      return SetStatus(GdipCombineRegionRect(nativeRegion, &rect, CombineMode.CombineModeIntersect));      
162    }
163    
164    Status Intersect(in GraphicsPath path) {
165      return SetStatus(GdipCombineRegionPath(nativeRegion, path.nativePath, CombineMode.CombineModeIntersect));      
166    }
167    
168    Status Intersect(in Region region) {
169      return SetStatus(GdipCombineRegionRegion(nativeRegion, region.nativeRegion, CombineMode.CombineModeIntersect));
170    }
171    
172    Status Union(in Rect rect) {
173      return SetStatus(GdipCombineRegionRectI(nativeRegion, &rect, CombineMode.CombineModeUnion));            
174    }
175    
176    Status Union(in RectF rect) {
177      return SetStatus(GdipCombineRegionRect(nativeRegion, &rect, CombineMode.CombineModeUnion));      
178    }
179    
180    Status Union(in GraphicsPath path) {
181      return SetStatus(GdipCombineRegionPath(nativeRegion, path.nativePath, CombineMode.CombineModeUnion));      
182    }
183    
184    Status Union(in Region region) {
185      return SetStatus(GdipCombineRegionRegion(nativeRegion, region.nativeRegion, CombineMode.CombineModeUnion));      
186    }
187    
188    Status Xor(in Rect rect) {    
189      return SetStatus(GdipCombineRegionRectI(nativeRegion, &rect, CombineMode.CombineModeXor));  
190    }
191    
192    Status Xor(in RectF rect) {
193      return SetStatus(GdipCombineRegionRect(nativeRegion, &rect, CombineMode.CombineModeXor));        
194    }
195    
196    Status Xor(in GraphicsPath path) {
197      return SetStatus(GdipCombineRegionPath(nativeRegion, path.nativePath, CombineMode.CombineModeXor));      
198    }
199    
200    Status Xor(in Region region) {
201      return SetStatus(GdipCombineRegionRegion(nativeRegion, region.nativeRegion, CombineMode.CombineModeXor));      
202    }
203    
204    Status Exclude(in Rect rect) {
205      return SetStatus(GdipCombineRegionRectI(nativeRegion, &rect, CombineMode.CombineModeExclude));      
206    }
207    
208    Status Exclude(in RectF rect) {
209      return SetStatus(GdipCombineRegionRect(nativeRegion, &rect, CombineMode.CombineModeExclude));      
210    }
211    
212    Status Exclude(in GraphicsPath path) {
213      return SetStatus(GdipCombineRegionPath(nativeRegion, path.nativePath, CombineMode.CombineModeExclude));      
214    }
215    
216    Status Exclude(in Region region) {
217      return SetStatus(GdipCombineRegionRegion(nativeRegion, region.nativeRegion, CombineMode.CombineModeExclude));      
218    }
219    
220    Status Complement(in Rect rect) {
221      return SetStatus(GdipCombineRegionRectI(nativeRegion, &rect, CombineMode.CombineModeComplement));      
222    }
223    
224    Status Complement(in RectF rect) {
225      return SetStatus(GdipCombineRegionRect(nativeRegion, &rect, CombineMode.CombineModeComplement));      
226      
227    }
228    
229    Status Complement(in GraphicsPath path) {
230      return SetStatus(GdipCombineRegionPath(nativeRegion, path.nativePath, CombineMode.CombineModeComplement));      
231    }
232    
233    Status Complement(in Region region) {
234      return SetStatus(GdipCombineRegionRegion(nativeRegion, region.nativeRegion, CombineMode.CombineModeComplement));      
235    }
236    
237    Status Translate(in REAL dx,
238                     in REAL dy) {
239      return SetStatus(GdipTranslateRegion(nativeRegion, dx, dy)); 
240    }
241                     
242    Status Translate(in INT dx,
243                     in INT dy) {
244      return SetStatus(GdipTranslateRegionI(nativeRegion, dx, dy));                       
245    }
246                     
247    Status Transform(in Matrix matrix) {
248      return SetStatus(GdipTransformRegion(nativeRegion, matrix.nativeMatrix));      
249    }
250
251    Status GetBounds(ref Rect rect, in Graphics g) {
252      return SetStatus(GdipGetRegionBoundsI(nativeRegion, g.nativeGraphics, &rect));
253    }
254
255    Status GetBounds(ref RectF rect, in Graphics g) {
256      return SetStatus(GdipGetRegionBounds(nativeRegion, g.nativeGraphics, &rect));                       
257    }
258
259    HRGN   GetHRGN  (in Graphics g) {
260      HRGN hrgn;
261  
262      SetStatus(GdipGetRegionHRgn(nativeRegion, g.nativeGraphics, &hrgn));
263  
264      return hrgn;      
265    }
266
267    BOOL IsEmpty(in Graphics g) {
268      BOOL booln = FALSE;
269     
270      SetStatus(GdipIsEmptyRegion(nativeRegion, g.nativeGraphics, &booln));
271  
272      return booln;      
273    }
274    
275    BOOL IsInfinite(in Graphics g) {
276      BOOL booln = FALSE;
277  
278      SetStatus(GdipIsInfiniteRegion(nativeRegion, g.nativeGraphics, &booln));
279  
280      return booln;      
281    }
282
283    BOOL IsVisible(in INT x,
284                   in INT y,
285                   in Graphics g = null) {
286        return IsVisible(Point(x, y), g);
287    }
288
289    BOOL IsVisible(in Point point,
290                   in Graphics g = null) {
291      BOOL booln = FALSE;
292  
293  
294      SetStatus(GdipIsVisibleRegionPointI(nativeRegion,
295                                                     point.X,
296                                                     point.Y,
297                                                     (g is null) 
298                                                      ? null : g.nativeGraphics,
299                                                     &booln));
300      return booln;                     
301    }
302
303    BOOL IsVisible(in REAL x,
304                   in REAL y,
305                   in Graphics g = null) {
306        return IsVisible(PointF(x, y), g);
307    }
308
309    BOOL IsVisible(in PointF point,
310                   in Graphics g = null) {
311      BOOL booln = FALSE;
312  
313      SetStatus(GdipIsVisibleRegionPoint(nativeRegion, point.X, point.Y, 
314                                       (g is null) ? null : g.nativeGraphics,
315                                       &booln));
316      return booln;                     
317    }
318
319    BOOL IsVisible(in INT x,
320                   in INT y,
321                   in INT width,
322                   in INT height,
323                   in Graphics g) {
324        return IsVisible(Rect(x, y, width, height), g);
325    }
326
327    BOOL IsVisible(in Rect rect,
328                   in Graphics g = null) {
329      BOOL booln = FALSE;
330  
331      SetStatus(GdipIsVisibleRegionRectI(nativeRegion,
332                                                    rect.X,
333                                                    rect.Y,
334                                                    rect.Width,
335                                                    rect.Height,
336                                                    (g is null) 
337                                                      ? null : g.nativeGraphics,
338                                                    &booln));
339      return booln;                     
340    }
341
342    BOOL IsVisible(in REAL x,
343                   in REAL y,
344                   in REAL width,
345                   in REAL height,
346                   in Graphics g = null) {
347        return IsVisible(RectF.init(x, y, width, height), g);
348    }
349
350    BOOL IsVisible(in RectF rect,
351                   in Graphics g = null) {
352      BOOL booln = FALSE;
353  
354      SetStatus(GdipIsVisibleRegionRect(nativeRegion, rect.X,
355                                                      rect.Y, rect.Width,
356                                                      rect.Height,
357                                                      (g is null) ?
358                                                        null : g.nativeGraphics,
359                                                      &booln));
360      return booln;                     
361    }
362
363    BOOL Equals(in Region region, in Graphics g) {
364      BOOL booln = FALSE;
365  
366      SetStatus(GdipIsEqualRegion(nativeRegion, region.nativeRegion, g.nativeGraphics, &booln));
367      
368      return booln;                  
369    }
370
371    UINT GetRegionScansCount(in Matrix matrix) {
372      UINT count = 0;
373  
374      SetStatus(GdipGetRegionScansCount(nativeRegion, &count, matrix.nativeMatrix));
375      return count;      
376    }
377    
378    Status GetRegionScans(in Matrix matrix,
379                          RectF[] rects,
380                          ref INT count) {
381      return SetStatus(GdipGetRegionScans(nativeRegion, rects.ptr, &count, matrix.nativeMatrix));                              
382    }
383                          
384    Status GetRegionScans(in Matrix matrix,
385                          Rect[]  rects,
386                          ref INT count) {
387      return SetStatus(GdipGetRegionScansI(nativeRegion, rects.ptr, &count, matrix.nativeMatrix));                            
388    }
389                          
390    Status GetLastStatus() {
391      Status lastStatus = lastResult;
392      lastResult = Status.Ok;
393  
394      return lastStatus;      
395    }
396
397protected:
398
399    Status SetStatus(Status status) {
400        if (status != Status.Ok)
401            return (lastResult = status);
402        else
403            return status;
404    }
405
406    this(GpRegion* nativeRegion) {
407      SetNativeRegion(nativeRegion);      
408    }
409
410    VOID SetNativeRegion(GpRegion* nativeRegion) {
411      this.nativeRegion = nativeRegion;      
412    }
413
414protected:
415    package GpRegion* nativeRegion;
416    package Status lastResult;
417}