ASPiK SDK
cgdrawcontext.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __cgdrawcontext__
6 #define __cgdrawcontext__
7 
8 #include "../../coffscreencontext.h"
9 
10 #if MAC
11 
12 #if TARGET_OS_IPHONE
13  #include <CoreGraphics/CoreGraphics.h>
14  #include <ImageIO/ImageIO.h>
15 #else
16  #include <ApplicationServices/ApplicationServices.h>
17 #endif
18 
19 #if MAC_CARBON
20 #include <Carbon/Carbon.h>
21 #endif
22 
23 #include <map>
24 
25 namespace VSTGUI {
26 class CGBitmap;
27 
28 //-----------------------------------------------------------------------------
29 class CGDrawContext : public COffscreenContext
30 {
31 public:
32  CGDrawContext (CGContextRef cgContext, const CRect& rect);
33  explicit CGDrawContext (CGBitmap* bitmap);
34  ~CGDrawContext () noexcept override;
35 
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; }
65 
66  CGContextRef beginCGContext (bool swapYAxis = false, bool integralOffset = false);
67  void releaseCGContext (CGContextRef context);
68 
69  CGContextRef getCGContext () const { return cgContext; }
70  void applyLineStyle (CGContextRef context);
71  void applyLineWidthCTM (CGContextRef context) const;
72 
73  CGRect pixelAlligned (const CGRect& r) const;
74  CGPoint pixelAlligned (const CGPoint& p) const;
75 
76 //------------------------------------------------------------------------------------
77 protected:
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);
80 
81  CGContextRef cgContext;
82 
83  using BitmapDrawCountMap = std::map<CGBitmap*, int32_t>;
84  BitmapDrawCountMap bitmapDrawCount;
85 
86  double scaleFactor;
87 };
88 
89 } // namespace
90 
91 #endif // MAC
92 
93 #endif // __cgdrawcontext__
94 
Definition: customcontrols.cpp:8