iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
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{
24public:
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);
67 }
68
69private:
70 float mAngle1;
71 float mAngle2;
72};
This file contains the base IControl implementation, along with some base classes for specific types ...
IGraphics * GetUI()
Definition: IControl.h:467
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
The lowest level base class of an IGraphics context.
Definition: IGraphics.h:86
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:2497
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 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:2569
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:2525
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:2532
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:2562
virtual void HideMouseCursor(bool hide=true, bool lock=true)=0
Call to hide/show the mouse cursor.
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:2597
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:2490
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
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1368
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:799
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:810
Control to test drawing arcs.
void OnMouseUp(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse up event on this control.
void Draw(IGraphics &g) override
Draw the control to the graphics context.
void OnMouseDown(float x, float y, const IMouseMod &mod) override
Implement this method to respond to a mouse down event on this control.
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 MW() const
IRECT GetPadded(float padding) const
Get a copy of this IRECT with each value padded by padding N.B.