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.

106 lines
2.7KB

  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. // 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.
  18. struct Font {
  19. NVGcontext* vg;
  20. int handle = -1;
  21. /** Don't call this directly but instead use `APP->window->loadFont()` */
  22. void loadFile(const std::string& filename, NVGcontext* vg);
  23. ~Font();
  24. /** Use `APP->window->loadFont()` instead. */
  25. DEPRECATED static std::shared_ptr<Font> load(const std::string& filename);
  26. };
  27. struct Image {
  28. NVGcontext* vg;
  29. int handle = -1;
  30. /** Don't call this directly but instead use `APP->window->loadImage()` */
  31. void loadFile(const std::string& filename, NVGcontext* vg);
  32. ~Image();
  33. /** Use `APP->window->loadImage()` instead. */
  34. DEPRECATED static std::shared_ptr<Image> load(const std::string& filename);
  35. };
  36. struct Window {
  37. struct Internal;
  38. Internal* internal;
  39. GLFWwindow* win = NULL;
  40. NVGcontext* vg = NULL;
  41. NVGcontext* fbVg = NULL;
  42. /** The scaling ratio */
  43. float pixelRatio = 1.f;
  44. /* The ratio between the framebuffer size and the window size reported by the OS.
  45. This is not equal to gPixelRatio in general.
  46. */
  47. float windowRatio = 1.f;
  48. std::shared_ptr<Font> uiFont;
  49. Window();
  50. ~Window();
  51. math::Vec getSize();
  52. void setSize(math::Vec size);
  53. void run();
  54. void step();
  55. /** Takes a screenshot of the screen and saves it to a PNG file. */
  56. void screenshot(const std::string& screenshotPath);
  57. /** Saves a PNG image of all modules to `screenshotsDir/<plugin slug>/<module slug>.png`.
  58. Skips screenshot if the file already exists.
  59. */
  60. void screenshotModules(const std::string& screenshotsDir, float zoom = 1.f);
  61. void close();
  62. void cursorLock();
  63. void cursorUnlock();
  64. bool isCursorLocked();
  65. /** Gets the current keyboard mod state
  66. Don't call this from a Key event. Simply use `e.mods` instead.
  67. */
  68. int getMods();
  69. void setFullScreen(bool fullScreen);
  70. bool isFullScreen();
  71. double getMonitorRefreshRate();
  72. double getFrameTime();
  73. double getLastFrameDuration();
  74. double getFrameTimeOverdue();
  75. std::shared_ptr<Font> loadFont(const std::string& filename);
  76. std::shared_ptr<Image> loadImage(const std::string& filename);
  77. /** Use `Svg::load(filename)` in new code. */
  78. DEPRECATED std::shared_ptr<Svg> loadSvg(const std::string& filename) {
  79. return Svg::load(filename);
  80. }
  81. INTERNAL bool& fbDirtyOnSubpixelChange();
  82. };
  83. void windowInit();
  84. void windowDestroy();
  85. } // namespace rack