iPlug2 - C++ Audio Plug-in Framework
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 {
24 public:
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 };
float MW() const
float MH() const
The lowest level base class of an IGraphics control.
Definition: IControl.h:42
Used to manage a rectangular area, independent of draw class/platform.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
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:2517
Control to test obtaining a drawing API (NanoVG, Skia, Canvas) context and using that API within an I...
void SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:210
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:631
This file contains the base IControl implementation, along with some base classes for specific types ...
float H() const
float W() const
IControl(const IRECT &bounds, int paramIdx=kNoParameter, IActionFunction actionFunc=nullptr)
Constructor.
Definition: IControl.cpp:81
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void * GetDrawContext()=0
Gets a void pointer to underlying drawing context, for the IGraphics backend See draw class implement...
float L
Left side of the rectangle (X)
IRECT GetCentredInside(const IRECT &sr) const
Get a rectangle the size of sr but with the same center point as this rectangle.
float T
Top of the rectangle (Y)