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.

59 lines
1.1KB

  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. /** Arbitrary DPI, standardized for Rack. */
  9. static const float SVG_DPI = 75.f;
  10. static const float MM_PER_IN = 25.4f;
  11. /** Converts inch measurements to pixels */
  12. inline float in2px(float in) {
  13. return in * SVG_DPI;
  14. }
  15. inline math::Vec in2px(math::Vec in) {
  16. return in.mult(SVG_DPI);
  17. }
  18. /** Converts millimeter measurements to pixels */
  19. inline float mm2px(float mm) {
  20. return mm * (SVG_DPI / MM_PER_IN);
  21. }
  22. inline math::Vec mm2px(math::Vec mm) {
  23. return mm.mult(SVG_DPI / MM_PER_IN);
  24. }
  25. struct Svg {
  26. NSVGimage* handle = NULL;
  27. ~Svg();
  28. /** Don't call this directly. Use `Svg::load()` for caching. */
  29. void loadFile(const std::string& filename);
  30. /** Loads SVG data from a string. */
  31. void loadString(const std::string& str);
  32. void draw(NVGcontext* vg);
  33. /** Loads Svg from a cache. */
  34. static std::shared_ptr<Svg> load(const std::string& filename);
  35. };
  36. DEPRECATED typedef Svg SVG;
  37. void svgDraw(NVGcontext* vg, NSVGimage* svg);
  38. } // namespace rack