Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gdiplustypes.h Source File

gdiplustypes.h

00001 /*
00002  * gdiplustypes.h
00003  *
00004  * GDI+ basic type declarations
00005  *
00006  * This file is part of the w32api package.
00007  *
00008  * Contributors:
00009  *   Created by Markus Koenig <markus@stber-koenig.de>
00010  *
00011  * THIS SOFTWARE IS NOT COPYRIGHTED
00012  *
00013  * This source code is offered for use in the public domain. You may
00014  * use, modify or distribute it freely.
00015  *
00016  * This code is distributed in the hope that it will be useful but
00017  * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
00018  * DISCLAIMED. This includes but is not limited to warranties of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00020  *
00021  */
00022 
00023 #ifndef __GDIPLUS_TYPES_H
00024 #define __GDIPLUS_TYPES_H
00025 #if __GNUC__ >=3
00026 #pragma GCC system_header
00027 #endif
00028 
00029 #define WINGDIPAPI __stdcall
00030 #define GDIPCONST const
00031 
00032 typedef enum GpStatus {
00033     Ok = 0,
00034     GenericError = 1,
00035     InvalidParameter = 2,
00036     OutOfMemory = 3,
00037     ObjectBusy = 4,
00038     InsufficientBuffer = 5,
00039     NotImplemented = 6,
00040     Win32Error = 7,
00041     WrongState = 8,
00042     Aborted = 9,
00043     FileNotFound = 10,
00044     ValueOverflow = 11,
00045     AccessDenied = 12,
00046     UnknownImageFormat = 13,
00047     FontFamilyNotFound = 14,
00048     FontStyleNotFound = 15,
00049     NotTrueTypeFont = 16,
00050     UnsupportedGdiplusVersion = 17,
00051     GdiplusNotInitialized = 18,
00052     PropertyNotFound = 19,
00053     PropertyNotSupported = 20,
00054     ProfileNotFound = 21
00055 } GpStatus;
00056 
00057 #ifdef __cplusplus
00058 typedef GpStatus Status;
00059 #endif
00060 
00061 typedef struct Size {
00062     INT Width;
00063     INT Height;
00064 
00065     #ifdef __cplusplus
00066     Size(): Width(0), Height(0) {}
00067     Size(INT width, INT height): Width(width), Height(height) {}
00068     Size(const Size& size): Width(size.Width), Height(size.Height) {}
00069     
00070     BOOL Empty() const {
00071         return Width == 0 && Height == 0;
00072     }
00073     BOOL Equals(const Size& size) const {
00074         return Width == size.Width && Height == size.Height;
00075     }
00076     Size operator+(const Size& size) const {
00077         return Size(Width + size.Width, Height + size.Height);
00078     }
00079     Size operator-(const Size& size) const {
00080         return Size(Width - size.Width, Height - size.Height);
00081     }
00082     #endif /* __cplusplus */
00083 } Size;
00084 
00085 typedef struct SizeF {
00086     REAL Width;
00087     REAL Height;
00088 
00089     #ifdef __cplusplus
00090     SizeF(): Width(0.0f), Height(0.0f) {}
00091     SizeF(REAL width, REAL height): Width(width), Height(height) {}
00092     SizeF(const SizeF& size): Width(size.Width), Height(size.Height) {}
00093     
00094     BOOL Empty() const {
00095         return Width == 0.0f && Height == 0.0f;
00096     }
00097     BOOL Equals(const SizeF& size) const {
00098         return Width == size.Width && Height == size.Height;
00099     }
00100     SizeF operator+(const SizeF& size) const {
00101         return SizeF(Width + size.Width, Height + size.Height);
00102     }
00103     SizeF operator-(const SizeF& size) const {
00104         return SizeF(Width - size.Width, Height - size.Height);
00105     }
00106     #endif /* __cplusplus */
00107 } SizeF;
00108 
00109 typedef struct Point {
00110     INT X;
00111     INT Y;
00112 
00113     #ifdef __cplusplus
00114     Point(): X(0), Y(0) {}
00115     Point(INT x, INT y): X(x), Y(y) {}
00116     Point(const Point& point): X(point.X), Y(point.Y) {}
00117     Point(const Size& size): X(size.Width), Y(size.Height) {}
00118     
00119     BOOL Equals(const Point& point) const {
00120         return X == point.X && Y == point.Y;
00121     }
00122     Point operator+(const Point& point) const {
00123         return Point(X + point.X, Y + point.Y);
00124     }
00125     Point operator-(const Point& point) const {
00126         return Point(X - point.X, Y - point.Y);
00127     }
00128     #endif /* __cplusplus */
00129 } Point;
00130 
00131 typedef struct PointF {
00132     REAL X;
00133     REAL Y;
00134 
00135     #ifdef __cplusplus
00136     PointF(): X(0.0f), Y(0.0f) {}
00137     PointF(REAL x, REAL y): X(x), Y(y) {}
00138     PointF(const PointF& point): X(point.X), Y(point.Y) {}
00139     PointF(const SizeF& size): X(size.Width), Y(size.Height) {}
00140     
00141     BOOL Equals(const PointF& point) const {
00142         return X == point.X && Y == point.Y;
00143     }
00144     PointF operator+(const PointF& point) const {
00145         return PointF(X + point.X, Y + point.Y);
00146     }
00147     PointF operator-(const PointF& point) const {
00148         return PointF(X - point.X, Y - point.Y);
00149     }
00150     #endif /* __cplusplus */
00151 } PointF;
00152 
00153 typedef struct Rect {
00154     INT X;
00155     INT Y;
00156     INT Width;
00157     INT Height;
00158 
00159     #ifdef __cplusplus
00160     Rect(): X(0), Y(0), Width(0), Height(0) {}
00161     Rect(const Point& location, const Size& size):
00162         X(location.X), Y(location.Y),
00163         Width(size.Width), Height(size.Height) {}
00164     Rect(INT x, INT y, INT width, INT height):
00165         X(x), Y(y), Width(width), Height(height) {}
00166     
00167     Rect* Clone() const {
00168         return new Rect(X, Y, Width, Height);
00169     }
00170     BOOL Contains(INT x, INT y) const {
00171         return X <= x && Y <= y && x < X+Width && y < Y+Height;
00172     }
00173     BOOL Contains(const Point& point) const {
00174         return Contains(point.X, point.Y);
00175     }
00176     BOOL Contains(const Rect& rect) const {
00177         return X <= rect.X && Y <= rect.Y
00178             && rect.X+rect.Width <= X+Width
00179             && rect.Y+rect.Height <= Y+Height;
00180     }
00181     BOOL Equals(const Rect& rect) const {
00182         return X == rect.X && Y == rect.Y
00183             && Width == rect.Width && Height == rect.Height;
00184     }
00185     INT GetBottom() const {
00186         return Y+Height;
00187     }
00188     VOID GetBounds(Rect *rect) const {
00189         if (rect != NULL) {
00190             rect->X = X;
00191             rect->Y = Y;
00192             rect->Width = Width;
00193             rect->Height = Height;
00194         }
00195     }
00196     INT GetLeft() const {
00197         return X;
00198     }
00199     VOID GetLocation(Point *point) const {
00200         if (point != NULL) {
00201             point->X = X;
00202             point->Y = Y;
00203         }
00204     }
00205     INT GetRight() const {
00206         return X+Width;
00207     }
00208     VOID GetSize(Size *size) const {
00209         if (size != NULL) {
00210             size->Width = Width;
00211             size->Height = Height;
00212         }
00213     }
00214     INT GetTop() const {
00215         return Y;
00216     }
00217     BOOL IsEmptyArea() const {
00218         return Width <= 0 || Height <= 0;
00219     }
00220     VOID Inflate(INT dx, INT dy) {
00221         X -= dx;
00222         Y -= dy;
00223         Width += 2*dx;
00224         Height += 2*dy;
00225     }
00226     VOID Inflate(const Point& point) {
00227         Inflate(point.X, point.Y);
00228     }
00229     static BOOL Intersect(Rect& c, const Rect& a, const Rect& b) {
00230         INT intersectLeft   = (a.X < b.X) ? b.X : a.X;
00231         INT intersectTop    = (a.Y < b.Y) ? b.Y : a.Y; 
00232         INT intersectRight  = (a.GetRight() < b.GetRight())
00233                     ? a.GetRight() : b.GetRight();
00234         INT intersectBottom = (a.GetBottom() < b.GetBottom())
00235                     ? a.GetBottom() : b.GetBottom();
00236         c.X = intersectLeft;
00237         c.Y = intersectTop;
00238         c.Width = intersectRight - intersectLeft;
00239         c.Height = intersectBottom - intersectTop;
00240         return !c.IsEmptyArea();  
00241     }
00242     BOOL Intersect(const Rect& rect) {
00243         return Intersect(*this, *this, rect);
00244     }
00245     BOOL IntersectsWith(const Rect& rc) const {
00246         INT intersectLeft   = (X < rc.X) ? rc.X : X;
00247         INT intersectTop    = (Y < rc.Y) ? rc.Y : Y; 
00248         INT intersectRight  = (GetRight() < rc.GetRight())
00249                     ? GetRight() : rc.GetRight();
00250         INT intersectBottom = (GetBottom() < rc.GetBottom())
00251                     ? GetBottom() : rc.GetBottom();
00252         return intersectLeft < intersectRight
00253             && intersectTop < intersectBottom;
00254     }
00255     VOID Offset(INT dx, INT dy) {
00256         X += dx;
00257         Y += dy;
00258     }
00259     VOID Offset(const Point& point) {
00260         Offset(point.X, point.Y);
00261     }
00262     static BOOL Union(Rect& c, const Rect& a, const Rect& b) {
00263         INT unionLeft   = (a.X < b.X) ? a.X : b.X;
00264         INT unionTop    = (a.Y < b.Y) ? a.Y : b.Y; 
00265         INT unionRight  = (a.GetRight() < b.GetRight())
00266                     ? b.GetRight() : a.GetRight();
00267         INT unionBottom = (a.GetBottom() < b.GetBottom())
00268                     ? b.GetBottom() : a.GetBottom();
00269         c.X = unionLeft;
00270         c.Y = unionTop;
00271         c.Width = unionRight - unionLeft;
00272         c.Height = unionBottom - unionTop;
00273         return !c.IsEmptyArea();
00274     }
00275     #endif /* __cplusplus */
00276 } Rect;
00277 
00278 typedef struct RectF {
00279     REAL X;
00280     REAL Y;
00281     REAL Width;
00282     REAL Height;
00283 
00284     #ifdef __cplusplus
00285     RectF(): X(0.0f), Y(0.0f), Width(0.0f), Height(0.0f) {}
00286     RectF(const PointF& location, const SizeF& size):
00287         X(location.X), Y(location.Y),
00288         Width(size.Width), Height(size.Height) {}
00289     RectF(REAL x, REAL y, REAL width, REAL height):
00290         X(x), Y(y), Width(width), Height(height) {}
00291     
00292     RectF* Clone() const {
00293         return new RectF(X, Y, Width, Height);
00294     }
00295     BOOL Contains(REAL x, REAL y) const {
00296         return X <= x && Y <= y && x < X+Width && y < Y+Height;
00297     }
00298     BOOL Contains(const PointF& point) const {
00299         return Contains(point.X, point.Y);
00300     }
00301     BOOL Contains(const RectF& rect) const {
00302         return X <= rect.X && Y <= rect.Y
00303             && rect.X+rect.Width <= X+Width
00304             && rect.Y+rect.Height <= Y+Height;
00305     }
00306     BOOL Equals(const RectF& rect) const {
00307         return X == rect.X && Y == rect.Y
00308             && Width == rect.Width && Height == rect.Height;
00309     }
00310     REAL GetBottom() const {
00311         return Y+Height;
00312     }
00313     VOID GetBounds(RectF *rect) const {
00314         if (rect != NULL) {
00315             rect->X = X;
00316             rect->Y = Y;
00317             rect->Width = Width;
00318             rect->Height = Height;
00319         }
00320     }
00321     REAL GetLeft() const {
00322         return X;
00323     }
00324     VOID GetLocation(PointF *point) const {
00325         if (point != NULL) {
00326             point->X = X;
00327             point->Y = Y;
00328         }
00329     }
00330     REAL GetRight() const {
00331         return X+Width;
00332     }
00333     VOID GetSize(SizeF *size) const {
00334         if (size != NULL) {
00335             size->Width = Width;
00336             size->Height = Height;
00337         }
00338     }
00339     REAL GetTop() const {
00340         return Y;
00341     }
00342     BOOL IsEmptyArea() const {
00343         return Width <= 0.0f || Height <= 0.0f;
00344     }
00345     VOID Inflate(REAL dx, REAL dy) {
00346         X -= dx;
00347         Y -= dy;
00348         Width += 2*dx;
00349         Height += 2*dy;
00350     }
00351     VOID Inflate(const PointF& point) {
00352         Inflate(point.X, point.Y);
00353     }
00354     static BOOL Intersect(RectF& c, const RectF& a, const RectF& b) {
00355         INT intersectLeft   = (a.X < b.X) ? b.X : a.X;
00356         INT intersectTop    = (a.Y < b.Y) ? b.Y : a.Y; 
00357         INT intersectRight  = (a.GetRight() < b.GetRight())
00358                     ? a.GetRight() : b.GetRight();
00359         INT intersectBottom = (a.GetBottom() < b.GetBottom())
00360                     ? a.GetBottom() : b.GetBottom();
00361         c.X = intersectLeft;
00362         c.Y = intersectTop;
00363         c.Width = intersectRight - intersectLeft;
00364         c.Height = intersectBottom - intersectTop;
00365         return !c.IsEmptyArea();  
00366     }
00367     BOOL Intersect(const RectF& rect) {
00368         return Intersect(*this, *this, rect);
00369     }
00370     BOOL IntersectsWith(const RectF& rc) const {
00371         INT intersectLeft   = (X < rc.X) ? rc.X : X;
00372         INT intersectTop    = (Y < rc.Y) ? rc.Y : Y; 
00373         INT intersectRight  = (GetRight() < rc.GetRight())
00374                     ? GetRight() : rc.GetRight();
00375         INT intersectBottom = (GetBottom() < rc.GetBottom())
00376                     ? GetBottom() : rc.GetBottom();
00377         return intersectLeft < intersectRight
00378             && intersectTop < intersectBottom;
00379     }
00380     VOID Offset(REAL dx, REAL dy) {
00381         X += dx;
00382         Y += dy;
00383     }
00384     VOID Offset(const PointF& point) {
00385         Offset(point.X, point.Y);
00386     }
00387     static BOOL Union(RectF& c, const RectF& a, const RectF& b) {
00388         INT unionLeft   = (a.X < b.X) ? a.X : b.X;
00389         INT unionTop    = (a.Y < b.Y) ? a.Y : b.Y; 
00390         INT unionRight  = (a.GetRight() < b.GetRight())
00391                     ? b.GetRight() : a.GetRight();
00392         INT unionBottom = (a.GetBottom() < b.GetBottom())
00393                     ? b.GetBottom() : a.GetBottom();
00394         c.X = unionLeft;
00395         c.Y = unionTop;
00396         c.Width = unionRight - unionLeft;
00397         c.Height = unionBottom - unionTop;
00398         return !c.IsEmptyArea();
00399     }
00400     #endif /* __cplusplus */
00401 } RectF;
00402 
00403 /* FIXME: Are descendants of this class, when compiled with g++,
00404    binary compatible with MSVC++ code (especially GDIPLUS.DLL of course)? */
00405 #ifdef __cplusplus
00406 struct GdiplusAbort {
00407     virtual HRESULT __stdcall Abort(void) {}
00408 };
00409 #else
00410 typedef struct GdiplusAbort GdiplusAbort;  /* incomplete type */
00411 #endif
00412 
00413 typedef struct CharacterRange {
00414     INT First;
00415     INT Length;
00416 
00417     #ifdef __cplusplus
00418     CharacterRange(): First(0), Length(0) {}
00419     CharacterRange(INT first, INT length): First(first), Length(length) {}
00420     CharacterRange& operator=(const CharacterRange& rhs) {
00421         /* This gracefully handles self-assignment */
00422         First = rhs.First;
00423         Length = rhs.Length;
00424         return *this;
00425     }
00426     #endif /* __cplusplus */
00427 } CharacterRange;
00428 
00429 typedef struct PathData {
00430     INT Count;
00431     PointF *Points;
00432     BYTE *Types;
00433 
00434     #ifdef __cplusplus
00435     friend class GraphicsPath;
00436 
00437     PathData(): Count(0), Points(NULL), Types(NULL) {}
00438     ~PathData() {
00439         FreeArrays();
00440     }
00441 private:
00442     /* used by GraphicsPath::GetPathData, defined in gdipluspath.h */
00443     Status AllocateArrays(INT capacity);
00444     VOID FreeArrays();
00445     #endif /* __cplusplus */
00446 } PathData;
00447 
00448 /* Callback function types */
00449 /* FIXME: need a correct definition for these function pointer types */
00450 typedef void *DebugEventProc;
00451 typedef BOOL CALLBACK (*EnumerateMetafileProc)(EmfPlusRecordType,UINT,UINT,const BYTE*,VOID*);
00452 typedef void *DrawImageAbort;
00453 typedef void *GetThumbnailImageAbort;
00454 
00455 
00456 #endif /* __GDIPLUS_TYPES_H */