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.

114 lines
2.8KB

  1. #pragma once
  2. #include "common.hpp"
  3. #include "math.hpp"
  4. #include <memory>
  5. #define GLEW_STATIC
  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. /** Remaps Ctrl to Cmd on Mac
  14. Use this instead of GLFW_MOD_CONTROL, since Cmd should be used on Mac in place of Ctrl on Linux/Windows.
  15. */
  16. #if defined ARCH_MAC
  17. #define WINDOW_MOD_CTRL GLFW_MOD_SUPER
  18. #define WINDOW_MOD_CTRL_NAME "Cmd"
  19. #else
  20. #define WINDOW_MOD_CTRL GLFW_MOD_CONTROL
  21. #define WINDOW_MOD_CTRL_NAME "Ctrl"
  22. #endif
  23. #define WINDOW_MOD_SHIFT_NAME "Shift"
  24. #define WINDOW_MOD_ALT_NAME "Alt"
  25. /** Filters actual mod keys from the mod flags.
  26. Use this if you don't care about GLFW_MOD_CAPS_LOCK and GLFW_MOD_NUM_LOCK.
  27. Example usage:
  28. if ((e.mod & WINDOW_MOD_MASK) == (WINDOW_MOD | GLFW_MOD_SHIFT)) ...
  29. */
  30. #define WINDOW_MOD_MASK (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER)
  31. namespace rack {
  32. // 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.
  33. struct Font {
  34. NVGcontext *vg;
  35. int handle;
  36. Font(NVGcontext *vg, const std::string &filename);
  37. ~Font();
  38. /** Use `APP->window->loadFont()` instead. */
  39. DEPRECATED static std::shared_ptr<Font> load(const std::string &filename);
  40. };
  41. struct Image {
  42. NVGcontext *vg;
  43. int handle;
  44. Image(NVGcontext *vg, const std::string &filename);
  45. ~Image();
  46. /** Use `APP->window->loadImage()` instead. */
  47. DEPRECATED static std::shared_ptr<Image> load(const std::string &filename);
  48. };
  49. struct Svg {
  50. NSVGimage *handle;
  51. Svg(const std::string &filename);
  52. ~Svg();
  53. /** Use `APP->window->loadSvg()` instead. */
  54. DEPRECATED static std::shared_ptr<Svg> load(const std::string &filename);
  55. };
  56. DEPRECATED typedef Svg SVG;
  57. struct Window {
  58. GLFWwindow *win = NULL;
  59. NVGcontext *vg = NULL;
  60. /** Secondary nanovg context for drawing to framebuffers */
  61. NVGcontext *fbVg = NULL;
  62. /** The scaling ratio */
  63. float pixelRatio = 1.f;
  64. /* The ratio between the framebuffer size and the window size reported by the OS.
  65. This is not equal to gPixelRatio in general.
  66. */
  67. float windowRatio = 1.f;
  68. int frame = 0;
  69. /** The last known absolute mouse position in the window */
  70. math::Vec mousePos;
  71. std::shared_ptr<Font> uiFont;
  72. struct Internal;
  73. Internal *internal;
  74. Window();
  75. ~Window();
  76. void run();
  77. void close();
  78. void cursorLock();
  79. void cursorUnlock();
  80. /** Gets the current keyboard mod state
  81. Don't call this from a Key event. Simply use `e.mods` instead.
  82. */
  83. int getMods();
  84. void setFullScreen(bool fullScreen);
  85. bool isFullScreen();
  86. std::shared_ptr<Font> loadFont(const std::string &filename);
  87. std::shared_ptr<Image> loadImage(const std::string &filename);
  88. std::shared_ptr<Svg> loadSvg(const std::string &filename);
  89. };
  90. void windowInit();
  91. void windowDestroy();
  92. } // namespace rack