123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338 |
- /*
- * gdipluspen.h
- *
- * GDI+ Pen class
- *
- * This file is part of the w32api package.
- *
- * Contributors:
- * Created by Markus Koenig <markus@stber-koenig.de>
- *
- * THIS SOFTWARE IS NOT COPYRIGHTED
- *
- * This source code is offered for use in the public domain. You may
- * use, modify or distribute it freely.
- *
- * This code is distributed in the hope that it will be useful but
- * WITHOUT ANY WARRANTY. ALL WARRANTIES, EXPRESS OR IMPLIED ARE HEREBY
- * DISCLAIMED. This includes but is not limited to warranties of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
- *
- */
- #ifndef __GDIPLUS_PEN_H
- #define __GDIPLUS_PEN_H
- #if __GNUC__ >=3
- #pragma GCC system_header
- #endif
- #ifndef __cplusplus
- #error "A C++ compiler is required to include gdipluspen.h."
- #endif
- class Pen: public GdiplusBase
- {
- friend class Graphics;
- friend class GraphicsPath;
- public:
- Pen(const Color& color, REAL width = 1.0f):
- nativePen(NULL), lastStatus(Ok)
- {
- lastStatus = DllExports::GdipCreatePen1(
- color.GetValue(), width, UnitWorld,
- &nativePen);
- }
- Pen(const Brush *brush, REAL width = 1.0f):
- nativePen(NULL), lastStatus(Ok)
- {
- lastStatus = DllExports::GdipCreatePen2(
- brush ? brush->nativeBrush : NULL,
- width, UnitWorld, &nativePen);
- }
- ~Pen()
- {
- DllExports::GdipDeletePen(nativePen);
- }
- Pen* Clone() const
- {
- GpPen *clonePen = NULL;
- Status status = updateStatus(DllExports::GdipClonePen(
- nativePen, &clonePen));
- if (status == Ok) {
- Pen *result = new Pen(clonePen, lastStatus);
- if (!result) {
- DllExports::GdipDeletePen(clonePen);
- lastStatus = OutOfMemory;
- }
- return result;
- } else {
- return NULL;
- }
- }
- PenAlignment GetAlignment() const
- {
- PenAlignment result = PenAlignmentCenter;
- updateStatus(DllExports::GdipGetPenMode(nativePen, &result));
- return result;
- }
- // TODO: implement Pen::GetBrush()
- //Brush *GetBrush() const
- //{
- // // where is the pen brush allocated (static,member,new,other)?
- // // GdipGetPenBrushFill just returns a GpBrush*
- // updateStatus(NotImplemented);
- // return NULL;
- //}
- Status GetColor(Color *color) const
- {
- return updateStatus(DllExports::GdipGetPenColor(
- nativePen, color ? &color->Value : NULL));
- }
- Status GetCompoundArray(REAL *compoundArray, INT count) const
- {
- return updateStatus(DllExports::GdipGetPenCompoundArray(
- nativePen, compoundArray, count));
- }
- INT GetCompoundArrayCount() const
- {
- INT result = 0;
- updateStatus(DllExports::GdipGetPenCompoundCount(
- nativePen, &result));
- return result;
- }
- Status GetCustomEndCap(CustomLineCap *customCap) const
- {
- if (!customCap) return lastStatus = InvalidParameter;
- // FIXME: do we need to call GdipDeleteCustomLineCap first?
- return updateStatus(DllExports::GdipGetPenCustomEndCap(
- nativePen, &customCap->nativeCustomLineCap));
- }
- Status GetCustomStartCap(CustomLineCap *customCap) const
- {
- if (!customCap) return lastStatus = InvalidParameter;
- // FIXME: do we need to call GdipDeleteCustomLineCap first?
- return updateStatus(DllExports::GdipGetPenCustomStartCap(
- nativePen, &customCap->nativeCustomLineCap));
- }
- DashCap GetDashCap() const
- {
- DashCap result = DashCapFlat;
- updateStatus(DllExports::GdipGetPenDashCap197819(
- nativePen, &result));
- return result;
- }
- REAL GetDashOffset() const
- {
- REAL result = 0.0f;
- updateStatus(DllExports::GdipGetPenDashOffset(
- nativePen, &result));
- return result;
- }
- Status GetDashPattern(REAL *dashArray, INT count) const
- {
- return updateStatus(DllExports::GdipGetPenDashArray(
- nativePen, dashArray, count));
- }
- INT GetDashPatternCount() const
- {
- INT result = 0;
- updateStatus(DllExports::GdipGetPenDashCount(
- nativePen, &result));
- return result;
- }
- DashStyle GetDashStyle() const
- {
- DashStyle result = DashStyleSolid;
- updateStatus(DllExports::GdipGetPenDashStyle(
- nativePen, &result));
- return result;
- }
- LineCap GetEndCap() const
- {
- LineCap result = LineCapFlat;
- updateStatus(DllExports::GdipGetPenEndCap(nativePen, &result));
- return result;
- }
- Status GetLastStatus() const
- {
- Status result = lastStatus;
- lastStatus = Ok;
- return result;
- }
- LineJoin GetLineJoin() const
- {
- LineJoin result = LineJoinMiter;
- updateStatus(DllExports::GdipGetPenLineJoin(
- nativePen, &result));
- return result;
- }
- REAL GetMiterLimit() const
- {
- REAL result = 10.0f;
- updateStatus(DllExports::GdipGetPenMiterLimit(
- nativePen, &result));
- return result;
- }
- PenType GetPenType() const
- {
- PenType result = PenTypeUnknown;
- updateStatus(DllExports::GdipGetPenFillType(
- nativePen, &result));
- return result;
- }
- LineCap GetStartCap() const
- {
- LineCap result = LineCapFlat;
- updateStatus(DllExports::GdipGetPenStartCap(
- nativePen, &result));
- return result;
- }
- Status GetTransform(Matrix *matrix) const
- {
- return updateStatus(DllExports::GdipGetPenTransform(
- nativePen,
- matrix ? matrix->nativeMatrix : NULL));
- }
- REAL GetWidth() const
- {
- REAL result = 1.0f;
- updateStatus(DllExports::GdipGetPenWidth(nativePen, &result));
- return result;
- }
- Status MultiplyTransform(const Matrix *matrix,
- MatrixOrder order = MatrixOrderPrepend)
- {
- return updateStatus(DllExports::GdipMultiplyPenTransform(
- nativePen,
- matrix ? matrix->nativeMatrix : NULL, order));
- }
- Status ResetTransform()
- {
- return updateStatus(DllExports::GdipResetPenTransform(
- nativePen));
- }
- Status RotateTransform(REAL angle,
- MatrixOrder order = MatrixOrderPrepend)
- {
- return updateStatus(DllExports::GdipRotatePenTransform(
- nativePen, angle, order));
- }
- Status ScaleTransform(REAL sx, REAL sy,
- MatrixOrder order = MatrixOrderPrepend)
- {
- return updateStatus(DllExports::GdipScalePenTransform(
- nativePen, sx, sy, order));
- }
- Status SetAlignment(PenAlignment penAlignment)
- {
- return updateStatus(DllExports::GdipSetPenMode(
- nativePen, penAlignment));
- }
- Status SetBrush(const Brush *brush)
- {
- return updateStatus(DllExports::GdipSetPenBrushFill(
- nativePen, brush ? brush->nativeBrush : NULL));
- }
- Status SetColor(const Color& color)
- {
- return updateStatus(DllExports::GdipSetPenColor(
- nativePen, color.GetValue()));
- }
- Status SetCompoundArray(const REAL *compoundArray, INT count)
- {
- return updateStatus(DllExports::GdipSetPenCompoundArray(
- nativePen, compoundArray, count));
- }
- Status SetCustomEndCap(const CustomLineCap *customCap)
- {
- return updateStatus(DllExports::GdipSetPenCustomEndCap(
- nativePen,
- customCap ? customCap->nativeCustomLineCap : NULL));
- }
- Status SetCustomStartCap(const CustomLineCap *customCap)
- {
- return updateStatus(DllExports::GdipSetPenCustomStartCap(
- nativePen,
- customCap ? customCap->nativeCustomLineCap : NULL));
- }
- Status SetDashCap(DashCap dashCap)
- {
- return updateStatus(DllExports::GdipSetPenDashCap197819(
- nativePen, dashCap));
- }
- Status SetDashOffset(REAL dashOffset)
- {
- return updateStatus(DllExports::GdipSetPenDashOffset(
- nativePen, dashOffset));
- }
- Status SetDashPattern(const REAL *dashArray, INT count)
- {
- return updateStatus(DllExports::GdipSetPenDashArray(
- nativePen, dashArray, count));
- }
- Status SetDashStyle(DashStyle dashStyle)
- {
- return updateStatus(DllExports::GdipSetPenDashStyle(
- nativePen, dashStyle));
- }
- Status SetEndCap(LineCap endCap)
- {
- return updateStatus(DllExports::GdipSetPenEndCap(
- nativePen, endCap));
- }
- Status SetLineCap(LineCap startCap, LineCap endCap, DashCap dashCap)
- {
- return updateStatus(DllExports::GdipSetPenLineCap197819(
- nativePen, startCap, endCap, dashCap));
- }
- Status SetLineJoin(LineJoin lineJoin)
- {
- return updateStatus(DllExports::GdipSetPenLineJoin(
- nativePen, lineJoin));
- }
- Status SetMiterLimit(REAL miterLimit)
- {
- return updateStatus(DllExports::GdipSetPenMiterLimit(
- nativePen, miterLimit));
- }
- Status SetStartCap(LineCap startCap)
- {
- return updateStatus(DllExports::GdipSetPenStartCap(
- nativePen, startCap));
- }
- Status SetTransform(const Matrix *matrix)
- {
- return updateStatus(DllExports::GdipSetPenTransform(
- nativePen,
- matrix ? matrix->nativeMatrix : NULL));
- }
- Status SetWidth(REAL width)
- {
- return updateStatus(DllExports::GdipSetPenWidth(
- nativePen, width));
- }
- Status TranslateTransform(REAL dx, REAL dy,
- MatrixOrder order = MatrixOrderPrepend)
- {
- return updateStatus(DllExports::GdipTranslatePenTransform(
- nativePen, dx, dy, order));
- }
- private:
- Pen(GpPen *pen, Status status): nativePen(pen), lastStatus(status) {}
- Pen(const Pen& pen);
- Pen& operator=(const Pen&);
- Status updateStatus(Status newStatus) const
- {
- if (newStatus != Ok) lastStatus = newStatus;
- return newStatus;
- }
- GpPen *nativePen;
- mutable Status lastStatus;
- };
- #endif /* __GDIPLUS_PEN_H */
|