BogaudioModules

BogaudioModules for VCV Rack
Log | Files | Refs | README | LICENSE

widgets.hpp (6755B)


      1 #pragma once
      2 
      3 #include "rack.hpp"
      4 #include "module.hpp"
      5 #include <functional>
      6 #include <string>
      7 
      8 using namespace rack;
      9 
     10 extern Plugin *pluginInstance;
     11 
     12 namespace bogaudio {
     13 
     14 template <class BASE>
     15 struct LightEmittingWidget : BASE {
     16 	virtual bool isLit() = 0;
     17 
     18 	void drawLayer(const typename BASE::DrawArgs& args, int layer) override {
     19 		if (layer == 1 && isLit()) {
     20 			drawLit(args);
     21 		}
     22 		BASE::drawLayer(args, layer);
     23 	}
     24 
     25 	virtual void drawLit(const typename BASE::DrawArgs& args) {}
     26 };
     27 
     28 struct DisplayWidget : LightEmittingWidget<OpaqueWidget> {
     29 	Module* _module = NULL;
     30 
     31 	DisplayWidget(Module* module);
     32 
     33 	bool isLit() override;
     34 	virtual bool isScreenshot();
     35 	void draw(const DrawArgs& args) override;
     36 	void drawLit(const DrawArgs& args) override;
     37 	virtual void drawOnce(const DrawArgs& args, bool screenshot, bool lit) = 0;
     38 };
     39 
     40 struct SkinnableWidget : SkinChangeListener {
     41 	void skinChanged(const std::string& skin) override {}
     42 	std::string skinSVG(const std::string& base, const std::string& skin = "default");
     43 };
     44 
     45 struct Screw : SvgScrew, SkinnableWidget {
     46 	Screw();
     47 
     48 	void skinChanged(const std::string& skin) override;
     49 };
     50 
     51 struct BGKnob : RoundKnob, SkinnableWidget {
     52 	std::string _svgBase;
     53 
     54 	BGKnob(const char* svgBase, int dim);
     55 
     56 	void redraw();
     57 	void skinChanged(const std::string& skin) override;
     58 };
     59 
     60 struct Knob16 : BGKnob {
     61 	Knob16();
     62 };
     63 
     64 struct Knob19 : BGKnob {
     65 	Knob19();
     66 };
     67 
     68 struct Knob26 : BGKnob {
     69 	Knob26();
     70 };
     71 
     72 struct Knob29 : BGKnob {
     73 	Knob29();
     74 };
     75 
     76 struct Knob38 : BGKnob {
     77 	Knob38();
     78 };
     79 
     80 struct Knob45 : BGKnob {
     81 	Knob45();
     82 };
     83 
     84 struct Knob68 : BGKnob {
     85 	Knob68();
     86 };
     87 
     88 struct IndicatorKnob : LightEmittingWidget<Knob>, SkinnableWidget {
     89 	struct IKWidget : widget::Widget {
     90 		float _angle = 0.0f;
     91 		NVGcolor _color = nvgRGBA(0x00, 0x00, 0x00, 0x00);
     92 		NVGcolor _rim = nvgRGBA(0x33, 0x33, 0x33, 0xff);
     93 		NVGcolor _center = nvgRGBA(0xee, 0xee, 0xee, 0xff);
     94 		std::function<bool()> _drawColorsCB;
     95 		std::function<bool()> _unipolarCB;
     96 
     97 		void setAngle(float a);
     98 		void draw(const DrawArgs& args) override;
     99 	};
    100 
    101 	widget::FramebufferWidget* fb;
    102 	CircularShadow* shadow;
    103 	IKWidget* w;
    104 
    105 	IndicatorKnob(int dim);
    106 	void onHover(const event::Hover& e) override;
    107 	void onLeave(const LeaveEvent& e) override;
    108 	void onChange(const event::Change& e) override;
    109 	inline void setDrawColorsCallback(std::function<bool()> fn) { w->_drawColorsCB = fn; }
    110 	inline void setUnipolarCallback(std::function<bool()> fn) { w->_unipolarCB = fn; }
    111 	void redraw();
    112 	bool isLit() override;
    113 	void draw(const DrawArgs& args) override;
    114 	void drawLit(const DrawArgs& args) override;
    115 	void skinChanged(const std::string& skin) override;
    116 };
    117 
    118 struct IndicatorKnob19 : IndicatorKnob {
    119 	IndicatorKnob19() : IndicatorKnob(19) {}
    120 };
    121 
    122 struct Port24 : SvgPort, SkinnableWidget {
    123 	Port24();
    124 
    125 	void skinChanged(const std::string& skin) override;
    126 };
    127 
    128 struct BlankPort24 : SvgPort {
    129 	BlankPort24();
    130 };
    131 
    132 struct SliderSwitch : SvgSwitch {
    133 	CircularShadow* shadow = NULL;
    134 	SliderSwitch();
    135 };
    136 
    137 struct SliderSwitch2State14 : SliderSwitch {
    138 	SliderSwitch2State14();
    139 };
    140 
    141 struct Button18 : SvgSwitch {
    142 	Button18();
    143 };
    144 
    145 struct StatefulButton : ParamWidget {
    146 	std::vector<std::shared_ptr<Svg>> _frames;
    147 	SvgWidget* _svgWidget; // deleted elsewhere.
    148 	CircularShadow* shadow = NULL;
    149 
    150 	StatefulButton(const char* offSvgPath, const char* onSvgPath);
    151 	void onDragStart(const event::DragStart& e) override;
    152 	void onDragEnd(const event::DragEnd& e) override;
    153 	void onDoubleClick(const event::DoubleClick& e) override {}
    154 };
    155 
    156 struct StatefulButton9 : StatefulButton {
    157 	StatefulButton9();
    158 };
    159 
    160 struct StatefulButton18 : StatefulButton {
    161 	StatefulButton18();
    162 };
    163 
    164 struct ToggleButton : SvgSwitch {
    165 };
    166 
    167 struct ToggleButton18 : ToggleButton {
    168 	ToggleButton18();
    169 };
    170 
    171 struct IndicatorButtonGreen9 : LightEmittingWidget<SvgSwitch> {
    172 	IndicatorButtonGreen9();
    173 
    174 	bool isLit() override;
    175 	void draw(const DrawArgs& args) override;
    176 	void drawLit(const DrawArgs& args) override;
    177 };
    178 
    179 struct InvertingIndicatorButton : LightEmittingWidget<ParamWidget> {
    180 	struct IIBWidget : widget::Widget {
    181 		int _dim;
    182 		NVGcolor _color = nvgRGBA(0x00, 0x00, 0x00, 0x00);
    183 
    184 		IIBWidget(int dim) : _dim(dim) {}
    185 
    186 		void setValue(float v);
    187 		void draw(const DrawArgs& args) override;
    188 	};
    189 
    190 	widget::FramebufferWidget* fb;
    191 	CircularShadow* shadow;
    192 	IIBWidget* w;
    193 	std::function<bool()> clickToInvertCB;
    194 	std::function<void(int, float)> onChangeCB;
    195 
    196 	InvertingIndicatorButton(int dim);
    197 
    198 	inline void setClickToInvertCallback(std::function<bool()> fn) { clickToInvertCB = fn; }
    199 	inline void setOnChangeCallback(std::function<void(int, float)> fn) { onChangeCB = fn; }
    200 	void onHover(const event::Hover& e) override;
    201 	void onDoubleClick(const event::DoubleClick& e) override {}
    202 	void onButton(const event::Button& e) override;
    203 	void onChange(const event::Change& e) override;
    204 	bool isLit() override;
    205 	void draw(const DrawArgs& args) override;
    206 	void drawLit(const DrawArgs& args) override;
    207 };
    208 
    209 struct InvertingIndicatorButton9 : InvertingIndicatorButton {
    210 	InvertingIndicatorButton9() : InvertingIndicatorButton(9) {}
    211 };
    212 
    213 struct InvertingIndicatorButton18 : InvertingIndicatorButton {
    214 	InvertingIndicatorButton18() : InvertingIndicatorButton(18) {}
    215 };
    216 
    217 NVGcolor decibelsToColor(float db);
    218 
    219 struct VUSlider : LightEmittingWidget<SliderKnob> {
    220 	const float slideHeight = 13.0f;
    221 	float* _vuLevel = NULL;
    222 	float* _stereoVuLevel = NULL;
    223 
    224 	VUSlider(float height = 183.0f) {
    225 		box.size = Vec(18.0f, height);
    226 	}
    227 
    228 	inline void setVULevel(float* level) {
    229 		_vuLevel = level;
    230 	}
    231 	inline void setStereoVULevel(float* level) {
    232 		_stereoVuLevel = level;
    233 	}
    234 	bool isLit() override;
    235 	void draw(const DrawArgs& args) override;
    236 	void drawLit(const DrawArgs& args) override;
    237 	void drawTranslate(const DrawArgs& args);
    238 };
    239 
    240 struct VUSlider151 : VUSlider {
    241 	VUSlider151() : VUSlider(151.0f) {}
    242 };
    243 
    244 template <typename TBase>
    245 struct BGTinyLight : TinyLight<TBase> {
    246 	void drawLight(const typename TinyLight<TBase>::DrawArgs& args) override {
    247 		if (!TinyLight<TBase>::module || !TinyLight<TBase>::module->isBypassed()) {
    248 			TinyLight<TBase>::drawLight(args);
    249 		}
    250 	}
    251 
    252 	void drawHalo(const typename TinyLight<TBase>::DrawArgs& args) override {
    253 		if (!TinyLight<TBase>::module || !TinyLight<TBase>::module->isBypassed()) {
    254 			TinyLight<TBase>::drawHalo(args);
    255 		}
    256 	}
    257 };
    258 
    259 template <typename TBase>
    260 struct BGSmallLight : SmallLight<TBase> {
    261 	void drawLight(const typename SmallLight<TBase>::DrawArgs& args) override {
    262 		if (!SmallLight<TBase>::module || !SmallLight<TBase>::module->isBypassed()) {
    263 			SmallLight<TBase>::drawLight(args);
    264 		}
    265 	}
    266 
    267 	void drawHalo(const typename SmallLight<TBase>::DrawArgs& args) override {
    268 		if (!SmallLight<TBase>::module || !SmallLight<TBase>::module->isBypassed()) {
    269 			SmallLight<TBase>::drawHalo(args);
    270 		}
    271 	}
    272 };
    273 
    274 } // namespace bogaudio