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.

SVGWidget.hpp 604B

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