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.

62 lines
1.2KB

  1. #include <app/SvgPanel.hpp>
  2. #include <context.hpp>
  3. namespace rack {
  4. namespace app {
  5. void PanelBorder::draw(const DrawArgs& args) {
  6. NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5);
  7. nvgBeginPath(args.vg);
  8. nvgRect(args.vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0);
  9. nvgStrokeColor(args.vg, borderColor);
  10. nvgStrokeWidth(args.vg, 1.0);
  11. nvgStroke(args.vg);
  12. }
  13. SvgPanel::SvgPanel() {
  14. fb = new widget::FramebufferWidget;
  15. addChild(fb);
  16. sw = new widget::SvgWidget;
  17. fb->addChild(sw);
  18. panelBorder = new PanelBorder;
  19. fb->addChild(panelBorder);
  20. }
  21. void SvgPanel::step() {
  22. if (APP->window->pixelRatio < 2.0) {
  23. // Small details draw poorly at low DPI, so oversample when drawing to the framebuffer
  24. fb->oversample = 2.0;
  25. }
  26. else {
  27. fb->oversample = 1.0;
  28. }
  29. Widget::step();
  30. }
  31. void SvgPanel::setBackground(std::shared_ptr<window::Svg> svg) {
  32. if (svg == this->svg)
  33. return;
  34. this->svg = svg;
  35. sw->setSvg(svg);
  36. // Round framebuffer size to nearest grid
  37. fb->box.size = sw->box.size.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE);
  38. panelBorder->box.size = fb->box.size;
  39. box.size = fb->box.size;
  40. fb->setDirty();
  41. }
  42. } // namespace app
  43. } // namespace rack