5 #ifndef __cgdrawcontext__ 6 #define __cgdrawcontext__ 8 #include "../../coffscreencontext.h" 13 #include <CoreGraphics/CoreGraphics.h> 14 #include <ImageIO/ImageIO.h> 16 #include <ApplicationServices/ApplicationServices.h> 20 #include <Carbon/Carbon.h> 29 class CGDrawContext :
public COffscreenContext
32 CGDrawContext (CGContextRef cgContext,
const CRect& rect);
33 explicit CGDrawContext (CGBitmap* bitmap);
34 ~CGDrawContext () noexcept override;
36 void drawLine (const LinePair& line) override;
37 void drawLines (const LineList& lines) override;
38 void drawPolygon (const PointList& polygonPointList, const CDrawStyle drawStyle = kDrawStroked) override;
39 void drawRect (const CRect &rect, const CDrawStyle drawStyle = kDrawStroked) override;
40 void drawArc (const CRect &rect, const
float startAngle1, const
float endAngle2, const CDrawStyle drawStyle = kDrawStroked) override;
41 void drawEllipse (const CRect &rect, const CDrawStyle drawStyle = kDrawStroked) override;
42 void drawPoint (const CPoint &point, const CColor& color) override;
43 void drawBitmap (CBitmap* bitmap, const CRect& dest, const CPoint& offset = CPoint (0, 0),
float alpha = 1.f) override;
44 void drawBitmapNinePartTiled (CBitmap* bitmap, const CRect& dest, const CNinePartTiledDescription& desc,
float alpha = 1.f) override;
45 void fillRectWithBitmap (CBitmap* bitmap, const CRect& srcRect, const CRect& dstRect,
float alpha) override;
46 void clearRect (const CRect& rect) override;
47 void setLineStyle (const CLineStyle& style) override;
48 void setLineWidth (CCoord width) override;
49 void setDrawMode (CDrawMode mode) override;
50 void setClipRect (const CRect &clip) override;
51 void resetClipRect () override;
52 void setFillColor (const CColor& color) override;
53 void setFrameColor (const CColor& color) override;
54 void setFontColor (const CColor& color) override;
55 void setGlobalAlpha (
float newAlpha) override;
56 void saveGlobalState () override;
57 void restoreGlobalState () override;
58 void endDraw () override;
59 CGraphicsPath* createGraphicsPath () override;
60 CGraphicsPath* createTextPath (const CFontRef font, UTF8StringPtr text) override;
61 void drawGraphicsPath (CGraphicsPath* path, PathDrawMode mode = kPathFilled, CGraphicsTransform* transformation =
nullptr) override;
62 void fillLinearGradient (CGraphicsPath* path, const CGradient& gradient, const CPoint& startPoint, const CPoint& endPoint,
bool evenOdd = false, CGraphicsTransform* transformation =
nullptr) override;
63 void fillRadialGradient (CGraphicsPath* path, const CGradient& gradient, const CPoint& center, CCoord radius, const CPoint& originOffset = CPoint (0, 0),
bool evenOdd = false, CGraphicsTransform* transformation =
nullptr) override;
64 double getScaleFactor ()
const override {
return scaleFactor; }
66 CGContextRef beginCGContext (
bool swapYAxis =
false,
bool integralOffset =
false);
67 void releaseCGContext (CGContextRef context);
69 CGContextRef getCGContext ()
const {
return cgContext; }
70 void applyLineStyle (CGContextRef context);
71 void applyLineWidthCTM (CGContextRef context)
const;
73 CGRect pixelAlligned (
const CGRect& r)
const;
74 CGPoint pixelAlligned (
const CGPoint& p)
const;
78 void init ()
override;
79 void drawCGImageRef (CGContextRef context, CGImageRef image, CGLayerRef layer,
double imageScaleFactor,
const CRect& inRect,
const CPoint& inOffset,
float alpha, CBitmap* bitmap);
81 CGContextRef cgContext;
83 using BitmapDrawCountMap = std::map<CGBitmap*, int32_t>;
84 BitmapDrawCountMap bitmapDrawCount;
93 #endif // __cgdrawcontext__ Definition: customcontrols.cpp:8