VCV Rack API v2
Loading...
Searching...
No Matches
Svg.hpp
Go to the documentation of this file.
1#pragma once
2#include <memory>
3
4#include <nanovg.h>
5#include <nanosvg.h>
6
7#include <common.hpp>
8#include <math.hpp>
9
10
11namespace rack {
12namespace window {
13
14
16static const float SVG_DPI = 75.f;
17static const float MM_PER_IN = 25.4f;
18
19
21inline float in2px(float in) {
22 return in * SVG_DPI;
23}
24
26 return in.mult(SVG_DPI);
27}
28
30inline float mm2px(float mm) {
31 return mm * (SVG_DPI / MM_PER_IN);
32}
33
35 return mm.mult(SVG_DPI / MM_PER_IN);
36}
37
38
40struct Svg {
41 NSVGimage* handle = NULL;
42
45 void loadFile(const std::string& filename);
47 void loadString(const std::string& str);
53 void draw(NVGcontext* vg);
54
56 static std::shared_ptr<Svg> load(const std::string& filename);
57};
58
60
61
62void svgDraw(NVGcontext* vg, NSVGimage* svg);
63
64
65} // namespace window
66} // namespace rack
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:24
const char * filename
Definition logger.hpp:41
void svgDraw(NVGcontext *vg, NSVGimage *svg)
float mm2px(float mm)
Converts millimeter measurements to pixels.
Definition Svg.hpp:30
float in2px(float in)
Converts inch measurements to pixels.
Definition Svg.hpp:21
DEPRECATED typedef Svg SVG
Definition Svg.hpp:59
static const float MM_PER_IN
Definition Svg.hpp:17
static const float SVG_DPI
Arbitrary DPI, standardized for Rack.
Definition Svg.hpp:16
Root namespace for the Rack API.
Definition AudioDisplay.hpp:9
2-dimensional vector of floats, representing a point on the plane for graphics.
Definition math.hpp:189
Vec mult(float s) const
Definition math.hpp:215
Scalable Vector Graphics document.
Definition Svg.hpp:40
void draw(NVGcontext *vg)
void loadString(const std::string &str)
Loads SVG data from a string.
NSVGimage * handle
Definition Svg.hpp:41
static std::shared_ptr< Svg > load(const std::string &filename)
Loads Svg from a cache.
math::Vec getSize()
Returns the SVG page size in pixels.
void loadFile(const std::string &filename)
Don't call this directly.