VCV Rack API v2
Loading...
Searching...
No Matches
Window.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <memory>
4#include <map>
5
6#include <common.hpp>
7#include <math.hpp>
8#include <window/Svg.hpp>
9
10#define GLEW_STATIC
11#define GLEW_NO_GLU
12#include <GL/glew.h>
13#include <GLFW/glfw3.h>
14#include <nanovg.h>
15#define NANOVG_GL2
16#include <nanovg_gl.h>
17#include <nanovg_gl_utils.h>
18
19
20namespace rack {
23namespace window {
24
25
26// Constructing these directly will load from the disk each time. Use the load() functions to load from disk and cache them as long as the shared_ptr is held.
27
29struct Font {
30 NVGcontext* vg;
31 int handle = -1;
32
35 void loadFile(const std::string& filename, NVGcontext* vg);
37 DEPRECATED static std::shared_ptr<Font> load(const std::string& filename);
38};
39
40
42struct Image {
43 NVGcontext* vg;
44 int handle = -1;
45
48 void loadFile(const std::string& filename, NVGcontext* vg);
50 DEPRECATED static std::shared_ptr<Image> load(const std::string& filename);
51};
52
53
55struct Window {
56 struct Internal;
57 Internal* internal;
58
59 GLFWwindow* win = NULL;
60 NVGcontext* vg = NULL;
61 NVGcontext* fbVg = NULL;
63 float pixelRatio = 1.f;
67 float windowRatio = 1.f;
68 std::shared_ptr<Font> uiFont;
69
73 void setSize(math::Vec size);
74 PRIVATE void run();
75 PRIVATE void step();
77 PRIVATE void screenshot(const std::string& screenshotPath);
81 PRIVATE void screenshotModules(const std::string& screenshotsDir, float zoom = 1.f);
83 void close();
84 void cursorLock();
90 int getMods();
91 void setFullScreen(bool fullScreen);
98 double getFrameTime();
105
109 std::shared_ptr<Font> loadFont(const std::string& filename);
113 std::shared_ptr<Image> loadImage(const std::string& filename);
117 std::shared_ptr<Svg> loadSvg(const std::string& filename) {
118 return Svg::load(filename);
119 }
120
123};
124
125
128
129
130} // namespace window
131} // namespace rack
#define PRIVATE
Attribute for private functions not intended to be called by plugins.
Definition common.hpp:30
#define DEPRECATED
Attribute for deprecated functions and symbols.
Definition common.hpp:24
const char * filename
Definition logger.hpp:41
PRIVATE void init()
PRIVATE void destroy()
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
Text font loaded in a particular Window context.
Definition Window.hpp:29
int handle
Definition Window.hpp:31
NVGcontext * vg
Definition Window.hpp:30
static DEPRECATED std::shared_ptr< Font > load(const std::string &filename)
Use APP->window->loadFont() instead.
void loadFile(const std::string &filename, NVGcontext *vg)
Don't call this directly but instead use APP->window->loadFont()
Bitmap/raster image loaded in a particular Window context.
Definition Window.hpp:42
NVGcontext * vg
Definition Window.hpp:43
int handle
Definition Window.hpp:44
void loadFile(const std::string &filename, NVGcontext *vg)
Don't call this directly but instead use APP->window->loadImage()
static DEPRECATED std::shared_ptr< Image > load(const std::string &filename)
Use APP->window->loadImage() instead.
static std::shared_ptr< Svg > load(const std::string &filename)
Loads Svg from a cache.
OS window with OpenGL context.
Definition Window.hpp:55
void setFullScreen(bool fullScreen)
PRIVATE void screenshotModules(const std::string &screenshotsDir, float zoom=1.f)
Saves a PNG image of all modules to screenshotsDir/<plugin slug>/<module slug>.png.
std::shared_ptr< Svg > loadSvg(const std::string &filename)
Loads and caches an Svg from a file path.
Definition Window.hpp:117
void close()
Request Window to be closed after rendering the current frame.
PRIVATE void screenshot(const std::string &screenshotPath)
Takes a screenshot of the screen and saves it to a PNG file.
int getMods()
Gets the current keyboard mod state Don't call this from a Key event.
double getFrameDurationRemaining()
Returns the current time remaining in seconds until the frame deadline, according to the frame rate l...
double getLastFrameDuration()
Returns the total time in seconds spent rendering the last frame.
std::shared_ptr< Image > loadImage(const std::string &filename)
Loads and caches an Image from a file path.
float pixelRatio
UI scaling ratio.
Definition Window.hpp:63
PRIVATE void run()
std::shared_ptr< Font > uiFont
Definition Window.hpp:68
GLFWwindow * win
Definition Window.hpp:59
PRIVATE bool & fbDirtyOnSubpixelChange()
NVGcontext * vg
Definition Window.hpp:60
double getMonitorRefreshRate()
Returns the primary monitor's refresh rate in Hz.
double getFrameTime()
Returns the timestamp of the beginning of the current frame render process.
void setSize(math::Vec size)
PRIVATE int & fbCount()
NVGcontext * fbVg
Definition Window.hpp:61
float windowRatio
Ratio between the framebuffer size and the window size reported by the OS.
Definition Window.hpp:67
std::shared_ptr< Font > loadFont(const std::string &filename)
Loads and caches a Font from a file path.
PRIVATE void step()
Internal * internal
Definition Window.hpp:57