iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestLayerControl.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 TestLayerControl(const IRECT& rect, int paramIdx)
26 : IKnobControlBase(rect, paramIdx)
27 {
28 SetTooltip("TestLayerControl");
29 }
30
31 void Draw(IGraphics& g) override
32 {
33 g.DrawDottedRect(COLOR_BLACK, mRECT);
34
35 if (mDrawBackground)
36 {
37 if (!g.CheckLayer(mLayer))
38 {
39 IText text;
40 text.mVAlign = EVAlign::Top;
41 text.mSize = 15;
42 g.StartLayer(this, mRECT);
43 g.FillRoundRect(COLOR_LIGHT_GRAY, mRECT.GetPadded(-5.5f), mRECT.W() / 4.f);
44 g.DrawText(text, "Cached Layer", mRECT.GetPadded(-10.f));
45 mLayer = g.EndLayer();
46 }
47
48 g.DrawLayer(mLayer);
49 }
50
51 g.FillCircle(COLOR_BLUE, mRECT.MW(), mRECT.MH(), mRECT.H() / 4.f);
52 g.DrawRadialLine(COLOR_BLACK, mRECT.MW(), mRECT.MH(), -120.f + static_cast<float>(GetValue()) * 240.f, 0.f, mRECT.H() / 4.f, nullptr, 3.f);
53 }
54
55 void OnMouseDown(float x, float y, const IMouseMod& mod) override
56 {
57 mLayer->Invalidate();
58 mDrawBackground = !mDrawBackground;
59 SetDirty(false);
60 }
61
62private:
63 ILayerPtr mLayer;
64 bool mDrawBackground = true;
65};
This file contains the base IControl implementation, along with some base classes for specific types ...
IControl * SetTooltip(const char *str)
Set a tooltip for the control.
Definition: IControl.h:216
double GetValue(int valIdx=0) const
Get the control's value.
Definition: IControl.cpp:153
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:198
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
void DrawRadialLine(const IColor &color, float cx, float cy, float angle, float rMin, float rMax, const IBlend *pBlend=0, float thickness=1.f)
Draw a radial line to the graphics context, useful for pointers on dials.
Definition: IGraphics.cpp:811
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
bool CheckLayer(const ILayerPtr &layer)
Test to see if a layer needs drawing, for instance if the control's bounds were changed.
Definition: IGraphics.cpp:2032
void DrawLayer(const ILayerPtr &layer, const IBlend *pBlend=nullptr)
Draw a layer to the main IGraphics context.
Definition: IGraphics.cpp:2045
virtual void FillRoundRect(const IColor &color, const IRECT &bounds, float cornerRadius=5.f, const IBlend *pBlend=0)
Fill a rounded rectangle with a color.
Definition: IGraphics.cpp:2576
void StartLayer(IControl *pOwner, const IRECT &r, bool cacheable=false)
Create an IGraphics layer.
Definition: IGraphics.cpp:1977
virtual void FillCircle(const IColor &color, float cx, float cy, float r, const IBlend *pBlend=0)
Fill a circle with a color.
Definition: IGraphics.cpp:2606
ILayerPtr EndLayer()
End an IGraphics layer.
Definition: IGraphics.cpp:2000
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1368
Control to test IGraphics layers.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
Used to manage mouse modifiers i.e.
Used to manage a rectangular area, independent of draw class/platform.
float MH() const
float W() const
float H() const
float MW() const
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
IText is used to manage font and text/text entry style for a piece of text on the UI,...