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.

98 lines
2.3KB

  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. /** Filters actual mod keys from the mod flags.
  21. Use this if you don't care about GLFW_MOD_CAPS_LOCK and GLFW_MOD_NUM_LOCK.
  22. Example usage:
  23. if ((e.mod & WINDOW_MOD_MASK) == (WINDOW_MOD | GLFW_MOD_SHIFT)) ...
  24. */
  25. #define WINDOW_MOD_MASK (GLFW_MOD_SHIFT | GLFW_MOD_CONTROL | GLFW_MOD_ALT | GLFW_MOD_SUPER)
  26. namespace rack {
  27. // 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.
  28. struct Font {
  29. int handle;
  30. Font(const std::string &filename);
  31. ~Font();
  32. static std::shared_ptr<Font> load(const std::string &filename);
  33. };
  34. struct Image {
  35. int handle;
  36. Image(const std::string &filename);
  37. ~Image();
  38. static std::shared_ptr<Image> load(const std::string &filename);
  39. };
  40. struct SVG {
  41. NSVGimage *handle;
  42. SVG(const std::string &filename);
  43. ~SVG();
  44. static std::shared_ptr<SVG> load(const std::string &filename);
  45. };
  46. struct Window {
  47. GLFWwindow *win = NULL;
  48. NVGcontext *vg = NULL;
  49. NVGcontext *framebufferVg = NULL;
  50. /** The scaling ratio */
  51. float pixelRatio = 1.f;
  52. /* The ratio between the framebuffer size and the window size reported by the OS.
  53. This is not equal to gPixelRatio in general.
  54. */
  55. float windowRatio = 1.f;
  56. bool allowCursorLock = true;
  57. int frame = 0;
  58. /** The last known absolute mouse position in the window */
  59. math::Vec mousePos;
  60. std::shared_ptr<Font> uiFont;
  61. struct Internal;
  62. Internal *internal;
  63. Window();
  64. ~Window();
  65. void run();
  66. void close();
  67. void cursorLock();
  68. void cursorUnlock();
  69. /** Gets the current keyboard mod state
  70. Don't call this from a Key event. Simply use `e.mods` instead.
  71. */
  72. int getMods();
  73. math::Vec getWindowSize();
  74. void setWindowSize(math::Vec size);
  75. math::Vec getWindowPos();
  76. void setWindowPos(math::Vec pos);
  77. bool isMaximized();
  78. void setFullScreen(bool fullScreen);
  79. bool isFullScreen();
  80. };
  81. } // namespace rack