raylib-cpp
C++ object-oriented wrapper library for raylib.
Window.hpp
1 #ifndef RAYLIB_CPP_INCLUDE_WINDOW_HPP_
2 #define RAYLIB_CPP_INCLUDE_WINDOW_HPP_
3 
4 #include <string>
5 
6 #include "./raylib.hpp"
7 
8 namespace raylib {
12 class Window {
13  public:
17  Window(int width = 800, int height = 450, const std::string& title = "raylib",
18  bool lateInit = false) {
19  if (!lateInit) {
20  Init(width, height, title);
21  }
22  }
23 
27  ~Window() {
28  Close();
29  }
30 
31  void Init(int width = 800, int height = 450, const std::string& title = "raylib") {
32  ::InitWindow(width, height, title.c_str());
33  }
34 
38  inline bool ShouldClose() const {
39  return ::WindowShouldClose();
40  }
41 
45  inline void Close() {
46  ::CloseWindow();
47  }
48 
52  inline bool IsCursorOnScreen() const {
53  return ::IsCursorOnScreen();
54  }
55 
59  inline static bool IsReady() {
60  return ::IsWindowReady();
61  }
62 
66  inline bool IsFullscreen() const {
67  return ::IsWindowFullscreen();
68  }
69 
73  inline bool IsHidden() const {
74  return ::IsWindowHidden();
75  }
76 
80  inline bool IsMinimized() const {
81  return ::IsWindowMinimized();
82  }
83 
87  inline bool IsMaximized() const {
88  return ::IsWindowMaximized();
89  }
90 
94  inline bool IsFocused() const {
95  return ::IsWindowFocused();
96  }
97 
101  inline bool IsResized() const {
102  return ::IsWindowResized();
103  }
104 
108  inline bool IsState(unsigned int flag) const {
109  return ::IsWindowState(flag);
110  }
111 
115  inline Window& SetState(unsigned int flag) {
116  ::SetWindowState(flag);
117  return *this;
118  }
119 
123  inline Window& ClearState(unsigned int flag) {
124  ::ClearWindowState(flag);
125  return *this;
126  }
127 
131  inline Window& ClearBackground(const ::Color& color = BLACK) {
132  ::ClearBackground(color);
133  return *this;
134  }
135 
141  return *this;
142  }
143 
147  inline Window& SetFullscreen(bool fullscreen) {
148  if (fullscreen) {
149  if (!IsFullscreen()) {
151  }
152  } else {
153  if (IsFullscreen()) {
155  }
156  }
157 
158  return *this;
159  }
160 
164  inline Window& Maximize() {
165  ::MaximizeWindow();
166  return *this;
167  }
168 
172  inline Window& Minimize() {
173  ::MinimizeWindow();
174  return *this;
175  }
176 
180  inline Window& Restore() {
181  ::RestoreWindow();
182  return *this;
183  }
184 
188  inline Window& SetIcon(const ::Image& image) {
189  ::SetWindowIcon(image);
190  return *this;
191  }
192 
196  inline Window& SetTitle(const std::string& title) {
197  ::SetWindowTitle(title.c_str());
198  return *this;
199  }
200 
204  inline Window& SetPosition(int x, int y) {
205  ::SetWindowPosition(x, y);
206  return *this;
207  }
208 
212  inline Window& SetPosition(const ::Vector2& position) {
213  return SetPosition(static_cast<int>(position.x), static_cast<int>(position.y));
214  }
215 
219  inline Window& SetMonitor(int monitor) {
220  ::SetWindowMonitor(monitor);
221  return *this;
222  }
223 
227  inline Window& SetMinSize(int width, int height) {
228  ::SetWindowMinSize(width, height);
229  return *this;
230  }
231 
235  inline Window& SetSize(int width, int height) {
236  ::SetWindowSize(width, height);
237  return *this;
238  }
239 
243  inline Window& SetSize(const ::Vector2& size) {
244  return SetSize(static_cast<int>(size.x), static_cast<int>(size.y));
245  }
246 
250  inline ::Vector2 GetSize() {
251  return {static_cast<float>(GetWidth()), static_cast<float>(GetHeight())};
252  }
253 
257  inline void* GetHandle() const {
258  return ::GetWindowHandle();
259  }
260 
264  inline Window& BeginDrawing() {
265  ::BeginDrawing();
266  return *this;
267  }
268 
272  inline Window& EndDrawing() {
273  ::EndDrawing();
274  return *this;
275  }
276 
280  inline int GetWidth() const {
281  return ::GetScreenWidth();
282  }
283 
287  inline int GetHeight() const {
288  return ::GetScreenHeight();
289  }
290 
294  inline ::Vector2 GetPosition() const {
295  return ::GetWindowPosition();
296  }
297 
301  inline ::Vector2 GetScaleDPI() const {
302  return ::GetWindowScaleDPI();
303  }
304 
308  inline Window& SetTargetFPS(int fps) {
309  ::SetTargetFPS(fps);
310  return *this;
311  }
312 
316  inline int GetFPS() const {
317  return ::GetFPS();
318  }
319 
323  inline float GetFrameTime() const {
324  return ::GetFrameTime();
325  }
326 
330  inline double GetTime() const {
331  return ::GetTime();
332  }
333 };
334 } // namespace raylib
335 
336 #endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_
raylib::Window::GetSize
inline ::Vector2 GetSize()
Get the screen's width and height.
Definition: Window.hpp:250
raylib::Window::GetWidth
int GetWidth() const
Get current screen width.
Definition: Window.hpp:280
raylib::Window::GetHandle
void * GetHandle() const
Get native window handle.
Definition: Window.hpp:257
raylib
All raylib-cpp classes and functions appear in the raylib namespace.
Definition: AudioDevice.hpp:7
raylib::Window::SetMonitor
Window & SetMonitor(int monitor)
Set monitor for the current window.
Definition: Window.hpp:219
raylib::Window::GetTime
double GetTime() const
Returns elapsed time in seconds since InitWindow()
Definition: Window.hpp:330
raylib::Window::~Window
~Window()
Close window and unload OpenGL context.
Definition: Window.hpp:27
raylib::Window::IsHidden
bool IsHidden() const
Check if window is currently hidden.
Definition: Window.hpp:73
raylib::SetWindowTitle
static void SetWindowTitle(const std::string &title)
Set title for window.
Definition: Functions.hpp:31
raylib::Window::Close
void Close()
Close window and unload OpenGL context.
Definition: Window.hpp:45
raylib::Window::ClearBackground
Window & ClearBackground(const ::Color &color=BLACK)
Clear window with given color.
Definition: Window.hpp:131
raylib::Window::SetMinSize
Window & SetMinSize(int width, int height)
Set window minimum dimensions.
Definition: Window.hpp:227
raylib::Window::SetState
Window & SetState(unsigned int flag)
Set window configuration state using flags.
Definition: Window.hpp:115
raylib::Window::GetFrameTime
float GetFrameTime() const
Returns time in seconds for last frame drawn.
Definition: Window.hpp:323
raylib::Window::ShouldClose
bool ShouldClose() const
Check if KEY_ESCAPE pressed or Close icon pressed.
Definition: Window.hpp:38
raylib::InitWindow
static void InitWindow(int width, int height, const std::string &title="raylib")
Initialize window and OpenGL context.
Definition: Functions.hpp:24
raylib::Window::SetFullscreen
Window & SetFullscreen(bool fullscreen)
Set whether or not the application should be fullscreen.
Definition: Window.hpp:147
raylib::Window::SetPosition
Window & SetPosition(int x, int y)
Set window position on screen.
Definition: Window.hpp:204
raylib::Window::SetSize
Window & SetSize(const ::Vector2 &size)
Set window dimensions.
Definition: Window.hpp:243
raylib::Window::IsMaximized
bool IsMaximized() const
Check if window is currently minimized.
Definition: Window.hpp:87
raylib::Window::GetScaleDPI
inline ::Vector2 GetScaleDPI() const
Get window scale DPI factor.
Definition: Window.hpp:301
raylib::Window::Window
Window(int width=800, int height=450, const std::string &title="raylib", bool lateInit=false)
Initialize window and OpenGL context.
Definition: Window.hpp:17
raylib::Window::IsFocused
bool IsFocused() const
Check if window is currently focused.
Definition: Window.hpp:94
raylib::Window::IsResized
bool IsResized() const
Check if window has been resized last frame.
Definition: Window.hpp:101
raylib::Window::GetHeight
int GetHeight() const
Get current screen height.
Definition: Window.hpp:287
raylib::Window::EndDrawing
Window & EndDrawing()
End canvas drawing and swap buffers (double buffering)
Definition: Window.hpp:272
raylib::Window::SetSize
Window & SetSize(int width, int height)
Set window dimensions.
Definition: Window.hpp:235
raylib::Window::GetFPS
int GetFPS() const
Returns current FPS.
Definition: Window.hpp:316
raylib::Window::Minimize
Window & Minimize()
Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
Definition: Window.hpp:172
raylib::Window::ToggleFullscreen
Window & ToggleFullscreen()
Toggle window state: fullscreen/windowed.
Definition: Window.hpp:139
raylib::Window::Maximize
Window & Maximize()
Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
Definition: Window.hpp:164
raylib::Window::SetTitle
Window & SetTitle(const std::string &title)
Set title for window.
Definition: Window.hpp:196
raylib::Window::IsCursorOnScreen
bool IsCursorOnScreen() const
Check if cursor is on the current screen.
Definition: Window.hpp:52
raylib::Window::IsFullscreen
bool IsFullscreen() const
Check if window is currently fullscreen.
Definition: Window.hpp:66
raylib::Window::IsReady
static bool IsReady()
Check if window has been initialized successfully.
Definition: Window.hpp:59
raylib::Window::BeginDrawing
Window & BeginDrawing()
Setup canvas (framebuffer) to start drawing.
Definition: Window.hpp:264
raylib::Window::ClearState
Window & ClearState(unsigned int flag)
Clear window configuration state flags.
Definition: Window.hpp:123
raylib::Window::IsState
bool IsState(unsigned int flag) const
Check if one specific window flag is enabled.
Definition: Window.hpp:108
raylib::Window::SetPosition
Window & SetPosition(const ::Vector2 &position)
Set window position on screen.
Definition: Window.hpp:212
raylib::Window::SetTargetFPS
Window & SetTargetFPS(int fps)
Set target FPS (maximum)
Definition: Window.hpp:308
raylib::Window::GetPosition
inline ::Vector2 GetPosition() const
Get window position XY on monitor.
Definition: Window.hpp:294
raylib::Window::IsMinimized
bool IsMinimized() const
Check if window is currently minimized.
Definition: Window.hpp:80
raylib::Window::Restore
Window & Restore()
Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
Definition: Window.hpp:180
raylib::Window::SetIcon
Window & SetIcon(const ::Image &image)
Set icon for window.
Definition: Window.hpp:188
raylib::Window
Window and Graphics Device Functions.
Definition: Window.hpp:12