forked from VCVRack/Rack
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.hpp
155 lines (133 loc) · 3.96 KB
/
helpers.hpp
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
#pragma once
#include <plugin/Model.hpp>
#include <ui/MenuOverlay.hpp>
#include <ui/MenuItem.hpp>
#include <ui/MenuLabel.hpp>
#include <ui/Menu.hpp>
#include <app/PortWidget.hpp>
#include <app/ParamWidget.hpp>
#include <app/Scene.hpp>
#include <engine/Module.hpp>
#include <engine/ParamQuantity.hpp>
#include <app.hpp>
#include <window.hpp>
namespace rack {
template <class TModule, class TModuleWidget, typename... Tags>
plugin::Model *createModel(const std::string &slug) {
struct TModel : plugin::Model {
engine::Module *createModule() override {
engine::Module *m = new TModule;
m->model = this;
return m;
}
app::ModuleWidget *createModuleWidget() override {
TModule *m = new TModule;
m->engine::Module::model = this;
app::ModuleWidget *mw = new TModuleWidget(m);
mw->model = this;
return mw;
}
app::ModuleWidget *createModuleWidgetNull() override {
app::ModuleWidget *mw = new TModuleWidget(NULL);
mw->model = this;
return mw;
}
};
plugin::Model *o = new TModel;
o->slug = slug;
return o;
}
template <class TWidget>
TWidget *createWidget(math::Vec pos) {
TWidget *o = new TWidget;
o->box.pos = pos;
return o;
}
template <class TWidget>
TWidget *createWidgetCentered(math::Vec pos) {
TWidget *o = createWidget<TWidget>(pos);
o->box.pos = o->box.pos.minus(o->box.size.div(2));
return o;
}
template <class TParamWidget>
TParamWidget *createParam(math::Vec pos, engine::Module *module, int paramId) {
TParamWidget *o = new TParamWidget;
o->box.pos = pos;
if (module) {
o->paramQuantity = module->paramQuantities[paramId];
}
return o;
}
template <class TParamWidget>
TParamWidget *createParamCentered(math::Vec pos, engine::Module *module, int paramId) {
TParamWidget *o = createParam<TParamWidget>(pos, module, paramId);
o->box.pos = o->box.pos.minus(o->box.size.div(2));
return o;
}
template <class TPortWidget>
TPortWidget *createInput(math::Vec pos, engine::Module *module, int inputId) {
TPortWidget *o = new TPortWidget;
o->box.pos = pos;
o->module = module;
o->type = app::PortWidget::INPUT;
o->portId = inputId;
return o;
}
template <class TPortWidget>
TPortWidget *createInputCentered(math::Vec pos, engine::Module *module, int inputId) {
TPortWidget *o = createInput<TPortWidget>(pos, module, inputId);
o->box.pos = o->box.pos.minus(o->box.size.div(2));
return o;
}
template <class TPortWidget>
TPortWidget *createOutput(math::Vec pos, engine::Module *module, int outputId) {
TPortWidget *o = new TPortWidget;
o->box.pos = pos;
o->module = module;
o->type = app::PortWidget::OUTPUT;
o->portId = outputId;
return o;
}
template <class TPortWidget>
TPortWidget *createOutputCentered(math::Vec pos, engine::Module *module, int outputId) {
TPortWidget *o = createOutput<TPortWidget>(pos, module, outputId);
o->box.pos = o->box.pos.minus(o->box.size.div(2));
return o;
}
template <class TModuleLightWidget>
TModuleLightWidget *createLight(math::Vec pos, engine::Module *module, int firstLightId) {
TModuleLightWidget *o = new TModuleLightWidget;
o->box.pos = pos;
o->module = module;
o->firstLightId = firstLightId;
return o;
}
template <class TModuleLightWidget>
TModuleLightWidget *createLightCentered(math::Vec pos, engine::Module *module, int firstLightId) {
TModuleLightWidget *o = createLight<TModuleLightWidget>(pos, module, firstLightId);
o->box.pos = o->box.pos.minus(o->box.size.div(2));
return o;
}
template <class TMenuLabel = ui::MenuLabel>
TMenuLabel *createMenuLabel(std::string text) {
TMenuLabel *o = new TMenuLabel;
o->text = text;
return o;
}
template <class TMenuItem = ui::MenuItem>
TMenuItem *createMenuItem(std::string text, std::string rightText = "") {
TMenuItem *o = new TMenuItem;
o->text = text;
o->rightText = rightText;
return o;
}
template <class TMenu = ui::Menu>
TMenu *createMenu() {
TMenu *o = new TMenu;
o->box.pos = APP->window->mousePos;
ui::MenuOverlay *menuOverlay = new ui::MenuOverlay;
menuOverlay->addChild(o);
APP->scene->addChild(menuOverlay);
return o;
}
} // namespace rack