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.

40 lines
648B

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