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 <common.hpp>
  3. #include <math.hpp>
  4. #include <memory>
  5. #include <map>
  6. #define GLEW_STATIC
  7. #define GLEW_NO_GLU
  8. #include <GL/glew.h>
  9. #include <GLFW/glfw3.h>
  10. #include <nanovg.h>
  11. #define NANOVG_GL2
  12. #include <nanovg_gl.h>
  13. #include <nanovg_gl_utils.h>
  14. #include <nanosvg.h>
  15. namespace rack {
  16. // 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.
  17. struct Font {
  18. NVGcontext* vg;
  19. int handle = -1;
  20. /** Don't call this directly but instead use `APP->window->loadFont()` */
  21. void loadFile(const std::string& filename, NVGcontext* vg);
  22. ~Font();
  23. /** Use `APP->window->loadFont()` instead. */
  24. DEPRECATED static std::shared_ptr<Font> load(const std::string& filename);
  25. };
  26. struct Image {
  27. NVGcontext* vg;
  28. int handle = -1;
  29. /** Don't call this directly but instead use `APP->window->loadImage()` */
  30. void loadFile(const std::string& filename, NVGcontext* vg);
  31. ~Image();
  32. /** Use `APP->window->loadImage()` instead. */
  33. DEPRECATED static std::shared_ptr<Image> load(const std::string& filename);
  34. };
  35. struct Svg {
  36. NSVGimage* handle = NULL;
  37. /** Don't call this directly but instead use `APP->window->loadSvg()` */
  38. void loadFile(const std::string& filename);
  39. ~Svg();
  40. /** Use `APP->window->loadSvg()` instead. */
  41. DEPRECATED static std::shared_ptr<Svg> load(const std::string& filename);
  42. };
  43. DEPRECATED typedef Svg SVG;
  44. struct Window {
  45. GLFWwindow* win = NULL;
  46. NVGcontext* vg = NULL;
  47. /** The scaling ratio */
  48. float pixelRatio = 1.f;
  49. /* The ratio between the framebuffer size and the window size reported by the OS.
  50. This is not equal to gPixelRatio in general.
  51. */
  52. float windowRatio = 1.f;
  53. int frame = 0;
  54. /** The last known absolute mouse position in the window */
  55. math::Vec mousePos;
  56. std::shared_ptr<Font> uiFont;
  57. double frameTimeStart = 0.f;
  58. /** Use load*() instead of modifying these directly. */
  59. std::map<std::string, std::weak_ptr<Font>> fontCache;
  60. std::map<std::string, std::weak_ptr<Image>> imageCache;
  61. std::map<std::string, std::weak_ptr<Svg>> svgCache;
  62. struct Internal;
  63. Internal* internal;
  64. Window();
  65. ~Window();
  66. void run();
  67. /** Takes a screenshot of each module */
  68. void screenshot(float zoom);
  69. void close();
  70. void cursorLock();
  71. void cursorUnlock();
  72. /** Gets the current keyboard mod state
  73. Don't call this from a Key event. Simply use `e.mods` instead.
  74. */
  75. int getMods();
  76. void setFullScreen(bool fullScreen);
  77. bool isFullScreen();
  78. bool isFrameOverdue();
  79. double getMonitorRefreshRate();
  80. std::shared_ptr<Font> loadFont(const std::string& filename);
  81. std::shared_ptr<Image> loadImage(const std::string& filename);
  82. std::shared_ptr<Svg> loadSvg(const std::string& filename);
  83. };
  84. void windowInit();
  85. void windowDestroy();
  86. } // namespace rack