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.

52 lines
1.0KB

  1. #include <app/SvgPanel.hpp>
  2. #include <settings.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. Widget::step();
  27. }
  28. void SvgPanel::setBackground(std::shared_ptr<window::Svg> svg) {
  29. this->svg = svg;
  30. sw->setSvg(svg);
  31. fb->box.size = sw->box.size.div(RACK_GRID_SIZE).round().mult(RACK_GRID_SIZE);
  32. panelBorder->box.size = fb->box.size;
  33. box.size = fb->box.size;
  34. }
  35. } // namespace app
  36. } // namespace rack