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.

42 lines
929B

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