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

  1. #include <app/SvgPanel.hpp>
  2. namespace rack {
  3. namespace app {
  4. void PanelBorder::draw(const DrawArgs& args) {
  5. NVGcolor borderColor = nvgRGBAf(0.5, 0.5, 0.5, 0.5);
  6. nvgBeginPath(args.vg);
  7. nvgRect(args.vg, 0.5, 0.5, box.size.x - 1.0, box.size.y - 1.0);
  8. nvgStrokeColor(args.vg, borderColor);
  9. nvgStrokeWidth(args.vg, 1.0);
  10. nvgStroke(args.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. 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