iPlug2 - C++ Audio Plug-in Framework
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 {
24 public:
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 
62 private:
63  ILayerPtr mLayer;
64  bool mDrawBackground = true;
65 };
float MW() const
float MH() const
void StartLayer(IControl *pOwner, const IRECT &r, bool cacheable=false)
Create an IGraphics layer.
Definition: IGraphics.cpp:1954
Used to manage a rectangular area, independent of draw class/platform.
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
Used to manage mouse modifiers i.e.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
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:2584
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
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
float W() const
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:764
IText is used to manage font and text/text entry style for a piece of text on the UI...
bool CheckLayer(const ILayerPtr &layer)
Test to see if a layer needs drawing, for instance if the control&#39;s bounds were changed.
Definition: IGraphics.cpp:2009
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:2554
Control to test IGraphics layers.
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1191
void DrawLayer(const ILayerPtr &layer, const IBlend *pBlend=nullptr)
Draw a layer to the main IGraphics context.
Definition: IGraphics.cpp:2022
double GetValue(int valIdx=0) const
Get the control&#39;s value.
Definition: IControl.cpp:151
ILayerPtr EndLayer()
End an IGraphics layer.
Definition: IGraphics.cpp:1977
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
std::unique_ptr< ILayer > ILayerPtr
ILayerPtr is a managed pointer for transferring the ownership of layers.
virtual void SetDirty(bool triggerAction=true, int valIdx=kNoValIdx)
Mark the control as dirty, i.e.
Definition: IControl.cpp:196