-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathControls.h
161 lines (144 loc) · 6.11 KB
/
Controls.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
//
// LabeledKnob.hpp
// EQ3
//
// Created by Andreas Pohl on 21/07/16.
//
//
#ifndef LabeledKnob_h
#define LabeledKnob_h
#include <iomanip>
#include <sstream>
#include "IControl.h"
#include "IPlugEasy.h"
struct Position {
Position(int x_, int y_) : x(x_), y(y_), start_x(x), start_y(y){};
void NewLine() {
x = start_x;
y += height;
}
void Next() { x += width; }
int x;
int y;
int start_x;
int start_y;
int width = 0;
int height = 0;
};
namespace LabeledKnob {
enum class LabelPosition { RIGHT, LEFT, BOTTOM };
void Create(IPlugHandler* pHandler, IGraphics* pGraphics, IBitmap* pImg, int idx, Position& position,
const std::string& name, const std::string& unit, double init, double min, double max, double shape,
LabelPosition labelPos, std::function<void(double)> onChangeHandler) {
auto* param = pHandler->GetIPlugBase()->GetParam(idx);
param->InitDouble(name.c_str(), init, min, max, 0.1, unit.c_str());
param->SetShape(shape);
int x = position.x;
int y = position.y;
int x_name, x_val, y_name, y_val, width;
IText::EAlign align;
switch (labelPos) {
case LabelPosition::RIGHT:
x_name = x_val = position.x + pImg->W + 5;
y_name = position.y + (pImg->H / pImg->N / 2 - 15);
width = 45;
align = IText::kAlignNear;
position.width = pImg->W + width + 10;
position.height = pImg->H / pImg->N + 5;
break;
case LabelPosition::LEFT:
x_name = x_val = position.x;
x += 50;
y_name = position.y + (pImg->H / pImg->N / 2 - 15);
width = 45;
align = IText::kAlignFar;
position.width = pImg->W + width + 10;
position.height = pImg->H / pImg->N + 5;
break;
case LabelPosition::BOTTOM:
x_name = x_val = position.x;
y_name = position.y + pImg->H / pImg->N;
width = pImg->W;
align = IText::kAlignCenter;
position.width = pImg->W + 5;
position.height = pImg->H / pImg->N + 20;
break;
}
if (name == "") {
y_val = y_name;
} else {
y_val = y_name + 20;
}
if (name != "") {
pGraphics->AttachControl(new ITextControl(
pHandler->GetIPlugBase(), IRECT(x_name, y_name, x_name + width, y_name + 15),
new IText(15, &COLOR_GRAY, "Courier", IText::kStyleBold, align, 0, IText::kQualityDefault), name.c_str()));
}
pGraphics->AttachControl(new IKnobMultiControl(pHandler->GetIPlugBase(), x, y, idx, pImg));
ITextControl* tc = new ITextControl(
pHandler->GetIPlugBase(), IRECT(x_val, y_val, x_val + width, y_val + 20),
new IText(12, &COLOR_GRAY, "Courier", IText::kStyleNormal, align, 0, IText::kQualityDefault), "");
pGraphics->AttachControl(tc);
pHandler->AddParamChangeHandler(idx, [param, unit, tc, onChangeHandler] {
double val = param->Value();
if (onChangeHandler) {
onChangeHandler(val);
}
int precision = 1;
std::string unit_str = unit;
if (unit == "Hz" && val >= 1000.) {
val /= 1000;
unit_str = "KHz";
precision = 2;
}
std::ostringstream s;
s << std::setprecision(precision) << std::fixed << val << unit_str;
tc->SetTextFromPlug(const_cast<char*>(s.str().c_str()));
});
position.Next();
}
} // LabeledKnob
namespace LabeledSwitch {
enum class LabelPosition { LEFT, TOP_BOTTOM };
void Create(IPlugHandler* pHandler, IGraphics* pGraphics, IBitmap* pImg, int idx, int x, int y, const std::string& name,
const std::string& offLabel, const std::string& onLabel, LabelPosition pos,
std::function<void(bool)> onChangeHandler) {
auto* param = pHandler->GetIPlugBase()->GetParam(idx);
param->InitBool(name.c_str(), false);
pGraphics->AttachControl(new ISwitchControl(pHandler->GetIPlugBase(), x + 60, y + 5, idx, pImg));
switch (pos) {
case LabelPosition::LEFT:
pGraphics->AttachControl(new ITextControl(
pHandler->GetIPlugBase(), IRECT(x, y + 10, x + 60, y + 10 + 15),
new IText(12, &COLOR_GRAY, "Courier", IText::kStyleNormal, IText::kAlignFar, 0, IText::kQualityDefault),
offLabel.c_str()));
pGraphics->AttachControl(new ITextControl(
pHandler->GetIPlugBase(), IRECT(x, y + 46, x + 60, y + 46 + 15),
new IText(12, &COLOR_GRAY, "Courier", IText::kStyleNormal, IText::kAlignFar, 0, IText::kQualityDefault),
onLabel.c_str()));
break;
case LabelPosition::TOP_BOTTOM:
pGraphics->AttachControl(new ITextControl(
pHandler->GetIPlugBase(), IRECT(x, y + 25, x + 56, y + 15),
new IText(15, &COLOR_GRAY, "Courier", IText::kStyleBold, IText::kAlignFar, 0, IText::kQualityDefault),
name.c_str()));
pGraphics->AttachControl(new ITextControl(pHandler->GetIPlugBase(),
IRECT(x + 75, y - 2, x + 75 + 30, y + 15),
new IText(12, &COLOR_GRAY, "Courier", IText::kStyleNormal,
IText::kAlignNear, 0, IText::kQualityDefault),
offLabel.c_str()));
pGraphics->AttachControl(new ITextControl(pHandler->GetIPlugBase(),
IRECT(x + 75, y + 56, x + 75 + 30, y + 60 + 15),
new IText(12, &COLOR_GRAY, "Courier", IText::kStyleNormal,
IText::kAlignNear, 0, IText::kQualityDefault),
onLabel.c_str()));
break;
}
pHandler->AddParamChangeHandler(idx, [param, onChangeHandler] {
if (onChangeHandler) {
onChangeHandler(param->Bool());
}
});
}
} // LabeledSwitch
#endif /* Controls_h */