20 #include <vstgui4/vstgui/lib/cdrawcontext.h> 21 #include <vstgui4/vstgui/lib/cview.h> 23 #include <base/source/fstring.h> 57 CHoriTxtAlign fHorizTxtAlign{kCenterText};
61 CColor fFontColor{kWhiteCColor};
62 CColor fShadowColor{kBlackCColor};
63 CPoint fTextInset{0, 0};
64 CPoint fShadowTextOffset{1., 1.};
65 bool fAntialias{
true};
67 constexpr
bool hasStyle(
Style iStyle)
const {
return fStyle & static_cast<int32_t>(iStyle); }
68 inline void setStyle(
Style iStyle) { fStyle = static_cast<int32_t>(iStyle); }
69 inline void addStyle(
Style iStyle) { fStyle |= static_cast<int32_t>(iStyle); }
82 explicit RelativeView(CView
const *iView) : fRect{iView->getViewSize()}
92 return RelativeRect(0, 0, fRect.getWidth(), fRect.getHeight());
97 return fRect.getWidth();
106 return fRect.getHeight();
111 return x + fRect.left;
116 return y + fRect.top;
121 return x - fRect.left;
126 return y - fRect.top;
131 return AbsolutePoint{toAbsoluteX(iPoint.x), toAbsoluteY(iPoint.y)};
136 return RelativePoint{fromAbsoluteX(iPoint.x), fromAbsoluteY(iPoint.y)};
146 Utils::clamp(fromAbsoluteX(iPoint.x), 0.0, fRect.getWidth()),
147 Utils::clamp(fromAbsoluteY(iPoint.y), 0.0, fRect.getHeight())
153 return CPoint{x + fRect.left, y + fRect.top};
158 return CRect(toAbsolutePoint(iRect.getTopLeft()), iRect.getSize());
177 fDrawContext->setFrameColor(color);
178 fDrawContext->drawLine(toAbsolutePoint(x1, y1), toAbsolutePoint(x2, y2));
188 fDrawContext->setFrameColor(iStrokeColor);
189 fDrawContext->drawRect(toAbsoluteRect(iRect), kDrawStroked);
199 fDrawContext->setFillColor(iColor);
200 fDrawContext->drawRect(toAbsoluteRect(iRect), kDrawFilled);
205 fDrawContext->setFillColor(iFillColor);
206 fDrawContext->setFrameColor(iStrokeColor);
207 fDrawContext->drawRect(toAbsoluteRect(iRect), kDrawFilledAndStroked);
212 drawEllipse(
RelativeRect{x1, y1, x2, y2}, iStrokeColor);
217 fDrawContext->setFrameColor(iStrokeColor);
218 fDrawContext->drawEllipse(toAbsoluteRect(iRect), kDrawStroked);
228 fDrawContext->setFillColor(iColor);
229 fDrawContext->drawEllipse(toAbsoluteRect(iRect), kDrawFilled);
234 fDrawContext->setFillColor(iFillColor);
235 fDrawContext->setFrameColor(iStrokeColor);
236 fDrawContext->drawEllipse(toAbsoluteRect(iRect), kDrawFilledAndStroked);
241 CRect size{x, y, fDrawContext->getStringWidth(iText.getPlatformString()), iHeight};
242 drawString(iText, size, iSdc);
249 drawString(iText, getViewSize(), iSdc);
259 template<
typename... Args>
263 auto s = Steinberg::String().printf(iFormat, std::forward<Args>(iArgs)...);
264 debugText(x, y, s.text8());
268 template<
typename... Args>
269 inline void debugTopLeft(
char const *iFormat, Args&& ...iArgs) { debugXY(0, 0, iFormat, std::forward<Args>(iArgs)...); }
272 template<
typename... Args>
273 inline void debugTopRight(
char const *iFormat, Args&& ...iArgs) { debugXY(-1, 0, iFormat, std::forward<Args>(iArgs)...); }
276 template<
typename... Args>
277 inline void debugBottomLeft(
char const *iFormat, Args&& ...iArgs) { debugXY(0, -1, iFormat, std::forward<Args>(iArgs)...); }
280 template<
typename... Args>
281 inline void debugBottomRight(
char const *iFormat, Args&& ...iArgs) { debugXY(-1, -1, iFormat, std::forward<Args>(iArgs)...); }
286 template<
typename... Args>
287 inline void debug(
char const *iFormat, Args&& ...iArgs) { debugTopLeft(iFormat, std::forward<Args>(iArgs)...); }
292 inline void debugText(
char const *iText) { debugText(0, 0, iText); }
306 CColor fDebugStringColor{kGreenCColor};
307 FontPtr fDebugStringFont{kNormalFontVerySmall};
void addStyle(Style iStyle)
Definition: DrawContext.h:69
void fillRect(RelativeCoord x1, RelativeCoord y1, RelativeCoord x2, RelativeCoord y2, CColor const &iColor)
Definition: DrawContext.h:192
Definition: DrawContext.h:43
CDrawContext * fDrawContext
Definition: DrawContext.h:302
RelativeView(CView const *iView)
Definition: DrawContext.h:82
AbsoluteCoord toAbsoluteX(RelativeCoord x) const
Definition: DrawContext.h:109
AbsolutePoint toAbsolutePoint(RelativeCoord x, RelativeCoord y) const
Definition: DrawContext.h:151
static T clamp(const U &iValue, const T &iLower, const T &iUpper)
Make sure that the value remains within its bounds.
Definition: Misc.h:33
RelativeView(AbsoluteRect const &iRect)
Definition: DrawContext.h:86
RelativePoint fromAbsolutePoint(AbsolutePoint const &iPoint) const
Definition: DrawContext.h:134
void fillEllipse(RelativeRect const &iRect, CColor const &iColor)
Definition: DrawContext.h:226
CPoint RelativePoint
Definition: DrawContext.h:74
Encapsulates the draw context provided by VSTGUI to reason in relative coordinates (0,...
Definition: DrawContext.h:168
void fillAndStrokeEllipse(RelativeRect const &iRect, CColor const &iFillColor, CColor const &iStrokeColor)
Definition: DrawContext.h:232
CCoord RelativeCoord
Definition: DrawContext.h:72
void fillAndStrokeRect(RelativeRect const &iRect, CColor const &iFillColor, CColor const &iStrokeColor)
Definition: DrawContext.h:203
Range getVerticalRange() const
Definition: DrawContext.h:102
RelativeCoord fromAbsoluteX(AbsoluteCoord x) const
Definition: DrawContext.h:119
Definition: DrawContext.h:44
AbsoluteRect const & fRect
Definition: DrawContext.h:162
RelativePoint clampAbsolutePoint(AbsolutePoint const &iPoint) const
Convert the absolute point to a relative point while making sure it is clamped (constrained) within t...
Definition: DrawContext.h:143
AbsolutePoint toAbsolutePoint(RelativePoint const &iPoint) const
Definition: DrawContext.h:129
void drawEllipse(RelativeRect const &iRect, CColor const &iStrokeColor)
Definition: DrawContext.h:215
CFontDesc * FontPtr
Definition: Types.h:53
void drawRect(RelativeRect const &iRect, CColor const &iStrokeColor)
Definition: DrawContext.h:186
DeprecatedCControlEnum
Implementation note: The CControlEnum enumeration has been removed from VSTGUI.
Definition: DrawContext.h:41
CRect RelativeRect
Definition: DrawContext.h:76
Range getHorizontalRange() const
Definition: DrawContext.h:100
void drawEllipse(RelativeCoord x1, RelativeCoord y1, RelativeCoord x2, RelativeCoord y2, CColor const &iStrokeColor)
Definition: DrawContext.h:210
CRect AbsoluteRect
Definition: DrawContext.h:77
constexpr bool hasStyle(Style iStyle) const
Definition: DrawContext.h:67
void drawRect(RelativeCoord x1, RelativeCoord y1, RelativeCoord x2, RelativeCoord y2, CColor const &iStrokeColor)
Definition: DrawContext.h:181
CPoint AbsolutePoint
Definition: DrawContext.h:75
void fillEllipse(RelativeCoord x1, RelativeCoord y1, RelativeCoord x2, RelativeCoord y2, CColor const &iColor)
Definition: DrawContext.h:221
CCoord AbsoluteCoord
Definition: DrawContext.h:73
void drawLine(RelativeCoord x1, RelativeCoord y1, RelativeCoord x2, RelativeCoord y2, CColor const &color)
Definition: DrawContext.h:175
void setStyle(Style iStyle)
Definition: DrawContext.h:68
AbsoluteCoord toAbsoluteY(RelativeCoord y) const
Definition: DrawContext.h:114
CCoord getHeight() const
Definition: DrawContext.h:104
The context which contains the details on how the string should be drawn.
Definition: DrawContext.h:49
Definition: DrawContext.h:79
CCoord getWidth() const
Definition: DrawContext.h:95
Style
Definition: DrawContext.h:51
void drawString(UTF8String const &iText, RelativeCoord x, RelativeCoord y, RelativeCoord iHeight, StringDrawContext &iSdc)
Definition: DrawContext.h:239
AbsoluteRect toAbsoluteRect(RelativeRect const &iRect) const
Definition: DrawContext.h:156
void fillRect(RelativeRect const &iRect, CColor const &iColor)
Definition: DrawContext.h:197
RelativeRect getViewSize() const
Definition: DrawContext.h:90
void drawString(UTF8String const &iText, StringDrawContext &iSdc)
Definition: DrawContext.h:247
RelativeDrawContext(CView *iView, CDrawContext *iDrawContext)
Definition: DrawContext.h:171
RelativeCoord fromAbsoluteY(AbsoluteCoord y) const
Definition: DrawContext.h:124