iPlug2 - C++ Audio Plug-in Framework
TestArcControl.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  TestArcControl(IRECT rect, int paramIdx = kNoParameter, float angle1 = -135.f, float angle2 = 135.f)
26  : IKnobControlBase(rect, paramIdx)
27  , mAngle1(angle1)
28  , mAngle2(angle2)
29  {
30  SetTooltip("TestArcControl");
31  }
32 
33  void Draw(IGraphics& g) override
34  {
35  g.FillRect(COLOR_WHITE, mRECT.GetPadded(-2));
36  g.DrawRect(COLOR_BLACK, mRECT.GetPadded(-2));
37  float angle = mAngle1 + (float) GetValue() * (mAngle2 - mAngle1);
38  g.FillArc(COLOR_BLUE, mRECT.MW(), mRECT.MH(), mRECT.W() * 0.44f, mAngle1, angle);
39  g.DrawArc(COLOR_BLACK, mRECT.MW(), mRECT.MH(), mRECT.W() * 0.44f, mAngle1, angle);
40  g.DrawRadialLine(COLOR_BLACK, mRECT.MW(), mRECT.MH(), angle, 0.f, mRECT.W() * 0.49f);
41  g.FillCircle(COLOR_WHITE, mRECT.MW(), mRECT.MH(), mRECT.W() * 0.1f);
42  g.DrawCircle(COLOR_BLACK, mRECT.MW(), mRECT.MH(), mRECT.W() * 0.1f);
43 
44  angle = DegToRad(angle-90.f);
45 
46  float x1 = mRECT.MW() + cosf(angle - 0.3f) * mRECT.W() * 0.3f;
47  float y1 = mRECT.MH() + sinf(angle - 0.3f) * mRECT.W() * 0.3f;
48  float x2 = mRECT.MW() + cosf(angle + 0.3f) * mRECT.W() * 0.3f;
49  float y2 = mRECT.MH() + sinf(angle + 0.3f) * mRECT.W() * 0.3f;
50  float x3 = mRECT.MW() + cosf(angle) * mRECT.W() * 0.44f;
51  float y3 = mRECT.MH() + sinf(angle) * mRECT.W() * 0.44f;
52 
53  g.FillTriangle(COLOR_WHITE, x1, y1, x2, y2, x3, y3);
54  g.DrawTriangle(COLOR_BLACK, x1, y1, x2, y2, x3, y3);
55  }
56 
57  void OnMouseDown(float x, float y, const IMouseMod& mod) override
58  {
61  }
62 
63  void OnMouseUp(float x, float y, const IMouseMod& mod) override
64  {
65  GetUI()->HideMouseCursor(false);
66  IKnobControlBase::OnMouseUp(x, y, mod);
67  }
68 
69 private:
70  float mAngle1;
71  float mAngle2;
72 };
float MW() const
float MH() const
Used to manage a rectangular area, independent of draw class/platform.
virtual void DrawRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0, float thickness=1.f)
Draw a rectangle to the graphics context.
Definition: IGraphics.cpp:2475
Used to manage mouse modifiers i.e.
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
This file contains the base IControl implementation, along with some base classes for specific types ...
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
virtual void DrawCircle(const IColor &color, float cx, float cy, float r, const IBlend *pBlend=0, float thickness=1.f)
Draw a circle to the graphics context.
Definition: IGraphics.cpp:2510
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
virtual void FillArc(const IColor &color, float cx, float cy, float r, float a1, float a2, const IBlend *pBlend=0)
Fill an arc segment with a color.
Definition: IGraphics.cpp:2575
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
virtual void FillRect(const IColor &color, const IRECT &bounds, const IBlend *pBlend=0)
Fill a rectangular region of the graphics context with a color.
Definition: IGraphics.cpp:2547
Control to test drawing arcs.
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1191
virtual void HideMouseCursor(bool hide=true, bool lock=true)=0
Call to hide/show the mouse cursor.
virtual void DrawTriangle(const IColor &color, float x1, float y1, float x2, float y2, float x3, float y3, const IBlend *pBlend=0, float thickness=1.f)
Draw a triangle to the graphics context.
Definition: IGraphics.cpp:2468
double GetValue(int valIdx=0) const
Get the control's value.
Definition: IControl.cpp:151
IGraphics * GetUI()
Definition: IControl.h:452
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
Definition: IControl.cpp:808
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
Definition: IControl.cpp:797
void Draw(IGraphics &g) override
Draw the control to the graphics context.
virtual void DrawArc(const IColor &color, float cx, float cy, float r, float a1, float a2, const IBlend *pBlend=0, float thickness=1.f)
Draw an arc to the graphics context.
Definition: IGraphics.cpp:2503
virtual void FillTriangle(const IColor &color, float x1, float y1, float x2, float y2, float x3, float y3, const IBlend *pBlend=0)
Fill a triangle with a color.
Definition: IGraphics.cpp:2540