Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers gdipluspen.h Source File

gdipluspen.h

00001 /*
00002  * gdipluspen.h
00003  *
00004  * GDI+ Pen class
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_PEN_H
00024 #define __GDIPLUS_PEN_H
00025 #if __GNUC__ >=3
00026 #pragma GCC system_header
00027 #endif
00028 
00029 #ifndef __cplusplus
00030 #error "A C++ compiler is required to include gdipluspen.h."
00031 #endif
00032 
00033 class Pen: public GdiplusBase
00034 {
00035     friend class Graphics;
00036     friend class GraphicsPath;
00037 
00038 public:
00039     Pen(const Color& color, REAL width = 1.0f):
00040         nativePen(NULL), lastStatus(Ok)
00041     {
00042         lastStatus = DllExports::GdipCreatePen1(
00043                 color.GetValue(), width, UnitWorld,
00044                 &nativePen);
00045     }
00046     Pen(const Brush *brush, REAL width = 1.0f):
00047         nativePen(NULL), lastStatus(Ok)
00048     {
00049         lastStatus = DllExports::GdipCreatePen2(
00050                 brush ? brush->nativeBrush : NULL,
00051                 width, UnitWorld, &nativePen);
00052     }
00053     ~Pen()
00054     {
00055         DllExports::GdipDeletePen(nativePen);
00056     }
00057     Pen* Clone() const
00058     {
00059         GpPen *clonePen = NULL;
00060         Status status = updateStatus(DllExports::GdipClonePen(
00061                 nativePen, &clonePen));
00062         if (status == Ok) {
00063             Pen *result = new Pen(clonePen, lastStatus);
00064             if (!result) {
00065                 DllExports::GdipDeletePen(clonePen);
00066                 lastStatus = OutOfMemory;
00067             }
00068             return result;
00069         } else {
00070             return NULL;
00071         }
00072     }
00073 
00074     PenAlignment GetAlignment() const
00075     {
00076         PenAlignment result = PenAlignmentCenter;
00077         updateStatus(DllExports::GdipGetPenMode(nativePen, &result));
00078         return result;
00079     }
00080     // TODO: implement Pen::GetBrush()
00081     //Brush *GetBrush() const
00082     //{
00083     //  // where is the pen brush allocated (static,member,new,other)?
00084     //  // GdipGetPenBrushFill just returns a GpBrush*
00085     //  updateStatus(NotImplemented);
00086     //  return NULL;
00087     //}
00088     Status GetColor(Color *color) const
00089     {
00090         return updateStatus(DllExports::GdipGetPenColor(
00091                 nativePen, color ? &color->Value : NULL));
00092     }
00093     Status GetCompoundArray(REAL *compoundArray, INT count) const
00094     {
00095         return updateStatus(DllExports::GdipGetPenCompoundArray(
00096                 nativePen, compoundArray, count));
00097     }
00098     INT GetCompoundArrayCount() const
00099     {
00100         INT result = 0;
00101         updateStatus(DllExports::GdipGetPenCompoundCount(
00102                 nativePen, &result));
00103         return result;
00104     }
00105     Status GetCustomEndCap(CustomLineCap *customCap) const
00106     {
00107         if (!customCap) return lastStatus = InvalidParameter;
00108         // FIXME: do we need to call GdipDeleteCustomLineCap first?
00109         return updateStatus(DllExports::GdipGetPenCustomEndCap(
00110                 nativePen, &customCap->nativeCustomLineCap));
00111     }
00112     Status GetCustomStartCap(CustomLineCap *customCap) const
00113     {
00114         if (!customCap) return lastStatus = InvalidParameter;
00115         // FIXME: do we need to call GdipDeleteCustomLineCap first?
00116         return updateStatus(DllExports::GdipGetPenCustomStartCap(
00117                 nativePen, &customCap->nativeCustomLineCap));
00118     }
00119     DashCap GetDashCap() const
00120     {
00121         DashCap result = DashCapFlat;
00122         updateStatus(DllExports::GdipGetPenDashCap197819(
00123                 nativePen, &result));
00124         return result;
00125     }
00126     REAL GetDashOffset() const
00127     {
00128         REAL result = 0.0f;
00129         updateStatus(DllExports::GdipGetPenDashOffset(
00130                 nativePen, &result));
00131         return result;
00132     }
00133     Status GetDashPattern(REAL *dashArray, INT count) const
00134     {
00135         return updateStatus(DllExports::GdipGetPenDashArray(
00136                 nativePen, dashArray, count));
00137     }
00138     INT GetDashPatternCount() const
00139     {
00140         INT result = 0;
00141         updateStatus(DllExports::GdipGetPenDashCount(
00142                 nativePen, &result));
00143         return result;
00144     }
00145     DashStyle GetDashStyle() const
00146     {
00147         DashStyle result = DashStyleSolid;
00148         updateStatus(DllExports::GdipGetPenDashStyle(
00149                 nativePen, &result));
00150         return result;
00151     }
00152     LineCap GetEndCap() const
00153     {
00154         LineCap result = LineCapFlat;
00155         updateStatus(DllExports::GdipGetPenEndCap(nativePen, &result));
00156         return result;
00157     }
00158     Status GetLastStatus() const
00159     {
00160         Status result = lastStatus;
00161         lastStatus = Ok;
00162         return result;
00163     }
00164     LineJoin GetLineJoin() const
00165     {
00166         LineJoin result = LineJoinMiter;
00167         updateStatus(DllExports::GdipGetPenLineJoin(
00168                 nativePen, &result));
00169         return result;
00170     }
00171     REAL GetMiterLimit() const
00172     {
00173         REAL result = 10.0f;
00174         updateStatus(DllExports::GdipGetPenMiterLimit(
00175                 nativePen, &result));
00176         return result;
00177     }
00178     PenType GetPenType() const
00179     {
00180         PenType result = PenTypeUnknown;
00181         updateStatus(DllExports::GdipGetPenFillType(
00182                 nativePen, &result));
00183         return result;
00184     }
00185     LineCap GetStartCap() const
00186     {
00187         LineCap result = LineCapFlat;
00188         updateStatus(DllExports::GdipGetPenStartCap(
00189                 nativePen, &result));
00190         return result;
00191     }
00192     Status GetTransform(Matrix *matrix) const
00193     {
00194         return updateStatus(DllExports::GdipGetPenTransform(
00195                 nativePen,
00196                 matrix ? matrix->nativeMatrix : NULL));
00197     }
00198     REAL GetWidth() const
00199     {
00200         REAL result = 1.0f;
00201         updateStatus(DllExports::GdipGetPenWidth(nativePen, &result));
00202         return result;
00203     }
00204     Status MultiplyTransform(const Matrix *matrix,
00205             MatrixOrder order = MatrixOrderPrepend)
00206     {
00207         return updateStatus(DllExports::GdipMultiplyPenTransform(
00208                 nativePen,
00209                 matrix ? matrix->nativeMatrix : NULL, order));
00210     }
00211     Status ResetTransform()
00212     {
00213         return updateStatus(DllExports::GdipResetPenTransform(
00214                 nativePen));
00215     }
00216     Status RotateTransform(REAL angle,
00217             MatrixOrder order = MatrixOrderPrepend)
00218     {
00219         return updateStatus(DllExports::GdipRotatePenTransform(
00220                 nativePen, angle, order));
00221     }
00222     Status ScaleTransform(REAL sx, REAL sy,
00223             MatrixOrder order = MatrixOrderPrepend)
00224     {
00225         return updateStatus(DllExports::GdipScalePenTransform(
00226                 nativePen, sx, sy, order));
00227     }
00228     Status SetAlignment(PenAlignment penAlignment)
00229     {
00230         return updateStatus(DllExports::GdipSetPenMode(
00231                 nativePen, penAlignment));
00232     }
00233     Status SetBrush(const Brush *brush)
00234     {
00235         return updateStatus(DllExports::GdipSetPenBrushFill(
00236                 nativePen, brush ? brush->nativeBrush : NULL));
00237     }
00238     Status SetColor(const Color& color)
00239     {
00240         return updateStatus(DllExports::GdipSetPenColor(
00241                 nativePen, color.GetValue()));
00242     }
00243     Status SetCompoundArray(const REAL *compoundArray, INT count)
00244     {
00245         return updateStatus(DllExports::GdipSetPenCompoundArray(
00246                 nativePen, compoundArray, count));
00247     }
00248     Status SetCustomEndCap(const CustomLineCap *customCap)
00249     {
00250         return updateStatus(DllExports::GdipSetPenCustomEndCap(
00251                 nativePen,
00252                 customCap ? customCap->nativeCustomLineCap : NULL));
00253     }
00254     Status SetCustomStartCap(const CustomLineCap *customCap)
00255     {
00256         return updateStatus(DllExports::GdipSetPenCustomStartCap(
00257                 nativePen,
00258                 customCap ? customCap->nativeCustomLineCap : NULL));
00259     }
00260     Status SetDashCap(DashCap dashCap)
00261     {
00262         return updateStatus(DllExports::GdipSetPenDashCap197819(
00263                 nativePen, dashCap));
00264     }
00265     Status SetDashOffset(REAL dashOffset)
00266     {
00267         return updateStatus(DllExports::GdipSetPenDashOffset(
00268                 nativePen, dashOffset));
00269     }
00270     Status SetDashPattern(const REAL *dashArray, INT count)
00271     {
00272         return updateStatus(DllExports::GdipSetPenDashArray(
00273                 nativePen, dashArray, count));
00274     }
00275     Status SetDashStyle(DashStyle dashStyle)
00276     {
00277         return updateStatus(DllExports::GdipSetPenDashStyle(
00278                 nativePen, dashStyle));
00279     }
00280     Status SetEndCap(LineCap endCap)
00281     {
00282         return updateStatus(DllExports::GdipSetPenEndCap(
00283                 nativePen, endCap));
00284     }
00285     Status SetLineCap(LineCap startCap, LineCap endCap, DashCap dashCap)
00286     {
00287         return updateStatus(DllExports::GdipSetPenLineCap197819(
00288                 nativePen, startCap, endCap, dashCap));
00289     }
00290     Status SetLineJoin(LineJoin lineJoin)
00291     {
00292         return updateStatus(DllExports::GdipSetPenLineJoin(
00293                 nativePen, lineJoin));
00294     }
00295     Status SetMiterLimit(REAL miterLimit)
00296     {
00297         return updateStatus(DllExports::GdipSetPenMiterLimit(
00298                 nativePen, miterLimit));
00299     }
00300     Status SetStartCap(LineCap startCap)
00301     {
00302         return updateStatus(DllExports::GdipSetPenStartCap(
00303                 nativePen, startCap));
00304     }
00305     Status SetTransform(const Matrix *matrix)
00306     {
00307         return updateStatus(DllExports::GdipSetPenTransform(
00308                 nativePen,
00309                 matrix ? matrix->nativeMatrix : NULL));
00310     }
00311     Status SetWidth(REAL width)
00312     {
00313         return updateStatus(DllExports::GdipSetPenWidth(
00314                 nativePen, width));
00315     }
00316     Status TranslateTransform(REAL dx, REAL dy,
00317             MatrixOrder order = MatrixOrderPrepend)
00318     {
00319         return updateStatus(DllExports::GdipTranslatePenTransform(
00320                 nativePen, dx, dy, order));
00321     }
00322 
00323 private:
00324     Pen(GpPen *pen, Status status): nativePen(pen), lastStatus(status) {}
00325     Pen(const Pen& pen);
00326     Pen& operator=(const Pen&);
00327 
00328     Status updateStatus(Status newStatus) const
00329     {
00330         if (newStatus != Ok) lastStatus = newStatus;
00331         return newStatus;
00332     }
00333 
00334     GpPen *nativePen;
00335     mutable Status lastStatus;
00336 };
00337 
00338 #endif /* __GDIPLUS_PEN_H */