iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
TestMultiPathControl.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 TestMultiPathControl(IRECT rect, int paramIdx = kNoParameter)
26 : IKnobControlBase(rect, paramIdx)
27 , mShape(0)
28 {
29 SetTooltip("TestMultiPathControl");
30 }
31
32 void Draw(IGraphics& g) override
33 {
34 g.DrawDottedRect(COLOR_BLACK, mRECT);
35
36 const float value = static_cast<float>(GetValue());
37
38 float r0 = value * (mRECT.H() / 2.f);
39 float l = mRECT.L + mRECT.W() * 0.1f;
40 float r = mRECT.L + mRECT.W() * 0.9f;
41 float t = mRECT.T + mRECT.H() * 0.1f;
42 float b = mRECT.T + mRECT.H() * 0.9f;
43 float l0 = mRECT.L + mRECT.W() * 0.2f;
44 float t0 = mRECT.T + mRECT.H() * 0.3f;
45 float b0 = mRECT.T + mRECT.H() * 0.7f;
46 float mx = mRECT.L + mRECT.W() * 0.43f;
47 float my = mRECT.MH();
48
49 if (mShape == 0)
50 {
51 g.PathCircle(mRECT.MW(), mRECT.MH(), r0);
52 g.PathCircle(mRECT.MW(), mRECT.MH(), r0 * 0.5f);
53 }
54 else if (mShape == 1)
55 {
56 float pad1 = (mRECT.W() / 2.f) * (1.f - value);
57 float pad2 = (mRECT.H() / 2.f) * (1.f - value);
58 IRECT size1 = mRECT.GetPadded(-pad1, -pad2, -pad1, -pad2);
59 pad1 = (size1.W() / 2.f) * (1.f - value);
60 pad2 = (size1.H() / 2.f) * (1.f - value);
61 IRECT size2 = size1.GetPadded(-pad1, -pad2, -pad1, -pad2);
62 g.PathRect(size1);
63 g.PathRect(size2);
64 }
65 else if (mShape == 2)
66 {
67 float pad1 = (mRECT.W() / 2.f) * (1.f - value);
68 float pad2 = (mRECT.H() / 2.f) * (1.f - value);
69 IRECT size1 = mRECT.GetPadded(-pad1, -pad2, -pad1, -pad2);
70 pad1 = (size1.W() / 2.f) * (1.f - value);
71 pad2 = (size1.H() / 2.f) * (1.f - value);
72 IRECT size2 = size1.GetPadded(-pad1, -pad2, -pad1, -pad2);
73 g.PathRoundRect(size1, size1.H() * 0.125f);
74 g.PathRoundRect(size2, size2.H() * 0.125f);
75 }
76 else if (mShape == 3)
77 {
78 g.PathMoveTo(mRECT.L, mRECT.B);
79 g.PathCubicBezierTo(mRECT.L + mRECT.W() * 0.125f, mRECT.T + mRECT.H() * 0.725f, mRECT.L + mRECT.W() * 0.25f, mRECT.T + mRECT.H() * 0.35f, mRECT.MW(), mRECT.MH());
80 g.PathLineTo(mRECT.MW(), mRECT.B);
81 g.PathClose();
82 }
83 else if (mShape == 4)
84 {
85 g.PathMoveTo(l, b);
86 g.PathLineTo(l, t);
87 g.PathLineTo(r, t);
88 g.PathLineTo(l0, b0);
89 g.PathLineTo(l0, t0);
90 g.PathLineTo(r, b);
91 g.PathClose();
92 }
93 else if (mShape == 5)
94 {
95 g.PathMoveTo(l, b);
96 g.PathLineTo(l, t);
97 g.PathLineTo(r, t);
98 g.PathLineTo(mx, my);
99 g.PathLineTo(l0, t0);
100 g.PathLineTo(l0, b0);
101 g.PathLineTo(mx, my);
102 g.PathLineTo(r, b);
103 g.PathClose();
104 }
105 else if (mShape == 6)
106 {
107 g.PathMoveTo(l, b);
108 g.PathLineTo(l, t);
109 g.PathLineTo(r, t);
110 g.PathLineTo(mx, my);
111 g.PathLineTo(r, b);
112 g.PathClose();
113 g.PathMoveTo(l0, b0);
114 g.PathLineTo(l0, t0);
115 g.PathLineTo(mx, my);
116 g.PathClose();
117 }
118 else if (mShape == 7)
119 {
120 g.PathMoveTo(l, b);
121 g.PathLineTo(l, t);
122 g.PathLineTo(r, t);
123 g.PathLineTo(mx, my);
124 g.PathLineTo(r, b);
125 g.PathClose();
126 g.PathMoveTo(l0, t0);
127 g.PathLineTo(l0, b0);
128 g.PathLineTo(mx, my);
129 g.PathClose();
130 }
131 else if (mShape == 8)
132 {
133 float centerX = mRECT.MW();
134 float centerY = mRECT.MH();
135 float radius = mRECT.W() * 0.25f;
136 float width = radius * 0.75f;
137 float startAngle = -90.0f;
138 float endAngle = +90.0f;
139
140 g.PathArc(centerX, centerY, radius - width * 0.5f, startAngle, endAngle);
141 g.PathArc(centerX, centerY, radius + width * 0.5f, endAngle, startAngle, EWinding::CCW);
142 g.PathClose();
143 }
144 else
145 {
146 float centerX = mRECT.MW();
147 float centerY = mRECT.MH();
148 float radius = mRECT.W() * 0.25f;
149 float width = radius * 0.75f;
150 float startAngle = -90.0f;
151 float endAngle = +90.0f;
152
153 g.PathArc(centerX, centerY, radius - width * 0.5f, startAngle, endAngle);
154 g.PathArc(centerX, centerY, radius + width * 0.5f, endAngle, startAngle, EWinding::CW);
155 g.PathClose();
156 }
157
158 IFillOptions fillOptions;
159 fillOptions.mFillRule = value > 0.5 ? EFillRule::EvenOdd : EFillRule::Winding;
160 fillOptions.mPreserve = true;
161 IStrokeOptions strokeOptions;
162 float dashes[] = { 11, 4, 7 };
163 strokeOptions.mDash.SetDash(dashes, 0.0, 2);
164 g.PathFill(COLOR_BLACK, fillOptions);
165 g.PathStroke(COLOR_WHITE, 1, strokeOptions);
166 }
167
168 void OnMouseDown(float x, float y, const IMouseMod& mod) override
169 {
170 if (++mShape > 9)
171 mShape = 0;
172
173 SetDirty(false);
174 }
175
176private:
177 int mShape;
178};
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
virtual void PathFill(const IPattern &pattern, const IFillOptions &options=IFillOptions(), const IBlend *pBlend=0)=0
Fill the current current path.
void PathRoundRect(const IRECT &bounds, float ctl, float ctr, float cbl, float cbr)
Add a rounded rectangle to the current path, with independent corner roundness.
Definition: IGraphics.cpp:2644
virtual void PathClose()=0
Close the path that is being specified.
void PathRect(const IRECT &bounds)
Add a rectangle to the current path.
Definition: IGraphics.cpp:2635
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
virtual void PathStroke(const IPattern &pattern, float thickness, const IStrokeOptions &options=IStrokeOptions(), const IBlend *pBlend=0)=0
Stroke the current current path.
void PathCircle(float cx, float cy, float r)
Add a circle to the current path.
Definition: IGraphics.cpp:2688
virtual void PathMoveTo(float x, float y)=0
Move the current point in the current path.
virtual void PathArc(float cx, float cy, float r, float a1, float a2, EWinding winding=EWinding::CW)=0
Add an arc to the current path.
virtual void PathLineTo(float x, float y)=0
Add a line to the current path from the current point to the specified location.
virtual void PathCubicBezierTo(float c1x, float c1y, float c2x, float c2y, float x2, float y2)=0
Add a cubic bezier to the current path from the current point to the specified location.
A base class for knob/dial controls, to handle mouse action and Sender.
Definition: IControl.h:1368
Control to test drawing paths in path-based drawing backends.
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 stroke behaviour for path based drawing back ends.
Used to manage fill behaviour.
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.