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.

84 lines
1.7KB

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