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.

46 lines
1.2KB

  1. #include "global_pre.hpp"
  2. #include "ValleyWidgets.hpp"
  3. #include "global_ui.hpp"
  4. void PanelBorderWidget::draw(NVGcontext *vg) {
  5. NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5);
  6. nvgBeginPath(vg);
  7. nvgRect(vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0);
  8. nvgStrokeColor(vg, borderColor);
  9. nvgStrokeWidth(vg, 1.0);
  10. nvgStroke(vg);
  11. }
  12. DynamicPanelWidget::DynamicPanelWidget() {
  13. mode = nullptr;
  14. oldMode = -1;
  15. visiblePanel = new SVGWidget();
  16. addChild(visiblePanel);
  17. border = new PanelBorderWidget();
  18. addChild(border);
  19. }
  20. void DynamicPanelWidget::addPanel(std::shared_ptr<SVG> svg) {
  21. panels.push_back(svg);
  22. if(!visiblePanel->svg) {
  23. visiblePanel->setSVG(svg);
  24. box.size = visiblePanel->box.size.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE);
  25. border->box.size = box.size;
  26. }
  27. }
  28. void DynamicPanelWidget::step() {
  29. #ifdef USE_VST2
  30. if (isNear(rack::global_ui->window.gPixelRatio, 1.0)) {
  31. #else
  32. if (isNear(gPixelRatio, 1.0)) {
  33. #endif // USE_VST2
  34. oversample = 2.f;
  35. }
  36. if(mode != nullptr && *mode != oldMode) {
  37. visiblePanel->setSVG(panels[*mode]);
  38. oldMode = *mode;
  39. dirty = true;
  40. }
  41. }