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.

window.hpp 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. #ifdef ARCH_MAC
  11. #define WINDOW_MOD GLFW_MOD_SUPER
  12. #define WINDOW_MOD_KEY_NAME "Cmd"
  13. #else
  14. #define WINDOW_MOD GLFW_MOD_CONTROL
  15. #define WINDOW_MOD_KEY_NAME "Ctrl"
  16. #endif
  17. namespace rack {
  18. // 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.
  19. struct Font {
  20. int handle;
  21. Font(const std::string &filename);
  22. ~Font();
  23. static std::shared_ptr<Font> load(const std::string &filename);
  24. };
  25. struct Image {
  26. int handle;
  27. Image(const std::string &filename);
  28. ~Image();
  29. static std::shared_ptr<Image> load(const std::string &filename);
  30. };
  31. struct SVG {
  32. NSVGimage *handle;
  33. SVG(const std::string &filename);
  34. ~SVG();
  35. static std::shared_ptr<SVG> load(const std::string &filename);
  36. };
  37. struct Window {
  38. GLFWwindow *win = NULL;
  39. NVGcontext *vg = NULL;
  40. NVGcontext *framebufferVg = NULL;
  41. /** The scaling ratio */
  42. float pixelRatio = 1.f;
  43. /* The ratio between the framebuffer size and the window size reported by the OS.
  44. This is not equal to gPixelRatio in general.
  45. */
  46. float windowRatio = 1.f;
  47. bool allowCursorLock = true;
  48. int frame = 0;
  49. /** The last known absolute mouse position in the window */
  50. math::Vec mousePos;
  51. std::shared_ptr<Font> uiFont;
  52. struct Internal;
  53. Internal *internal;
  54. Window();
  55. ~Window();
  56. void run();
  57. void close();
  58. void cursorLock();
  59. void cursorUnlock();
  60. bool isModPressed();
  61. bool isShiftPressed();
  62. math::Vec getWindowSize();
  63. void setWindowSize(math::Vec size);
  64. math::Vec getWindowPos();
  65. void setWindowPos(math::Vec pos);
  66. bool isMaximized();
  67. void setFullScreen(bool fullScreen);
  68. bool isFullScreen();
  69. };
  70. } // namespace rack