5 #ifndef __cdrawcontext__ 6 #define __cdrawcontext__ 14 #include "cgraphicstransform.h" 15 #include "clinestyle.h" 16 #include "cdrawdefs.h" 23 struct CNinePartTiledDescription;
49 using LinePair = std::pair<CPoint, CPoint>;
50 using LineList = std::vector<LinePair>;
51 using PointList = std::vector<CPoint>;
53 inline void drawLine (
const CPoint& start,
const CPoint& end) { drawLine (std::make_pair (start, end)); }
54 virtual void drawLine (
const LinePair& line) = 0;
55 virtual void drawLines (
const LineList& lines) = 0;
56 virtual void drawPolygon (
const PointList& polygonPointList,
const CDrawStyle drawStyle = kDrawStroked) = 0;
57 virtual void drawRect (
const CRect &rect,
const CDrawStyle drawStyle = kDrawStroked) = 0;
58 virtual void drawArc (
const CRect &rect,
const float startAngle1,
const float endAngle2,
const CDrawStyle drawStyle = kDrawStroked) = 0;
59 virtual void drawEllipse (
const CRect &rect,
const CDrawStyle drawStyle = kDrawStroked) = 0;
64 virtual void fillRectWithBitmap (
CBitmap* bitmap,
const CRect& srcRect,
const CRect& dstRect,
float alpha);
113 virtual void setFont (
const CFontRef font,
const CCoord& size = 0,
const int32_t& style = -1);
122 void drawString (UTF8StringPtr
string,
const CRect& _rect,
const CHoriTxtAlign hAlign = kCenterText,
bool antialias =
true);
123 void drawString (UTF8StringPtr
string,
const CPoint& _point,
bool antialias =
true);
126 void drawString (IPlatformString*
string,
const CRect& _rect,
const CHoriTxtAlign hAlign = kCenterText,
bool antialias =
true);
127 void drawString (IPlatformString*
string,
const CPoint& _point,
bool antialias =
true);
142 virtual void saveGlobalState ();
143 virtual void restoreGlobalState ();
151 const CRect& getAbsoluteClipRect ()
const {
return currentState.clipRect; }
179 virtual void drawGraphicsPath (CGraphicsPath* path, PathDrawMode mode = kPathFilled, CGraphicsTransform* transformation =
nullptr) = 0;
180 virtual void fillLinearGradient (CGraphicsPath* path,
const CGradient& gradient,
const CPoint& startPoint,
const CPoint& endPoint,
bool evenOdd =
false, CGraphicsTransform* transformation =
nullptr) = 0;
181 virtual void fillRadialGradient (CGraphicsPath* path,
const CGradient& gradient,
const CPoint& center, CCoord radius,
const CPoint& originOffset = CPoint (0,0),
bool evenOdd =
false, CGraphicsTransform* transformation =
nullptr) = 0;
184 virtual void beginDraw () {}
185 virtual void endDraw () {}
188 explicit CDrawContext (
const CRect& surfaceRect);
189 ~CDrawContext () noexcept override;
191 virtual
void init ();
193 void pushTransform (const CGraphicsTransform& transformation);
194 void popTransform ();
196 const UTF8String& getDrawString (UTF8StringPtr
string);
197 void clearDrawString ();
200 struct CDrawContextState
202 SharedPointer<CFontDesc> font;
203 CColor frameColor {kTransparentCColor};
204 CColor fillColor {kTransparentCColor};
205 CColor fontColor {kTransparentCColor};
206 CCoord frameWidth {0.};
209 CLineStyle lineStyle {kLineOnOffDash};
210 CDrawMode drawMode {kAntiAliasing};
211 float globalAlpha {1.f};
213 CDrawContextState () =
default;
214 CDrawContextState (
const CDrawContextState& state);
215 CDrawContextState& operator= (
const CDrawContextState& state) =
default;
216 CDrawContextState (CDrawContextState&& state) noexcept;
217 CDrawContextState& operator= (CDrawContextState&& state) noexcept;
221 UTF8String* drawStringHelper;
224 CDrawContextState currentState;
227 std::stack<CDrawContextState> globalStatesStack;
228 std::stack<CGraphicsTransform> transformStack;
239 rect.bound (origClip);
virtual void drawArc(const CRect &rect, const float startAngle1, const float endAngle2, const CDrawStyle drawStyle=kDrawStroked)=0
draw an arc, angles are in degree
CCoord getStringWidth(UTF8StringPtr pStr)
get the width of an UTF-8 encoded string
Definition: cdrawcontext.cpp:270
CCoord getLineWidth() const
get the current line width
Definition: cdrawcontext.h:77
virtual double getScaleFactor() const
Definition: cdrawcontext.h:154
font class
Definition: cfont.h:31
Rect structure.
Definition: crect.h:17
CColor getFontColor() const
get current font color
Definition: cdrawcontext.h:112
virtual void drawEllipse(const CRect &rect, const CDrawStyle drawStyle=kDrawStroked)=0
draw an ellipse
virtual void drawBitmap(CBitmap *bitmap, const CRect &dest, const CPoint &offset=CPoint(0, 0), float alpha=1.f)=0
don't call directly, please use CBitmap::draw instead
virtual void setFillColor(const CColor &color)
set current fill color
Definition: cdrawcontext.cpp:155
CColor getFillColor() const
get current fill color
Definition: cdrawcontext.h:102
float getGlobalAlpha() const
get current global alpha value
Definition: cdrawcontext.h:135
virtual void drawRect(const CRect &rect, const CDrawStyle drawStyle=kDrawStroked)=0
draw a rect
CCoord getHairlineSize() const
Definition: cdrawcontext.cpp:371
A drawing context encapsulates the drawing context of the underlying OS.
Definition: cdrawcontext.h:29
CColor getFrameColor() const
get current stroke color
Definition: cdrawcontext.h:104
const CLineStyle & getLineStyle() const
get the current line style
Definition: cdrawcontext.h:74
RGBA Color structure.
Definition: ccolor.h:15
const CFontRef getFont() const
get current font
Definition: cdrawcontext.h:114
virtual void drawPoint(const CPoint &point, const CColor &color)=0
draw a point
CDrawMode getDrawMode() const
get the current draw mode, see CDrawMode
Definition: cdrawcontext.h:85
Graphics Path Object.
Definition: cgraphicspath.h:19
virtual CGraphicsPath * createTextPath(const CFontRef font, UTF8StringPtr text)=0
create a graphics path from a text
virtual void setClipRect(const CRect &clip)
set the current clip
Definition: cdrawcontext.cpp:141
Encapsulates various platform depended kinds of bitmaps.
Definition: cbitmap.h:21
void drawString(UTF8StringPtr string, const CRect &_rect, const CHoriTxtAlign hAlign=kCenterText, bool antialias=true)
draw an UTF-8 encoded string
Definition: cdrawcontext.cpp:283
Definition: clinestyle.h:16
Definition: customcontrols.cpp:8
virtual void setGlobalAlpha(float newAlpha)
sets the global alpha value[0..1]
Definition: cdrawcontext.cpp:192
virtual void resetClipRect()
reset the clip to the default state
Definition: cdrawcontext.cpp:149
Definition: cdrawdefs.h:25
virtual void setLineWidth(CCoord width)
set the current line width
Definition: cdrawcontext.cpp:120
virtual void setFontColor(const CColor &color)
set current font color
Definition: cdrawcontext.cpp:167
Definition: vstguibase.h:247
virtual void setLineStyle(const CLineStyle &style)
set the current line style
Definition: cdrawcontext.cpp:114
Definition: cdrawcontext.h:35
CRect & getClipRect(CRect &clip) const
get the current clip
Definition: cdrawcontext.cpp:132
virtual void setFrameColor(const CColor &color)
set current stroke color
Definition: cdrawcontext.cpp:161
Definition: cdrawcontext.h:232
virtual CGraphicsPath * createGraphicsPath()=0
create a graphics path object, you need to forget it after usage
virtual void drawLines(const LineList &lines)=0
draw multiple lines at once
virtual void setFont(const CFontRef font, const CCoord &size=0, const int32_t &style=-1)
set current font
Definition: cdrawcontext.cpp:173
Point structure.
Definition: cpoint.h:17
virtual void clearRect(const CRect &rect)=0
clears the rect (makes r = 0, g = 0, b = 0, a = 0)
virtual void drawPolygon(const PointList &polygonPointList, const CDrawStyle drawStyle=kDrawStroked)=0
draw a polygon
virtual void setDrawMode(CDrawMode mode)
set the current draw mode, see CDrawMode
Definition: cdrawcontext.cpp:126
CGraphicsPath * createRoundRectGraphicsPath(const CRect &size, CCoord radius)
create a rect with round corners as graphics path, you need to forget it after usage ...
Definition: cdrawcontext.cpp:338