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.

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