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.

Window.hpp 2.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. /** Request Window to be closed after rendering the current frame. */
  62. void close();
  63. void cursorLock();
  64. void cursorUnlock();
  65. bool isCursorLocked();
  66. /** Gets the current keyboard mod state
  67. Don't call this from a Key event. Simply use `e.mods` instead.
  68. */
  69. int getMods();
  70. void setFullScreen(bool fullScreen);
  71. bool isFullScreen();
  72. double getMonitorRefreshRate();
  73. double getFrameTime();
  74. double getLastFrameDuration();
  75. double getFrameDurationRemaining();
  76. std::shared_ptr<Font> loadFont(const std::string& filename);
  77. std::shared_ptr<Image> loadImage(const std::string& filename);
  78. /** Use `Svg::load(filename)` in new code. */
  79. DEPRECATED std::shared_ptr<Svg> loadSvg(const std::string& filename) {
  80. return Svg::load(filename);
  81. }
  82. INTERNAL bool& fbDirtyOnSubpixelChange();
  83. };
  84. void windowInit();
  85. void windowDestroy();
  86. } // namespace rack