ASPiK SDK
cairocontext.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 #pragma once
6 
7 #include "cairoutils.h"
8 
9 #include "../../coffscreencontext.h"
10 
11 //------------------------------------------------------------------------
12 namespace VSTGUI {
13 namespace Cairo {
14 
15 class Bitmap;
16 
17 //------------------------------------------------------------------------
18 class Context : public COffscreenContext
19 {
20 public:
21  using super = COffscreenContext;
22 
23  Context (CRect& rect, const SurfaceHandle& surface);
24  Context (CRect r, cairo_t* context);
25  Context (Bitmap* bitmap);
26 
27  ~Context ();
28 
29  bool valid () const { return cr != nullptr; }
30  CRect getSurfaceRect () const { return surfaceRect; }
31  const SurfaceHandle& getSurface () const { return surface; }
32  const ContextHandle& getCairo () const { return cr; }
33 
34  void drawLine (const LinePair& line) override;
35  void drawLines (const LineList& lines) override;
36  void drawPolygon (const PointList& polygonPointList, const CDrawStyle drawStyle) override;
37  void drawRect (const CRect& rect, const CDrawStyle drawStyle) override;
38  void drawArc (const CRect& rect, const float startAngle1, const float endAngle2,
39  const CDrawStyle drawStyle) override;
40  void drawEllipse (const CRect& rect, const CDrawStyle drawStyle) override;
41  void drawPoint (const CPoint& point, const CColor& color) override;
42  void drawBitmap (CBitmap* bitmap, const CRect& dest, const CPoint& offset,
43  float alpha) override;
44  void clearRect (const CRect& rect) override;
45  CGraphicsPath* createGraphicsPath () override;
46  CGraphicsPath* createTextPath (const CFontRef font, UTF8StringPtr text) override;
47  void drawGraphicsPath (CGraphicsPath* path, PathDrawMode mode,
48  CGraphicsTransform* transformation) override;
49  void fillLinearGradient (CGraphicsPath* path, const CGradient& gradient,
50  const CPoint& startPoint, const CPoint& endPoint, bool evenOdd,
51  CGraphicsTransform* transformation) override;
52  void fillRadialGradient (CGraphicsPath* path, const CGradient& gradient, const CPoint& center,
53  CCoord radius, const CPoint& originOffset, bool evenOdd,
54  CGraphicsTransform* transformation) override;
55 
56  void saveGlobalState () override;
57  void restoreGlobalState () override;
58 
59  void beginDraw () override;
60  void endDraw () override;
61 
62 private:
63  void init () override;
64  void setSourceColor (CColor color);
65  void setupCurrentStroke ();
66  void draw (CDrawStyle drawstyle);
67 
68  SurfaceHandle surface;
69  ContextHandle cr;
70 };
71 
72 //------------------------------------------------------------------------
73 struct DrawBlock
74 {
75  static DrawBlock begin (Context& context);
76 
77  ~DrawBlock ();
78  operator bool () { return !clipIsEmpty; }
79 private:
80  explicit DrawBlock (Context& context);
81  Context& context;
82  bool clipIsEmpty {false};
83 };
84 
85 //-----------------------------------------------------------------------------
86 template <typename T>
87 inline T pixelAlign (const CGraphicsTransform& tm, T obj)
88 {
89  tm.transform (obj);
90  obj.makeIntegral ();
91  tm.inverse ().transform (obj);
92  return obj;
93 }
94 
95 //------------------------------------------------------------------------
96 } // Cairo
97 } // VSTGUI
void drawEllipse(const CRect &rect, const CDrawStyle drawStyle) override
draw an ellipse
Definition: cairocontext.cpp:356
font class
Definition: cfont.h:31
Rect structure.
Definition: crect.h:17
void drawPoint(const CPoint &point, const CColor &color) override
draw a point
Definition: cairocontext.cpp:369
CGraphicsPath * createGraphicsPath() override
create a graphics path object, you need to forget it after usage
Definition: cairocontext.cpp:435
void drawLines(const LineList &lines) override
draw multiple lines at once
Definition: cairocontext.cpp:276
Definition: cairocontext.h:73
void drawLine(const LinePair &line) override
draw a line
Definition: cairocontext.cpp:252
Definition: cairocontext.h:18
RGBA Color structure.
Definition: ccolor.h:15
A draw context using a bitmap as it&#39;s back buffer.
Definition: coffscreencontext.h:58
Definition: cairobitmap.h:19
Graphics Path Object.
Definition: cgraphicspath.h:19
Gradient Object [new in 4.0].
Definition: cgradient.h:19
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
Definition: customcontrols.cpp:8
void drawArc(const CRect &rect, const float startAngle1, const float endAngle2, const CDrawStyle drawStyle) override
draw an arc, angles are in degree
Definition: cairocontext.cpp:342
Graphics Transform Matrix.
Definition: cgraphicstransform.h:23
void drawBitmap(CBitmap *bitmap, const CRect &dest, const CPoint &offset, float alpha) override
don&#39;t call directly, please use CBitmap::draw instead
Definition: cairocontext.cpp:381
void drawPolygon(const PointList &polygonPointList, const CDrawStyle drawStyle) override
draw a polygon
Definition: cairocontext.cpp:306
Point structure.
Definition: cpoint.h:17
void drawRect(const CRect &rect, const CDrawStyle drawStyle) override
draw a rect
Definition: cairocontext.cpp:324
CGraphicsPath * createTextPath(const CFontRef font, UTF8StringPtr text) override
create a graphics path from a text
Definition: cairocontext.cpp:441
void clearRect(const CRect &rect) override
clears the rect (makes r = 0, g = 0, b = 0, a = 0)
Definition: cairocontext.cpp:423