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
919B

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