iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestDrawContextControl.h
Go to the documentation of this file.
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10
11#pragma once
12
18#include "IControl.h"
19
23{
24public:
25 TestDrawContextControl(const IRECT& bounds)
26 : IControl(bounds)
27 {
28 SetTooltip("TestDrawContextControl");
29 }
30
31 void Draw(IGraphics& g) override
32 {
33 g.DrawDottedRect(COLOR_BLACK, mRECT);
34
35 IRECT r1 = mRECT.GetCentredInside(100);
36
37#if defined IGRAPHICS_NANOVG
38 NVGcontext* vg = (NVGcontext*) g.GetDrawContext();
39 nvgSave(vg);
40 nvgTranslate(vg, r1.MW(), r1.MH());
41 nvgRotate(vg, nvgDegToRad(30));
42 nvgTranslate(vg, -r1.MW(), -r1.MH());
43 nvgBeginPath(vg);
44 nvgRect(vg, r1.L, r1.T, r1.W(), r1.H());
45 nvgFillColor(vg, nvgRGBA(255, 0, 0, 255));
46 nvgFill(vg);
47 nvgRestore(vg);
48#elif defined IGRAPHICS_SKIA
49 SkCanvas* canvas = (SkCanvas*) g.GetDrawContext();
50 SkPaint paint;
51 paint.setAntiAlias(true);
52 paint.setColor(SK_ColorRED);
53
54 SkRect rect = SkiaRect(r1);
55 canvas->translate(r1.MW(), r1.MH());
56 canvas->rotate(30);
57 canvas->translate(-r1.MW(), -r1.MH());
58 canvas->drawRect(rect, paint);
59#elif defined IGRAPHICS_CANVAS
60
61#else
62 g.DrawText(mText, "UNSUPPORTED", mRECT);
63#endif
64 }
65};
This file contains the base IControl implementation, along with some base classes for specific types ...
The lowest level base class of an IGraphics control.
Definition: IControl.h:49
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
void DrawText(const IText &text, const char *str, const IRECT &bounds, const IBlend *pBlend=0)
Draw some text to the graphics context in a specific rectangle.
Definition: IGraphics.cpp:670
virtual void * GetDrawContext()=0
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
virtual void DrawDottedRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f, float dashLen=2.f)
Draw a dotted rectangle to the graphics context.
Definition: IGraphics.cpp:2539
Control to test obtaining a drawing API (NanoVG, Skia, Canvas) context and using that API within an I...
void Draw(IGraphics &g) override
Draw the control to the graphics context.
Used to manage a rectangular area, independent of draw class/platform.
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
float MH() const
float W() const
float H() const
float MW() const