PageRenderTime 43ms CodeModel.GetById 5ms app.highlight 33ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdipluspen.d

http://github.com/wilkie/djehuty
D | 445 lines | 310 code | 107 blank | 28 comment | 16 complexity | d178bad60640d9de86b8f3551c033029 MD5 | raw file
  1/*
  2 * gdipluspen.d
  3 *
  4 * This module implements GdiPlusPen.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.gdipluspen;
 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.gdiplusbrush;
 34import binding.win32.gdipluslinecaps;
 35
 36/**************************************************************************\
 37*
 38* Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
 39*
 40* Module Name:
 41*
 42*   GdiplusPen.h
 43*
 44* Abstract:
 45*
 46*   GDI+ Pen class
 47*
 48\**************************************************************************/
 49
 50extern(System):
 51
 52//--------------------------------------------------------------------------
 53// Pen class
 54//--------------------------------------------------------------------------
 55
 56class Pen : GdiplusBase {
 57
 58    this(in Color color,
 59        in REAL width = 1.0f) {
 60        Unit unit = Unit.UnitWorld;
 61        nativePen = null;
 62        lastResult = GdipCreatePen1(color.GetValue(),
 63                                    width, unit, &nativePen);
 64    }
 65
 66    this(in Brush brush, in REAL width = 1.0f) {
 67        Unit unit = Unit.UnitWorld;
 68        nativePen = null;
 69        lastResult = GdipCreatePen2(brush.nativeBrush,
 70                                    width, unit, &nativePen);
 71    }
 72
 73    ~this() {
 74        GdipDeletePen(nativePen);
 75    }
 76
 77    Pen Clone() {
 78        GpPen *clonePen = null;
 79
 80        lastResult = GdipClonePen(nativePen, &clonePen);
 81
 82        return new Pen(clonePen, lastResult);
 83    }
 84
 85    alias Clone dup;
 86
 87    Status SetWidth(in REAL width) {
 88        return SetStatus(GdipSetPenWidth(nativePen, width));
 89    }
 90
 91    REAL GetWidth() {
 92        REAL width;
 93
 94        SetStatus(GdipGetPenWidth(nativePen, &width));
 95
 96        return width;
 97    }
 98    
 99    // Set/get line caps: start, end, and dash
100
101    // Line cap and join APIs by using LineCap and LineJoin enums.
102
103    Status SetLineCap(in LineCap startCap,
104                      in LineCap endCap,
105                      in DashCap dashCap) {
106        return SetStatus(GdipSetPenLineCap197819(nativePen,
107                                   startCap, endCap, dashCap));
108    }
109
110    Status SetStartCap(in LineCap startCap) {
111        return SetStatus(GdipSetPenStartCap(nativePen, startCap));
112    }
113
114    Status SetEndCap(in LineCap endCap) {
115        return SetStatus(GdipSetPenEndCap(nativePen, endCap));
116    }
117
118    Status SetDashCap(in DashCap dashCap) {
119        return SetStatus(GdipSetPenDashCap197819(nativePen,
120                                   dashCap));
121    }
122
123    LineCap GetStartCap() {
124        LineCap startCap;
125
126        SetStatus(GdipGetPenStartCap(nativePen, &startCap));
127
128        return startCap;
129    }
130
131    LineCap GetEndCap() {
132        LineCap endCap;
133
134        SetStatus(GdipGetPenEndCap(nativePen, &endCap));
135
136        return endCap;
137    }
138
139    DashCap GetDashCap() {
140        DashCap dashCap;
141
142        SetStatus(GdipGetPenDashCap197819(nativePen,
143                            &dashCap));
144
145        return dashCap;
146    }
147
148    Status SetLineJoin(in LineJoin lineJoin) {
149        return SetStatus(GdipSetPenLineJoin(nativePen, lineJoin));
150    }
151
152    LineJoin GetLineJoin() {
153        LineJoin lineJoin;
154
155        SetStatus(GdipGetPenLineJoin(nativePen, &lineJoin));
156
157        return lineJoin;
158    }
159
160    Status SetCustomStartCap(in CustomLineCap* customCap) {
161        GpCustomLineCap* nativeCap = null;
162        if(customCap)
163            nativeCap = customCap.nativeCap;
164
165        return SetStatus(GdipSetPenCustomStartCap(nativePen,
166                                                              nativeCap));
167    }
168
169    Status GetCustomStartCap(out CustomLineCap* customCap) {
170        if(!customCap)
171            return SetStatus(Status.InvalidParameter);
172
173        return SetStatus(GdipGetPenCustomStartCap(nativePen,
174                                                    &(customCap.nativeCap)));
175    }
176
177    Status SetCustomEndCap(in CustomLineCap* customCap) {
178        GpCustomLineCap* nativeCap = null;
179        if(customCap)
180            nativeCap = customCap.nativeCap;
181
182        return SetStatus(GdipSetPenCustomEndCap(nativePen,
183                                                            nativeCap));
184    }
185
186    Status GetCustomEndCap(out CustomLineCap* customCap) {
187        if(!customCap)
188            return SetStatus(Status.InvalidParameter);
189
190        return SetStatus(GdipGetPenCustomEndCap(nativePen,
191                                                    &(customCap.nativeCap)));
192    }
193
194    Status SetMiterLimit(in REAL miterLimit) {
195        return SetStatus(GdipSetPenMiterLimit(nativePen,
196                                                    miterLimit));
197    }
198
199    REAL GetMiterLimit() {
200        REAL miterLimit;
201
202        SetStatus(GdipGetPenMiterLimit(nativePen, &miterLimit));
203
204        return miterLimit;
205    }
206
207    Status SetAlignment(in PenAlignment penAlignment) {
208        return SetStatus(GdipSetPenMode(nativePen, penAlignment));
209    }
210
211    PenAlignment GetAlignment() {
212        PenAlignment penAlignment;
213
214        SetStatus(GdipGetPenMode(nativePen, &penAlignment));
215
216        return penAlignment;
217    }
218
219    Status SetTransform(in Matrix* matrix) {
220        return SetStatus(GdipSetPenTransform(nativePen,
221                                                       matrix.nativeMatrix));
222    }
223
224    Status GetTransform(out Matrix* matrix) {
225        return SetStatus(GdipGetPenTransform(nativePen,
226                                                         matrix.nativeMatrix));
227    }
228
229    Status ResetTransform() {
230        return SetStatus(GdipResetPenTransform(nativePen));
231    }
232
233    Status MultiplyTransform(in Matrix* matrix,
234                             in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
235        return SetStatus(GdipMultiplyPenTransform(nativePen,
236                                                         matrix.nativeMatrix,
237                                                         order));
238    }
239
240    Status TranslateTransform(in REAL dx,
241                              in REAL dy,
242                              in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
243        return SetStatus(GdipTranslatePenTransform(nativePen,
244                                                               dx,
245                                                               dy,
246                                                               order));
247    }
248
249    Status ScaleTransform(in REAL sx,
250                          in REAL sy,
251                          in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
252        return SetStatus(GdipScalePenTransform(nativePen,
253                                                           sx,
254                                                           sy,
255                                                           order));
256    }
257
258    Status RotateTransform(in REAL angle,
259                           in MatrixOrder order = MatrixOrder.MatrixOrderPrepend) {
260        return SetStatus(GdipRotatePenTransform(nativePen,
261                                                            angle,
262                                                            order));
263    }
264
265    PenType GetPenType() {
266       PenType type;
267       SetStatus(GdipGetPenFillType(nativePen, &type));
268
269       return type;
270    }
271
272    Status SetColor(in Color color) {
273        return SetStatus(GdipSetPenColor(nativePen,
274                                                     color.GetValue()));
275    }
276
277    Status SetBrush(in Brush brush) {
278        return SetStatus(GdipSetPenBrushFill(nativePen,
279                                       brush.nativeBrush));
280    }
281
282    Status GetColor(out Color color) {
283        if (color is null) {
284            return SetStatus(Status.InvalidParameter);
285        }
286
287        PenType type = GetPenType();
288
289        if (type != PenType.PenTypeSolidColor) {
290            return Status.WrongState;
291        }
292
293        ARGB argb;
294
295        SetStatus(GdipGetPenColor(nativePen,
296                                              &argb));
297        if (lastResult == Status.Ok) {
298            color.SetValue(argb);
299        }
300
301        return lastResult;
302    }
303
304    Brush GetBrush() {
305       PenType type = GetPenType();
306
307       Brush brush = null;
308
309       switch(type) {
310       case PenType.PenTypeSolidColor:
311           brush = new SolidBrush();
312           break;
313
314       case PenType.PenTypeHatchFill:
315           brush = new HatchBrush();
316           break;
317
318       case PenType.PenTypeTextureFill:
319           brush = new TextureBrush();
320           break;
321
322       case PenType.PenTypePathGradient:
323           brush = new Brush();
324           break;
325
326       case PenType.PenTypeLinearGradient:
327           brush = new LinearGradientBrush();
328           break;
329
330       default:
331           break;
332       }
333
334       if(brush) {
335           GpBrush* nativeBrush;
336
337           SetStatus(GdipGetPenBrushFill(nativePen,
338                                                     &nativeBrush));
339           brush.SetNativeBrush(nativeBrush);
340       }
341
342       return brush;
343    }
344
345    DashStyle GetDashStyle() {
346        DashStyle dashStyle;
347
348        SetStatus(GdipGetPenDashStyle(nativePen, &dashStyle));
349
350        return dashStyle;
351    }
352
353    Status SetDashStyle(in DashStyle dashStyle) {
354        return SetStatus(GdipSetPenDashStyle(nativePen,
355                                                         dashStyle));
356    }
357
358    REAL GetDashOffset() {
359        REAL dashOffset;
360
361        SetStatus(GdipGetPenDashOffset(nativePen, &dashOffset));
362
363        return dashOffset;
364    }
365
366    Status SetDashOffset(in REAL dashOffset) {
367        return SetStatus(GdipSetPenDashOffset(nativePen,
368                                                          dashOffset));
369    }
370
371    Status SetDashPattern(in REAL* dashArray, in INT count) {
372        return SetStatus(GdipSetPenDashArray(nativePen,
373                                                         dashArray,
374                                                         count));
375    }
376
377    INT GetDashPatternCount() {
378        INT count = 0;
379
380        SetStatus(GdipGetPenDashCount(nativePen, &count));
381
382        return count;
383    }
384
385    Status GetDashPattern(out REAL* dashArray, in INT count) {
386        if (dashArray is null || count <= 0)
387            return SetStatus(Status.InvalidParameter);
388
389        return SetStatus(GdipGetPenDashArray(nativePen,
390                                                         dashArray,
391                                                         count));
392    }
393
394    Status SetCompoundArray(in REAL* compoundArray,
395                            in INT count) {
396        return SetStatus(GdipSetPenCompoundArray(nativePen,
397                                                             compoundArray,
398                                                             count));
399    }
400
401    INT GetCompoundArrayCount() {
402        INT count = 0;
403
404        SetStatus(GdipGetPenCompoundCount(nativePen, &count));
405
406        return count;
407    }
408
409    Status GetCompoundArray(out REAL* compoundArray, in INT count) {
410        if (compoundArray is null || count <= 0)
411            return SetStatus(Status.InvalidParameter);
412
413        return SetStatus(GdipGetPenCompoundArray(nativePen,
414                                                             compoundArray,
415                                                             count));
416    }
417
418    Status GetLastStatus() {
419        Status lastStatus = lastResult;
420        lastResult = Status.Ok;
421
422        return lastStatus;
423    }
424
425protected:
426
427    package this(GpPen* nativePen, Status status) {
428        lastResult = status;
429        SetNativePen(nativePen);
430    }
431
432    VOID SetNativePen(GpPen* nativePen) {
433        this.nativePen = nativePen;
434    }
435
436    Status SetStatus(Status status) {
437        if (status != Status.Ok)
438            return (lastResult = status);
439        else
440            return status;
441    }
442
443    package GpPen* nativePen;
444    package Status lastResult;
445}