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.

37 lines
572B

  1. #pragma once
  2. #include "widgets/Widget.hpp"
  3. namespace rack {
  4. /** Draws an SVG */
  5. struct SVGWidget : VirtualWidget {
  6. std::shared_ptr<SVG> svg;
  7. /** Sets the box size to the svg image size */
  8. void wrap() {
  9. if (svg && svg->handle) {
  10. box.size = Vec(svg->handle->width, svg->handle->height);
  11. }
  12. else {
  13. box.size = Vec();
  14. }
  15. }
  16. /** Sets and wraps the SVG */
  17. void setSVG(std::shared_ptr<SVG> svg) {
  18. this->svg = svg;
  19. wrap();
  20. }
  21. void draw(NVGcontext *vg) override {
  22. if (svg && svg->handle) {
  23. svgDraw(vg, svg->handle);
  24. }
  25. }
  26. };
  27. } // namespace rack