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.

48 lines
1000B

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