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.

100 lines
2.4KB

  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. #include <nanosvg.h>
  10. /** Remaps Ctrl to Cmd on Mac
  11. Use this instead of GLFW_MOD_CONTROL, since Cmd should be used on Mac in place of Ctrl on Linux/Windows.
  12. */
  13. #ifdef ARCH_MAC
  14. #define WINDOW_MOD_CTRL GLFW_MOD_SUPER
  15. #define WINDOW_MOD_CTRL_NAME "Cmd"
  16. #else
  17. #define WINDOW_MOD_CTRL GLFW_MOD_CONTROL
  18. #define WINDOW_MOD_CTRL_NAME "Ctrl"
  19. #endif
  20. #define WINDOW_MOD_SHIFT_NAME "Shift"
  21. #define WINDOW_MOD_ALT_NAME "Alt"
  22. /** Filters actual mod keys from the mod flags.
  23. Use this if you don't care about GLFW_MOD_CAPS_LOCK and GLFW_MOD_NUM_LOCK.
  24. Example usage:
  25. if ((e.mod & WINDOW_MOD_MASK) == (WINDOW_MOD | GLFW_MOD_SHIFT)) ...
  26. */
  27. #define WINDOW_MOD_MASK (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER)
  28. namespace rack {
  29. // 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.
  30. struct Font {
  31. int handle;
  32. Font(const std::string &filename);
  33. ~Font();
  34. static std::shared_ptr<Font> load(const std::string &filename);
  35. };
  36. struct Image {
  37. int handle;
  38. Image(const std::string &filename);
  39. ~Image();
  40. static std::shared_ptr<Image> load(const std::string &filename);
  41. };
  42. struct SVG {
  43. NSVGimage *handle;
  44. SVG(const std::string &filename);
  45. ~SVG();
  46. static std::shared_ptr<SVG> load(const std::string &filename);
  47. };
  48. struct Window {
  49. GLFWwindow *win = NULL;
  50. NVGcontext *vg = NULL;
  51. NVGcontext *framebufferVg = NULL;
  52. /** The scaling ratio */
  53. float pixelRatio = 1.f;
  54. /* The ratio between the framebuffer size and the window size reported by the OS.
  55. This is not equal to gPixelRatio in general.
  56. */
  57. float windowRatio = 1.f;
  58. bool allowCursorLock = true;
  59. int frame = 0;
  60. /** The last known absolute mouse position in the window */
  61. math::Vec mousePos;
  62. std::shared_ptr<Font> uiFont;
  63. struct Internal;
  64. Internal *internal;
  65. Window();
  66. ~Window();
  67. void run();
  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. math::Vec getWindowSize();
  76. void setWindowSize(math::Vec size);
  77. math::Vec getWindowPos();
  78. void setWindowPos(math::Vec pos);
  79. bool isMaximized();
  80. void setFullScreen(bool fullScreen);
  81. bool isFullScreen();
  82. };
  83. } // namespace rack