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.

112 lines
2.9KB

  1. #pragma once
  2. #include <memory>
  3. #include <map>
  4. #define GLEW_STATIC
  5. #define GLEW_NO_GLU
  6. #include <GL/glew.h>
  7. #include <GLFW/glfw3.h>
  8. #include <nanovg.h>
  9. #define NANOVG_GL2
  10. #include <nanovg_gl.h>
  11. #include <nanovg_gl_utils.h>
  12. #include <nanosvg.h>
  13. #include <svg.hpp>
  14. #include <common.hpp>
  15. #include <math.hpp>
  16. namespace rack {
  17. namespace window {
  18. // 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.
  19. /** Text font loaded in a particular Window context. */
  20. struct Font {
  21. NVGcontext* vg;
  22. int handle = -1;
  23. /** Don't call this directly but instead use `APP->window->loadFont()` */
  24. void loadFile(const std::string& filename, NVGcontext* vg);
  25. ~Font();
  26. /** Use `APP->window->loadFont()` instead. */
  27. DEPRECATED static std::shared_ptr<Font> load(const std::string& filename);
  28. };
  29. /** Bitmap/raster image loaded in a particular Window context. */
  30. struct Image {
  31. NVGcontext* vg;
  32. int handle = -1;
  33. /** Don't call this directly but instead use `APP->window->loadImage()` */
  34. void loadFile(const std::string& filename, NVGcontext* vg);
  35. ~Image();
  36. /** Use `APP->window->loadImage()` instead. */
  37. DEPRECATED static std::shared_ptr<Image> load(const std::string& filename);
  38. };
  39. struct Window {
  40. struct Internal;
  41. Internal* internal;
  42. GLFWwindow* win = NULL;
  43. NVGcontext* vg = NULL;
  44. NVGcontext* fbVg = NULL;
  45. /** The scaling ratio */
  46. float pixelRatio = 1.f;
  47. /* The ratio between the framebuffer size and the window size reported by the OS.
  48. This is not equal to gPixelRatio in general.
  49. */
  50. float windowRatio = 1.f;
  51. std::shared_ptr<Font> uiFont;
  52. Window();
  53. ~Window();
  54. math::Vec getSize();
  55. void setSize(math::Vec size);
  56. void run();
  57. void step();
  58. /** Takes a screenshot of the screen and saves it to a PNG file. */
  59. void screenshot(const std::string& screenshotPath);
  60. /** Saves a PNG image of all modules to `screenshotsDir/<plugin slug>/<module slug>.png`.
  61. Skips screenshot if the file already exists.
  62. */
  63. void screenshotModules(const std::string& screenshotsDir, float zoom = 1.f);
  64. /** Request Window to be closed after rendering the current frame. */
  65. void close();
  66. void cursorLock();
  67. void cursorUnlock();
  68. bool isCursorLocked();
  69. /** Gets the current keyboard mod state
  70. Don't call this from a Key event. Simply use `e.mods` instead.
  71. */
  72. int getMods();
  73. void setFullScreen(bool fullScreen);
  74. bool isFullScreen();
  75. double getMonitorRefreshRate();
  76. double getFrameTime();
  77. double getLastFrameDuration();
  78. double getFrameDurationRemaining();
  79. std::shared_ptr<Font> loadFont(const std::string& filename);
  80. std::shared_ptr<Image> loadImage(const std::string& filename);
  81. /** Use `Svg::load(filename)` in new code. */
  82. DEPRECATED std::shared_ptr<Svg> loadSvg(const std::string& filename) {
  83. return Svg::load(filename);
  84. }
  85. INTERNAL bool& fbDirtyOnSubpixelChange();
  86. };
  87. void init();
  88. void destroy();
  89. } // namespace window
  90. } // namespace rack