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.

58 lines
1.0KB

  1. #pragma once
  2. #include <memory>
  3. #include <nanovg.h>
  4. #include <nanosvg.h>
  5. #include <common.hpp>
  6. #include <math.hpp>
  7. namespace rack {
  8. static const float SVG_DPI = 75.f;
  9. static const float MM_PER_IN = 25.4f;
  10. /** Converts inch measurements to pixels */
  11. inline float in2px(float in) {
  12. return in * SVG_DPI;
  13. }
  14. inline math::Vec in2px(math::Vec in) {
  15. return in.mult(SVG_DPI);
  16. }
  17. /** Converts millimeter measurements to pixels */
  18. inline float mm2px(float mm) {
  19. return mm * (SVG_DPI / MM_PER_IN);
  20. }
  21. inline math::Vec mm2px(math::Vec mm) {
  22. return mm.mult(SVG_DPI / MM_PER_IN);
  23. }
  24. struct Svg {
  25. NSVGimage* handle = NULL;
  26. ~Svg();
  27. /** Don't call this directly. Use `Svg::load()` for caching. */
  28. void loadFile(const std::string& filename);
  29. /** Loads SVG data from a string. */
  30. void loadString(const std::string& str);
  31. void draw(NVGcontext* vg);
  32. /** Loads Svg from a cache. */
  33. static std::shared_ptr<Svg> load(const std::string& filename);
  34. };
  35. DEPRECATED typedef Svg SVG;
  36. void svgDraw(NVGcontext* vg, NSVGimage* svg);
  37. } // namespace rack