Mountain  1.0.0
Simple C++ 2D Game Framework
window.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <Maths/vector2i.hpp>
4 
5 #include "Mountain/core.hpp"
6 #include "Mountain/rendering/renderer.hpp"
9 
12 
13 // ReSharper disable once CppInconsistentNaming
14 struct GLFWwindow;
15 
16 namespace Mountain
17 {
18  enum class WindowMode : uint8_t
19  {
20  Windowed,
21  Borderless,
22  Fullscreen
23  };
24 
26  class Window
27  {
28  STATIC_CLASS(Window)
29 
30  public:
32  MOUNTAIN_API static inline Event<Vector2i> onPositionChanged;
34  MOUNTAIN_API static inline Event<Vector2i> onSizeChanged;
35 
37  STATIC_GETTER(Vector2i, Position, m_Position)
38 
39  MOUNTAIN_API static void SetPosition(Vector2i newPosition);
40 
42  STATIC_GETTER(Vector2i, Size, m_Size)
43 
44  MOUNTAIN_API static void SetSize(Vector2i newSize);
45 
47  [[nodiscard]]
48  MOUNTAIN_API static bool_t GetShouldClose();
49 
51  MOUNTAIN_API static void SetShouldClose(bool_t newShouldClose);
52 
54  MOUNTAIN_API static void MakeContextCurrent();
55 
57  STATIC_GETTER(GLFWwindow*, Handle, m_Window)
58 
59 
60  STATIC_GETTER(bool_t, Visible, m_Visible)
61 
62 
63  MOUNTAIN_API static void SetVisible(bool_t newVisible);
64 
66  MOUNTAIN_API static void SetIcon(const Pointer<Texture>& newIcon);
67 
70  MOUNTAIN_API static void SetCursorHidden(bool_t newCursorHidden);
71 
73  MOUNTAIN_API static void SetCursorPosition(Vector2 newPosition);
74 
75  STATIC_GETTER(bool_t, VSync, m_VSync)
76 
77  MOUNTAIN_API static void SetVSync(bool_t newVsync);
78 
79  STATIC_GETTER(WindowMode, WindowMode, m_WindowMode)
80 
81  MOUNTAIN_API static void SetWindowMode(WindowMode newWindowMode);
82 
84  STATIC_GETTER(int32_t, CurrentScreen, m_CurrentScreen)
85 
86  [[nodiscard]]
87  MOUNTAIN_API static std::string_view GetTitle();
88 
89  MOUNTAIN_API static void SetTitle(const std::string& newTitle);
90 
91  STATIC_GETTER(bool_t, Minimized, m_Minimized)
92 
93  private:
95  MOUNTAIN_API static inline GLFWwindow* m_Window = nullptr;
96 
97  MOUNTAIN_API static inline WindowMode m_WindowMode = WindowMode::Windowed;
98 
99  MOUNTAIN_API static inline int32_t m_CurrentScreen;
100 
101  MOUNTAIN_API static inline Vector2i m_Position;
102  MOUNTAIN_API static inline Vector2i m_Size;
103 
104  MOUNTAIN_API static inline bool_t m_Visible;
105  MOUNTAIN_API static inline bool_t m_Minimized = false;
106 
107  MOUNTAIN_API static inline bool_t m_VSync = false;
108 
110  static void Initialize(const std::string& windowTitle, Vector2i windowSize, const OpenGlVersion &glVersion);
111 
113  static void Shutdown();
114 
115  static void UpdateFields();
116 
117  static void UpdateCurrentScreen();
118 
119  static void PollEvents();
120 
121  static void SwapBuffers();
122 
123  static void WindowMinimizeCallback(GLFWwindow* window, int32_t minimized);
124 
125  // Calls Initialize, UpdateFields and Shutdown
126  friend class Renderer;
127  // Calls PollEvents
128  friend class Game;
129  // Calls SwapBuffers
130  friend class Time;
131  };
132 }
A wrapper for the main window.
Definition: window.hpp:26
static MOUNTAIN_API Event< Vector2i > onSizeChanged
Event called when the window size changed. The parameter is the new size.
Definition: window.hpp:34
static MOUNTAIN_API Event< Vector2i > onPositionChanged
Event called when the window position changed. The parameter is the new position. ...
Definition: window.hpp:32
Custom Mountain smart pointer. Represents both a std::shared_ptr and a std::weak_ptr.
Defines the Mountain::Texture class.
Defines the Event class.
Contains all declarations of the Mountain Framework.
Definition: audio.hpp:22