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.

50 lines
1.1KB

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