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.

105 lines
2.6KB

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