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.

49 lines
1.0KB

  1. #pragma once
  2. #include "app/common.hpp"
  3. #include "widgets/TransparentWidget.hpp"
  4. #include "widgets/FramebufferWidget.hpp"
  5. #include "widgets/SVGWidget.hpp"
  6. namespace rack {
  7. struct PanelBorder : TransparentWidget {
  8. void draw(NVGcontext *vg) override {
  9. NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5);
  10. nvgBeginPath(vg);
  11. nvgRect(vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0);
  12. nvgStrokeColor(vg, borderColor);
  13. nvgStrokeWidth(vg, 1.0);
  14. nvgStroke(vg);
  15. }
  16. };
  17. struct SVGPanel : FramebufferWidget {
  18. void step() override {
  19. if (isNear(gPixelRatio, 1.0)) {
  20. // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer
  21. oversample = 2.0;
  22. }
  23. FramebufferWidget::step();
  24. }
  25. void setBackground(std::shared_ptr<SVG> svg) {
  26. SVGWidget *sw = new SVGWidget;
  27. sw->setSVG(svg);
  28. addChild(sw);
  29. // Set size
  30. box.size = sw->box.size.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE);
  31. PanelBorder *pb = new PanelBorder;
  32. pb->box.size = box.size;
  33. addChild(pb);
  34. }
  35. };
  36. } // namespace rack