You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

198 lines
4.4KB

  1. #include "widgets.hpp"
  2. #include "dsp/signal.hpp"
  3. using namespace bogaudio;
  4. using namespace bogaudio::dsp;
  5. Button18::Button18() {
  6. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_0.svg")));
  7. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_1.svg")));
  8. box.size = Vec(18, 18);
  9. }
  10. BGKnob::BGKnob(const char* svg, int dim) {
  11. setSVG(SVG::load(assetPlugin(plugin, svg)));
  12. box.size = Vec(dim, dim);
  13. shadow->blurRadius = 2.0;
  14. // k->shadow->opacity = 0.15;
  15. shadow->box.pos = Vec(0.0, 3.0);
  16. }
  17. Knob16::Knob16() : BGKnob("res/knob_16px.svg", 16) {
  18. shadow->box.pos = Vec(0.0, 2.5);
  19. }
  20. Knob19::Knob19() : BGKnob("res/knob_19px.svg", 19) {
  21. shadow->box.pos = Vec(0.0, 2.5);
  22. }
  23. Knob26::Knob26() : BGKnob("res/knob_26px.svg", 26) {
  24. }
  25. Knob29::Knob29() : BGKnob("res/knob_29px.svg", 29) {
  26. }
  27. Knob38::Knob38() : BGKnob("res/knob_38px.svg", 38) {
  28. }
  29. Knob45::Knob45() : BGKnob("res/knob_45px.svg", 45) {
  30. }
  31. Knob68::Knob68() : BGKnob("res/knob_68px.svg", 68) {
  32. shadow->box.pos = Vec(0.0, 4.0);
  33. }
  34. Port24::Port24() {
  35. setSVG(SVG::load(assetPlugin(plugin, "res/port.svg")));
  36. box.size = Vec(24, 24);
  37. shadow->blurRadius = 1.0;
  38. shadow->box.pos = Vec(0.0, 1.5);
  39. }
  40. SliderSwitch::SliderSwitch() {
  41. shadow = new CircularShadow();
  42. addChild(shadow);
  43. shadow->box.size = Vec();
  44. }
  45. SliderSwitch2State14::SliderSwitch2State14() {
  46. addFrame(SVG::load(assetPlugin(plugin, "res/slider_switch_2_14px_0.svg")));
  47. addFrame(SVG::load(assetPlugin(plugin, "res/slider_switch_2_14px_1.svg")));
  48. shadow->box.size = Vec(14.0, 24.0);
  49. shadow->blurRadius = 1.0;
  50. shadow->box.pos = Vec(0.0, 7.0);
  51. }
  52. StatefulButton::StatefulButton(const char* offSVGPath, const char* onSVGPath) {
  53. shadow = new CircularShadow();
  54. addChild(shadow);
  55. _svgWidget = new SVGWidget();
  56. addChild(_svgWidget);
  57. auto svg = SVG::load(assetPlugin(plugin, offSVGPath));
  58. _frames.push_back(svg);
  59. _frames.push_back(SVG::load(assetPlugin(plugin, onSVGPath)));
  60. _svgWidget->setSVG(svg);
  61. box.size = _svgWidget->box.size;
  62. shadow->box.size = _svgWidget->box.size;
  63. shadow->blurRadius = 1.0;
  64. shadow->box.pos = Vec(0.0, 1.0);
  65. }
  66. void StatefulButton::step() {
  67. FramebufferWidget::step();
  68. }
  69. void StatefulButton::onDragStart(EventDragStart& e) {
  70. _svgWidget->setSVG(_frames[1]);
  71. dirty = true;
  72. if (value >= maxValue) {
  73. setValue(minValue);
  74. }
  75. else {
  76. setValue(value + 1.0);
  77. }
  78. }
  79. void StatefulButton::onDragEnd(EventDragEnd& e) {
  80. _svgWidget->setSVG(_frames[0]);
  81. dirty = true;
  82. }
  83. StatefulButton9::StatefulButton9() : StatefulButton("res/button_9px_0.svg", "res/button_9px_1.svg") {
  84. }
  85. StatefulButton18::StatefulButton18() : StatefulButton("res/button_18px_0.svg", "res/button_18px_1.svg") {
  86. }
  87. ToggleButton18::ToggleButton18() {
  88. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_0.svg")));
  89. addFrame(SVG::load(assetPlugin(plugin, "res/button_18px_1.svg")));
  90. }
  91. NVGcolor bogaudio::decibelsToColor(float db) {
  92. if (db < -80.0f) {
  93. return nvgRGBA(0x00, 0x00, 0x00, 0x00);
  94. }
  95. if (db < -24.0f) {
  96. return nvgRGBA(0x55, 0xff, 0x00, (1.0f - (db + 24.0f) / -56.0f) * (float)0xff);
  97. }
  98. if (db < 0.0f) {
  99. return nvgRGBA((1.0f - db / -24.0f) * 0xff, 0xff, 0x00, 0xff);
  100. }
  101. #ifdef _MSC_VER
  102. #define sMIN(a,b) (((a)>(b))?(b):(a))
  103. return nvgRGBA(0xff, (1.0f - sMIN(db, 9.0f) / 9.0f) * 0xff, 0x00, 0xff);
  104. #else
  105. return nvgRGBA(0xff, (1.0f - std::min(db, 9.0f) / 9.0f) * 0xff, 0x00, 0xff);
  106. #endif
  107. }
  108. void VUSlider::draw(NVGcontext* vg) {
  109. nvgSave(vg);
  110. {
  111. nvgBeginPath(vg);
  112. nvgRoundedRect(vg, 6, 3, 6, box.size.y - 6, 2);
  113. nvgFillColor(vg, nvgRGBA(0x22, 0x22, 0x22, 0xff));
  114. nvgFill(vg);
  115. nvgStrokeColor(vg, nvgRGBA(0x88, 0x88, 0x88, 0xff));
  116. nvgStroke(vg);
  117. }
  118. nvgRestore(vg);
  119. nvgSave(vg);
  120. {
  121. nvgTranslate(vg, 0, (box.size.y - 13.0f) * (1.0f - value));
  122. nvgBeginPath(vg);
  123. nvgRoundedRect(vg, 0, 0, 18, 13, 1.5);
  124. nvgFillColor(vg, nvgRGBA(0x77, 0x77, 0x77, 0xff));
  125. nvgFill(vg);
  126. nvgBeginPath(vg);
  127. nvgRect(vg, 0, 2, 18, 9);
  128. nvgFillColor(vg, nvgRGBA(0x44, 0x44, 0x44, 0xff));
  129. nvgFill(vg);
  130. nvgBeginPath(vg);
  131. nvgRect(vg, 0, 6, 18, 1);
  132. nvgFillColor(vg, nvgRGBA(0xfa, 0xfa, 0xfa, 0xff));
  133. nvgFill(vg);
  134. nvgBeginPath(vg);
  135. nvgRoundedRect(vg, 2, 4, 14, 5, 1.0);
  136. nvgFillColor(vg, nvgRGBA(0xaa, 0xaa, 0xaa, 0xff));
  137. nvgFill(vg);
  138. float db = _vuLevel ? *_vuLevel : 0.0f;
  139. if (db > 0.0f) {
  140. db = amplitudeToDecibels(db);
  141. nvgBeginPath(vg);
  142. nvgRoundedRect(vg, 2, 4, 14, 5, 1.0);
  143. nvgFillColor(vg, decibelsToColor(db));
  144. nvgFill(vg);
  145. }
  146. }
  147. nvgRestore(vg);
  148. }