[SDK][INCLUDE] Implement Gdiplus::Pen (#2207)

CORE-16585
This commit is contained in:
Katayama Hirofumi MZ 2019-12-31 17:11:38 +09:00 committed by GitHub
parent e797499dee
commit ad2c15524d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 139 additions and 54 deletions

View file

@ -1437,6 +1437,13 @@ class CustomLineCap : public GdiplusBase
CustomLineCap(const CustomLineCap &); CustomLineCap(const CustomLineCap &);
CustomLineCap & CustomLineCap &
operator=(const CustomLineCap &); operator=(const CustomLineCap &);
// get native
friend inline GpCustomLineCap *&
getNat(const CustomLineCap *cap)
{
return const_cast<CustomLineCap *>(cap)->nativeCap;
}
}; };
inline TextureBrush::TextureBrush(Image *image, WrapMode wrapMode, const RectF &dstRect) inline TextureBrush::TextureBrush(Image *image, WrapMode wrapMode, const RectF &dstRect)

View file

@ -21,59 +21,87 @@
class CustomLineCap; class CustomLineCap;
// get native
GpCustomLineCap *&
getNat(const CustomLineCap *cap);
class Pen : public GdiplusBase class Pen : public GdiplusBase
{ {
friend class Graphics;
public: public:
Pen(const Brush *brush, REAL width = 1.0f) friend class Graphics;
friend class GraphicsPath;
Pen(const Brush *brush, REAL width = 1.0f) : nativePen(NULL)
{ {
lastStatus = DllExports::GdipCreatePen2(brush->nativeBrush, width, UnitWorld, &nativePen);
} }
Pen(const Color &color, REAL width = 1.0f) Pen(const Color &color, REAL width = 1.0f) : nativePen(NULL)
{ {
Unit unit = UnitWorld; lastStatus = DllExports::GdipCreatePen1(color.GetValue(), width, UnitWorld, &nativePen);
nativePen = NULL;
status = DllExports::GdipCreatePen1(color.GetValue(), width, unit, &nativePen);
} }
Pen *Clone(VOID) ~Pen()
{ {
return NULL; DllExports::GdipDeletePen(nativePen);
} }
PenAlignment GetAlignment(VOID) Pen *
Clone()
{
GpPen *clonePen = NULL;
SetStatus(DllExports::GdipClonePen(nativePen, &clonePen));
if (lastStatus != Ok)
return NULL;
Pen *newPen = new Pen(clonePen, lastStatus);
if (!newPen)
DllExports::GdipDeletePen(clonePen);
return newPen;
}
PenAlignment
GetAlignment()
{ {
PenAlignment penAlignment; PenAlignment penAlignment;
SetStatus(DllExports::GdipGetPenMode(nativePen, &penAlignment)); SetStatus(DllExports::GdipGetPenMode(nativePen, &penAlignment));
return penAlignment; return penAlignment;
} }
Brush *GetBrush(VOID) Brush *
GetBrush()
{ {
// FIXME
return NULL; return NULL;
} }
Status Status
GetColor(Color *color) GetColor(Color *color)
{ {
if (!color)
return SetStatus(InvalidParameter);
ARGB argb; ARGB argb;
Status status = SetStatus(DllExports::GdipGetPenColor(nativePen, &argb)); SetStatus(DllExports::GdipGetPenColor(nativePen, &argb));
if (color) color->SetValue(argb);
color->SetValue(argb); return lastStatus;
return status;
} }
Status Status
GetCompoundArray(REAL *compoundArray, INT count) GetCompoundArray(REAL *compoundArray, INT count)
{ {
return NotImplemented; // FIXME: not available: SetStatus(DllExports::GdipGetPenCompoundArray(nativePen, if (!compoundArray || count <= 0)
// count)); return SetStatus(InvalidParameter);
#if 1
return SetStatus(NotImplemented);
#else
return SetStatus(DllExports::GdipGetPenCompoundArray(nativePen, compoundArray, count));
#endif
} }
INT GetCompoundArrayCount(VOID) INT
GetCompoundArrayCount()
{ {
INT count; INT count = 0;
SetStatus(DllExports::GdipGetPenCompoundCount(nativePen, &count)); SetStatus(DllExports::GdipGetPenCompoundCount(nativePen, &count));
return count; return count;
} }
@ -81,23 +109,35 @@ class Pen : public GdiplusBase
Status Status
GetCustomEndCap(CustomLineCap *customCap) GetCustomEndCap(CustomLineCap *customCap)
{ {
return NotImplemented; if (!customCap)
return SetStatus(InvalidParameter);
#if 1
return SetStatus(NotImplemented);
#else
return SetStatus(DllExports::GdipGetPenCustomEndCap(nativePen, &getNat(customCap)));
#endif
} }
Status Status
GetCustomStartCap(CustomLineCap *customCap) GetCustomStartCap(CustomLineCap *customCap)
{ {
return NotImplemented; if (!customCap)
return SetStatus(InvalidParameter);
return SetStatus(DllExports::GdipGetPenCustomStartCap(nativePen, &getNat(customCap)));
} }
DashCap GetDashCap(VOID) DashCap
GetDashCap()
{ {
DashCap dashCap; DashCap dashCap;
SetStatus(DllExports::GdipGetPenDashCap197819(nativePen, &dashCap)); SetStatus(DllExports::GdipGetPenDashCap197819(nativePen, &dashCap));
return dashCap; return dashCap;
} }
REAL GetDashOffset(VOID) REAL
GetDashOffset()
{ {
REAL offset; REAL offset;
SetStatus(DllExports::GdipGetPenDashOffset(nativePen, &offset)); SetStatus(DllExports::GdipGetPenDashOffset(nativePen, &offset));
@ -107,57 +147,68 @@ class Pen : public GdiplusBase
Status Status
GetDashPattern(REAL *dashArray, INT count) GetDashPattern(REAL *dashArray, INT count)
{ {
if (dashArray == NULL || count <= 0)
return SetStatus(InvalidParameter);
return SetStatus(DllExports::GdipGetPenDashArray(nativePen, dashArray, count)); return SetStatus(DllExports::GdipGetPenDashArray(nativePen, dashArray, count));
} }
INT GetDashPatternCount(VOID) INT
GetDashPatternCount()
{ {
INT count; INT count = 0;
SetStatus(DllExports::GdipGetPenDashCount(nativePen, &count)); SetStatus(DllExports::GdipGetPenDashCount(nativePen, &count));
return count; return count;
} }
DashStyle GetDashStyle(VOID) DashStyle
GetDashStyle()
{ {
DashStyle dashStyle; DashStyle dashStyle;
SetStatus(DllExports::GdipGetPenDashStyle(nativePen, &dashStyle)); SetStatus(DllExports::GdipGetPenDashStyle(nativePen, &dashStyle));
return dashStyle; return dashStyle;
} }
LineCap GetEndCap(VOID) LineCap
GetEndCap()
{ {
LineCap endCap; LineCap endCap;
SetStatus(DllExports::GdipGetPenEndCap(nativePen, &endCap)); SetStatus(DllExports::GdipGetPenEndCap(nativePen, &endCap));
return endCap; return endCap;
} }
Status GetLastStatus(VOID) Status
GetLastStatus() const
{ {
return status; return lastStatus;
} }
LineJoin GetLineJoin(VOID) LineJoin
GetLineJoin()
{ {
LineJoin lineJoin; LineJoin lineJoin;
SetStatus(DllExports::GdipGetPenLineJoin(nativePen, &lineJoin)); SetStatus(DllExports::GdipGetPenLineJoin(nativePen, &lineJoin));
return lineJoin; return lineJoin;
} }
REAL GetMiterLimit(VOID) REAL
GetMiterLimit()
{ {
REAL miterLimit; REAL miterLimit;
SetStatus(DllExports::GdipGetPenMiterLimit(nativePen, &miterLimit)); SetStatus(DllExports::GdipGetPenMiterLimit(nativePen, &miterLimit));
return miterLimit; return miterLimit;
} }
PenType GetPenType(VOID) PenType
GetPenType()
{ {
PenType type; PenType type;
SetStatus(DllExports::GdipGetPenFillType(nativePen, &type)); SetStatus(DllExports::GdipGetPenFillType(nativePen, &type));
return type; return type;
} }
LineCap GetStartCap(VOID) LineCap
GetStartCap()
{ {
LineCap startCap; LineCap startCap;
SetStatus(DllExports::GdipGetPenStartCap(nativePen, &startCap)); SetStatus(DllExports::GdipGetPenStartCap(nativePen, &startCap));
@ -167,10 +218,11 @@ class Pen : public GdiplusBase
Status Status
GetTransform(Matrix *matrix) GetTransform(Matrix *matrix)
{ {
return NotImplemented; return SetStatus(DllExports::GdipGetPenTransform(nativePen, matrix->nativeMatrix));
} }
REAL GetWidth(VOID) REAL
GetWidth()
{ {
REAL width; REAL width;
SetStatus(DllExports::GdipGetPenWidth(nativePen, &width)); SetStatus(DllExports::GdipGetPenWidth(nativePen, &width));
@ -178,26 +230,29 @@ class Pen : public GdiplusBase
} }
Status Status
MultiplyTransform(Matrix *matrix, MatrixOrder order) MultiplyTransform(Matrix *matrix, MatrixOrder order = MatrixOrderPrepend)
{ {
return NotImplemented; // FIXME: not available: SetStatus(DllExports::GdipMultiplyPenTransform(nativePen, matrix #if 1
// ? matrix->nativeMatrix : NULL, order)); return SetStatus(NotImplemented);
#else
return SetStatus(DllExports::GdipMultiplyPenTransform(nativePen, matrix->nativeMatrix, order));
#endif
} }
Status ResetTransform(VOID) Status
ResetTransform()
{ {
return SetStatus(DllExports::GdipResetPenTransform(nativePen)); return SetStatus(DllExports::GdipResetPenTransform(nativePen));
} }
Status Status
RotateTransform(REAL angle, MatrixOrder order) RotateTransform(REAL angle, MatrixOrder order = MatrixOrderPrepend)
{ {
return NotImplemented; // FIXME: not available: SetStatus(DllExports::GdipRotatePenTransform(nativePen, angle, return SetStatus(DllExports::GdipRotatePenTransform(nativePen, angle, order));
// order));
} }
Status Status
ScaleTransform(REAL sx, REAL sy, MatrixOrder order) ScaleTransform(REAL sx, REAL sy, MatrixOrder order = MatrixOrderPrepend)
{ {
return SetStatus(DllExports::GdipScalePenTransform(nativePen, sx, sy, order)); return SetStatus(DllExports::GdipScalePenTransform(nativePen, sx, sy, order));
} }
@ -211,7 +266,8 @@ class Pen : public GdiplusBase
Status Status
SetBrush(const Brush *brush) SetBrush(const Brush *brush)
{ {
return SetStatus(DllExports::GdipSetPenBrushFill(nativePen, brush ? brush->nativeBrush : NULL)); GpBrush *theBrush = brush ? brush->nativeBrush : NULL;
return SetStatus(DllExports::GdipSetPenBrushFill(nativePen, theBrush));
} }
Status Status
@ -229,13 +285,15 @@ class Pen : public GdiplusBase
Status Status
SetCustomEndCap(const CustomLineCap *customCap) SetCustomEndCap(const CustomLineCap *customCap)
{ {
return NotImplemented; GpCustomLineCap *cap = customCap ? getNat(customCap) : NULL;
return SetStatus(DllExports::GdipSetPenCustomEndCap(nativePen, cap));
} }
Status Status
SetCustomStartCap(const CustomLineCap *customCap) SetCustomStartCap(const CustomLineCap *customCap)
{ {
return NotImplemented; GpCustomLineCap *cap = customCap ? getNat(customCap) : NULL;
return SetStatus(DllExports::GdipSetPenCustomStartCap(nativePen, cap));
} }
Status Status
@ -295,7 +353,8 @@ class Pen : public GdiplusBase
Status Status
SetTransform(const Matrix *matrix) SetTransform(const Matrix *matrix)
{ {
return SetStatus(DllExports::GdipSetPenTransform(nativePen, matrix ? matrix->nativeMatrix : NULL)); GpMatrix *mat = matrix ? matrix->nativeMatrix : NULL;
return SetStatus(DllExports::GdipSetPenTransform(nativePen, mat));
} }
Status Status
@ -304,20 +363,39 @@ class Pen : public GdiplusBase
return SetStatus(DllExports::GdipSetPenWidth(nativePen, width)); return SetStatus(DllExports::GdipSetPenWidth(nativePen, width));
} }
private: Status
GpPen *nativePen; TranslateTransform(REAL dx, REAL dy, MatrixOrder order = MatrixOrderPrepend)
{
return SetStatus(DllExports::GdipTranslatePenTransform(nativePen, dx, dy, order));
}
private: protected:
mutable Status status; GpPen *nativePen;
mutable Status lastStatus;
Status Status
SetStatus(Status status) const SetStatus(Status status) const
{ {
if (status == Ok) if (status != Ok)
return status; lastStatus = status;
this->status = status;
return status; return status;
} }
Pen(GpPen *pen, Status status) : nativePen(pen), lastStatus(status)
{
}
VOID
SetNativePen(GpPen *pen)
{
nativePen = pen;
}
private:
// Pen is not copyable
Pen(const Pen &);
Pen &
operator=(const Pen &);
}; };
#endif /* _GDIPLUSPEN_H */ #endif /* _GDIPLUSPEN_H */