PageRenderTime 106ms CodeModel.GetById 53ms app.highlight 48ms RepoModel.GetById 1ms app.codeStats 0ms

/binding/win32/gdiplustypes.d

http://github.com/wilkie/djehuty
D | 624 lines | 423 code | 115 blank | 86 comment | 36 complexity | eace3efa246c9f6131bd7d2089219d7d MD5 | raw file
  1/*
  2 * gdiplustypes.d
  3 *
  4 * This module binds GdiPlusTypes.h to D. The original copyright
  5 * notice is preserved below.
  6 *
  7 * Author: Dave Wilkinson
  8 * Originated: November 25th, 2009
  9 *
 10 */
 11
 12module binding.win32.gdiplustypes;
 13
 14import binding.win32.windef;
 15import binding.win32.winbase;
 16import binding.win32.winnt;
 17
 18import binding.win32.gdiplusenums;
 19
 20extern(System):
 21
 22/**************************************************************************\
 23*
 24* Copyright (c) 1998-2001, Microsoft Corp.  All Rights Reserved.
 25*
 26* Module Name:
 27*
 28*   GdiplusTypes.hco
 29*
 30* Abstract:
 31*
 32*   GDI+ Types
 33*
 34\**************************************************************************/
 35
 36extern(System) struct IDirectDrawSurface7;
 37
 38//--------------------------------------------------------------------------
 39// Callback functions
 40//--------------------------------------------------------------------------
 41
 42alias BOOL function(VOID*) ImageAbort;
 43alias ImageAbort DrawImageAbort;
 44alias ImageAbort GetThumbnailImageAbort;
 45
 46// Callback for EnumerateMetafile methods.  The parameters are:
 47
 48//      recordType      WMF, EMF, or EMF+ record type
 49//      flags           (always 0 for WMF/EMF records)
 50//      dataSize        size of the record data (in bytes), or 0 if no data
 51//      data            pointer to the record data, or NULL if no data
 52//      callbackData    pointer to callbackData, if any
 53
 54// This method can then call Metafile::PlayRecord to play the
 55// record that was just enumerated.  If this method  returns
 56// FALSE, the enumeration process is aborted.  Otherwise, it continues.
 57
 58alias BOOL function(EmfPlusRecordType, UINT, UINT, BYTE*, VOID*) EnumerateMetafileProc;
 59
 60// This is the main GDI+ Abort interface
 61
 62extern(C++) interface GdiplusAbort {
 63    HRESULT Abort();
 64}
 65
 66//--------------------------------------------------------------------------
 67// Primitive data types
 68//
 69// NOTE:
 70//  Types already defined in standard header files:
 71//      INT8
 72//      UINT8
 73//      INT16
 74//      UINT16
 75//      INT32
 76//      UINT32
 77//      INT64
 78//      UINT64
 79//
 80//  Avoid using the following types:
 81//      LONG - use INT
 82//      ULONG - use UINT
 83//      DWORD - use UINT32
 84//--------------------------------------------------------------------------
 85
 86alias float REAL;
 87
 88const auto REAL_MAX            = REAL.max;
 89const auto REAL_MIN            = REAL.min;
 90const auto REAL_TOLERANCE      = (REAL.min * 100);
 91const auto REAL_EPSILON        = 1.192092896e-07F;        /* FLT_EPSILON */
 92
 93//--------------------------------------------------------------------------
 94// Status return values from GDI+ methods
 95//--------------------------------------------------------------------------
 96
 97enum Status {
 98    Ok = 0,
 99    GenericError = 1,
100    InvalidParameter = 2,
101    OutOfMemory = 3,
102    ObjectBusy = 4,
103    InsufficientBuffer = 5,
104    NotImplemented = 6,
105    Win32Error = 7,
106    WrongState = 8,
107    Aborted = 9,
108    FileNotFound = 10,
109    ValueOverflow = 11,
110    AccessDenied = 12,
111    UnknownImageFormat = 13,
112    FontFamilyNotFound = 14,
113    FontStyleNotFound = 15,
114    NotTrueTypeFont = 16,
115    UnsupportedGdiplusVersion = 17,
116    GdiplusNotInitialized = 18,
117    PropertyNotFound = 19,
118    PropertyNotSupported = 20,
119
120    ProfileNotFound = 21,
121}
122
123//--------------------------------------------------------------------------
124// Represents a dimension in a 2D coordinate system (floating-point coordinates)
125//--------------------------------------------------------------------------
126
127struct SizeF {
128public:
129	SizeF init(SizeF size) {
130		SizeF ret;
131		ret.Width = size.Width;
132		ret.Height = size.Height;
133		return ret;
134	}
135
136	SizeF init(REAL width, REAL height) {
137		SizeF ret;
138		ret.Width = width;
139		ret.Height = height;
140		return ret;
141	}
142
143	SizeF opAdd(SizeF sz) {
144		return SizeF(Width + sz.Width, Height + sz.Height);
145	}
146
147	SizeF opSub(SizeF sz) {
148		return SizeF(Width - sz.Width, Height - sz.Height);
149	}
150
151    BOOL Equals(SizeF sz) {
152        return (Width == sz.Width) && (Height == sz.Height);
153    }
154
155    BOOL Empty() {
156        return (Width == 0.0f && Height == 0.0f);
157    }
158
159    REAL Width = 0.0f;
160    REAL Height = 0.0f;
161}
162
163//--------------------------------------------------------------------------
164// Represents a dimension in a 2D coordinate system (integer coordinates)
165//--------------------------------------------------------------------------
166
167struct Size {
168public:
169    static Size init(Size size) {
170    	Size ret;
171        ret.Width = size.Width;
172        ret.Height = size.Height;
173        return ret;
174    }
175
176    static Size init(INT width, INT height) {
177    	Size ret;
178        ret.Width = width;
179        ret.Height = height;
180        return ret;
181    }
182
183    Size opAdd(Size sz) {
184        return Size(Width + sz.Width, Height + sz.Height);
185    }
186
187    Size opSub(Size sz) {
188        return Size(Width - sz.Width,
189                    Height - sz.Height);
190    }
191
192    BOOL Equals(Size sz)  {
193        return (Width == sz.Width) && (Height == sz.Height);
194    }
195
196    BOOL Empty() {
197        return (Width == 0 && Height == 0);
198    }
199
200    INT Width;
201    INT Height;
202}
203
204
205//--------------------------------------------------------------------------
206// Represents a location in a 2D coordinate system (floating-point coordinates)
207//--------------------------------------------------------------------------
208
209struct PointF {
210public:
211	static PointF init(ref PointF point) {
212		PointF ret;
213		ret.X = point.X;
214		ret.Y = point.Y;
215		return ret;
216	}
217
218	static PointF init(ref SizeF size) {
219		PointF ret;
220		ret.X = size.Width;
221		ret.Y = size.Height;
222		return ret;
223	}
224
225	static PointF init(REAL x, REAL y)  {
226		PointF ret;
227	    ret.X = x;
228	    ret.Y = y;
229	    return ret;
230	}
231
232	PointF opAdd(ref PointF point) {
233	    return PointF(X + point.X, Y + point.Y);
234	}
235
236	PointF opSub(ref PointF point) {
237	    return PointF(X - point.X, Y - point.Y);
238	}
239
240	BOOL Equals(ref PointF point) {
241	    return (X == point.X) && (Y == point.Y);
242	}
243
244    REAL X;
245    REAL Y;
246}
247
248//--------------------------------------------------------------------------
249// Represents a location in a 2D coordinate system (integer coordinates)
250//--------------------------------------------------------------------------
251
252struct Point {
253public:
254
255	static Point init(in Point point) {
256		Point ret;
257	    ret.X = point.X;
258	    ret.Y = point.Y;
259	    return ret;
260	}
261
262	static Point init(in Size size) {
263		Point ret;
264	    ret.X = size.Width;
265	    ret.Y = size.Height;
266	    return ret;
267	}
268
269	Point init(INT x, INT y) {
270		Point ret;
271	    ret.X = x;
272	    ret.Y = y;
273	    return ret;
274	}
275
276	Point opAdd(in Point point) {
277	    return Point(X + point.X, Y + point.Y);
278	}
279
280	Point opSub(in Point point) {
281	    return Point(X - point.X, Y - point.Y);
282	}
283
284	BOOL Equals(in Point point) {
285	    return (X == point.X) && (Y == point.Y);
286	}
287
288    INT X;
289    INT Y;
290}
291
292//--------------------------------------------------------------------------
293// Represents a rectangle in a 2D coordinate system (floating-point coordinates)
294//--------------------------------------------------------------------------
295
296struct RectF {
297public:
298    static RectF init(REAL x, REAL y, REAL width, REAL height) {
299    	RectF ret;
300        ret.X = x;
301        ret.Y = y;
302        ret.Width = width;
303        ret.Height = height;
304        return ret;
305    }
306
307    static RectF init(in PointF location, in SizeF size) {
308    	RectF ret;
309        ret.X = location.X;
310        ret.Y = location.Y;
311        ret.Width = size.Width;
312        ret.Height = size.Height;
313        return ret;
314    }
315
316    RectF Clone() {
317    	return RectF.init(X, Y, Width, Height);
318    }
319
320    alias Clone dup;
321
322    VOID GetLocation(out PointF point) {
323    	point.X = X;
324    	point.Y = Y;
325    }
326
327    VOID GetSize(out SizeF size) {
328    	size.Width = Width;
329    	size.Height = Height;
330    }
331
332    VOID GetBounds(out RectF rect) {
333    	rect.X = X;
334    	rect.Y = Y;
335		rect.Width = Width;
336		rect.Height = Height;
337    }
338
339    REAL GetLeft() {
340        return X;
341    }
342
343    REAL GetTop() {
344        return Y;
345    }
346
347    REAL GetRight() {
348        return X+Width;
349    }
350
351    REAL GetBottom() {
352        return Y+Height;
353    }
354
355    BOOL IsEmptyArea() {
356        return (Width <= REAL_EPSILON) || (Height <= REAL_EPSILON);
357    }
358
359    BOOL Equals(in RectF rect) {
360        return X == rect.X &&
361               Y == rect.Y &&
362               Width == rect.Width &&
363               Height == rect.Height;
364    }
365
366    BOOL Contains(in REAL x, in REAL y) {
367        return x >= X && x < X+Width &&
368               y >= Y && y < Y+Height;
369    }
370
371    BOOL Contains(in PointF pt) {
372        return Contains(pt.X, pt.Y);
373    }
374
375    BOOL Contains(in RectF rect) {
376        return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
377               (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
378    }
379
380    VOID Inflate(in REAL dx, in REAL dy) {
381        X -= dx;
382        Y -= dy;
383        Width += 2*dx;
384        Height += 2*dy;
385    }
386
387    VOID Inflate(in PointF point) {
388        Inflate(point.X, point.Y);
389    }
390
391    BOOL Intersect(in RectF rect) {
392        return Intersect(*this, *this, rect);
393    }
394
395    static BOOL Intersect(RectF c, in RectF a, in RectF b) {
396    	REAL right = ((a.GetRight() < b.GetRight()) ? a.GetRight() : b.GetRight());
397//        REAL right = min(a.GetRight(), b.GetRight());
398    	REAL bottom = ((a.GetBottom() < b.GetBottom()) ? a.GetBottom() : b.GetBottom());
399    	REAL left = ((a.GetLeft() > b.GetLeft()) ? a.GetLeft() : b.GetLeft());
400    	REAL top = ((a.GetTop() > b.GetTop()) ? a.GetTop() : b.GetTop());
401
402        c.X = left;
403        c.Y = top;
404        c.Width = right - left;
405        c.Height = bottom - top;
406        return !c.IsEmptyArea();
407    }
408
409    BOOL IntersectsWith(in RectF rect) {
410        return (GetLeft() < rect.GetRight() &&
411                GetTop() < rect.GetBottom() &&
412                GetRight() > rect.GetLeft() &&
413                GetBottom() > rect.GetTop());
414    }
415
416    static BOOL Union(out RectF c, in RectF a, in RectF b) {
417    	REAL right = ((a.GetRight() > b.GetRight()) ? a.GetRight() : b.GetRight());
418    	REAL bottom = ((a.GetBottom() > b.GetBottom()) ? a.GetBottom() : b.GetBottom());
419//        REAL right = max(a.GetRight(), b.GetRight());
420//        REAL bottom = max(a.GetBottom(), b.GetBottom());
421//        REAL left = min(a.GetLeft(), b.GetLeft());
422//        REAL top = min(a.GetTop(), b.GetTop());
423    	REAL left = ((a.GetLeft() < b.GetLeft()) ? a.GetLeft() : b.GetLeft());
424    	REAL top = ((a.GetTop() < b.GetTop()) ? a.GetTop() : b.GetTop());
425
426        c.X = left;
427        c.Y = top;
428        c.Width = right - left;
429        c.Height = bottom - top;
430        return !c.IsEmptyArea();
431    }
432
433    VOID Offset(in PointF point) {
434        Offset(point.X, point.Y);
435    }
436
437    VOID Offset(in REAL dx, in REAL dy) {
438        X += dx;
439        Y += dy;
440    }
441
442    REAL X;
443    REAL Y;
444    REAL Width;
445    REAL Height;
446}
447
448//--------------------------------------------------------------------------
449// Represents a rectangle in a 2D coordinate system (integer coordinates)
450//--------------------------------------------------------------------------
451
452struct Rect {
453public:
454
455	static Rect init(in INT x, in INT y, in INT width, in INT height) {
456		Rect ret;
457        ret.X = x;
458        ret.Y = y;
459        ret.Width = width;
460        ret.Height = height;
461        return ret;
462    }
463
464    static Rect init(in Point location, in Size size) {
465    	Rect ret;
466        ret.X = location.X;
467        ret.Y = location.Y;
468        ret.Width = size.Width;
469        ret.Height = size.Height;
470        return ret;
471    }
472
473    Rect Clone() {
474        return Rect.init(X, Y, Width, Height);
475    }
476
477    alias Clone dup;
478
479    VOID GetLocation(out Point point) {
480    	point.X = X;
481    	point.Y = Y;
482    }
483
484    VOID GetSize(out Size size) {
485        size.Width = Width;
486        size.Height = Height;
487    }
488
489    VOID GetBounds(out Rect rect) {
490        rect.X = X;
491        rect.Y = Y;
492        rect.Width = Width;
493        rect.Height = Height;
494    }
495
496    INT GetLeft() {
497        return X;
498    }
499
500    INT GetTop() {
501        return Y;
502    }
503
504    INT GetRight() {
505        return X+Width;
506    }
507
508    INT GetBottom() {
509        return Y+Height;
510    }
511
512    BOOL IsEmptyArea() {
513        return (Width <= 0) || (Height <= 0);
514    }
515
516    BOOL Equals(in Rect rect) {
517        return X == rect.X &&
518               Y == rect.Y &&
519               Width == rect.Width &&
520               Height == rect.Height;
521    }
522
523    BOOL Contains(in INT x, in INT y) {
524        return x >= X && x < X+Width &&
525               y >= Y && y < Y+Height;
526    }
527
528    BOOL Contains(in Point pt) {
529        return Contains(pt.X, pt.Y);
530    }
531
532    BOOL Contains(in Rect rect) {
533        return (X <= rect.X) && (rect.GetRight() <= GetRight()) &&
534               (Y <= rect.Y) && (rect.GetBottom() <= GetBottom());
535    }
536
537    VOID Inflate(in INT dx, in INT dy) {
538        X -= dx;
539        Y -= dy;
540        Width += 2*dx;
541        Height += 2*dy;
542    }
543
544    VOID Inflate(in Point point) {
545        Inflate(point.X, point.Y);
546    }
547
548    BOOL Intersect(in Rect rect) {
549        return Intersect(*this, *this, rect);
550    }
551
552    static BOOL Intersect(out Rect c, in Rect a, in Rect b) {
553    	INT right = ((a.GetRight() < b.GetRight()) ? a.GetRight() : b.GetRight());
554//        INT right = min(a.GetRight(), b.GetRight());
555    	INT bottom = ((a.GetBottom() < b.GetBottom()) ? a.GetBottom() : b.GetBottom());
556    	INT left = ((a.GetLeft() > b.GetLeft()) ? a.GetLeft() : b.GetLeft());
557    	INT top = ((a.GetTop() > b.GetTop()) ? a.GetTop() : b.GetTop());
558
559        c.X = left;
560        c.Y = top;
561        c.Width = right - left;
562        c.Height = bottom - top;
563        return !c.IsEmptyArea();
564    }
565
566    BOOL IntersectsWith(in Rect rect) {
567        return (GetLeft() < rect.GetRight() &&
568                GetTop() < rect.GetBottom() &&
569                GetRight() > rect.GetLeft() &&
570                GetBottom() > rect.GetTop());
571    }
572
573    static BOOL Union(out Rect c, in Rect a, in Rect b) {
574    	INT right = ((a.GetRight() > b.GetRight()) ? a.GetRight() : b.GetRight());
575    	INT bottom = ((a.GetBottom() > b.GetBottom()) ? a.GetBottom() : b.GetBottom());
576//        INT right = max(a.GetRight(), b.GetRight());
577//        INT bottom = max(a.GetBottom(), b.GetBottom());
578//        INT left = min(a.GetLeft(), b.GetLeft());
579//        INT top = min(a.GetTop(), b.GetTop());
580    	INT left = ((a.GetLeft() < b.GetLeft()) ? a.GetLeft() : b.GetLeft());
581    	INT top = ((a.GetTop() < b.GetTop()) ? a.GetTop() : b.GetTop());
582
583        c.X = left;
584        c.Y = top;
585        c.Width = right - left;
586        c.Height = bottom - top;
587        return !c.IsEmptyArea();
588    }
589
590    VOID Offset(in Point point) {
591        Offset(point.X, point.Y);
592    }
593
594    VOID Offset(in INT dx, in INT dy) {
595        X += dx;
596        Y += dy;
597    }
598
599    INT X;
600    INT Y;
601    INT Width;
602    INT Height;
603}
604
605struct PathData {
606public:
607    INT Count;
608    PointF[] Points;
609	BYTE[] Types;
610}
611
612struct CharacterRange {
613public:
614
615	CharacterRange init(INT first, INT length) {
616		CharacterRange ret;
617		ret.First = first;
618		ret.Length = length;
619		return ret;
620	}
621
622    INT First;
623    INT Length;
624}