raylib-cpp
C++ object-oriented wrapper library for raylib.
Window.hpp
1 /*
2 * LICENSE: zlib/libpng
3 *
4 * raylib-cpp is licensed under an unmodified zlib/libpng license, which is an OSI-certified,
5 * BSD-like license that allows static linking with closed source software:
6 *
7 * Copyright (c) 2020 Rob Loach (@RobLoach)
8 *
9 * This software is provided "as-is", without any express or implied warranty. In no event
10 * will the authors be held liable for any damages arising from the use of this software.
11 *
12 * Permission is granted to anyone to use this software for any purpose, including commercial
13 * applications, and to alter it and redistribute it freely, subject to the following restrictions:
14 *
15 * 1. The origin of this software must not be misrepresented; you must not claim that you
16 * wrote the original software. If you use this software in a product, an acknowledgment
17 * in the product documentation would be appreciated but is not required.
18 *
19 * 2. Altered source versions must be plainly marked as such, and must not be misrepresented
20 * as being the original software.
21 *
22 * 3. This notice may not be removed or altered from any source distribution.
23 */
24 
25 #ifndef RAYLIB_CPP_INCLUDE_WINDOW_HPP_
26 #define RAYLIB_CPP_INCLUDE_WINDOW_HPP_
27 
28 #include <string>
29 
30 #include "./raylib.hpp"
31 
32 namespace raylib {
44 class Window {
45  public:
49  Window(int width = 800, int height = 450, const std::string& title = "raylib",
50  bool lateInit = false) {
51  if (!lateInit) {
52  Init(width, height, title);
53  }
54  }
55 
56  ~Window() {
57  Close();
58  }
59 
60  void Init(int width, int height, const std::string& title) {
61  ::InitWindow(width, height, title.c_str());
62  }
63 
67  inline bool ShouldClose() const {
68  return ::WindowShouldClose();
69  }
70 
74  inline void Close() {
75  ::CloseWindow();
76  }
77 
81  inline bool IsCursorOnScreen() const {
82  return ::IsCursorOnScreen();
83  }
84 
88  inline static bool IsReady() {
89  return ::IsWindowReady();
90  }
91 
95  inline bool IsFullscreen() const {
96  return ::IsWindowFullscreen();
97  }
98 
102  inline bool IsHidden() const {
103  return ::IsWindowHidden();
104  }
105 
109  inline bool IsMinimized() const {
110  return ::IsWindowMinimized();
111  }
112 
116  inline bool IsMaximized() const {
117  return ::IsWindowMaximized();
118  }
119 
123  inline bool IsFocused() const {
124  return ::IsWindowFocused();
125  }
126 
130  inline bool IsResized() const {
131  return ::IsWindowResized();
132  }
133 
137  inline bool IsState(unsigned int flag) const {
138  return ::IsWindowState(flag);
139  }
140 
144  inline Window& SetState(unsigned int flag) {
145  ::SetWindowState(flag);
146  return *this;
147  }
148 
152  inline Window& ClearState(unsigned int flag) {
153  ::ClearWindowState(flag);
154  return *this;
155  }
156 
162  return *this;
163  }
164 
168  inline Window& Maximize() {
169  ::MaximizeWindow();
170  return *this;
171  }
172 
176  inline Window& Minimize() {
177  ::MinimizeWindow();
178  return *this;
179  }
180 
184  inline Window& Restore() {
185  ::RestoreWindow();
186  return *this;
187  }
188 
192  inline Window& SetIcon(::Image image) {
193  ::SetWindowIcon(image);
194  return *this;
195  }
196 
200  inline Window& SetTitle(const std::string& title) {
201  ::SetWindowTitle(title.c_str());
202  return *this;
203  }
204 
208  inline Window& SetPosition(int x, int y) {
209  ::SetWindowPosition(x, y);
210  return *this;
211  }
212 
216  inline Window& SetMonitor(int monitor) {
217  ::SetWindowMonitor(monitor);
218  return *this;
219  }
220 
224  inline Window& SetMinSize(int width, int height) {
225  ::SetWindowMinSize(width, height);
226  return *this;
227  }
228 
232  inline Window& SetSize(int width, int height) {
233  ::SetWindowSize(width, height);
234  return *this;
235  }
236 
240  inline void* GetHandle() const {
241  return ::GetWindowHandle();
242  }
243 
247  inline Window& BeginDrawing() {
248  ::BeginDrawing();
249  return *this;
250  }
251 
255  inline Window& EndDrawing() {
256  ::EndDrawing();
257  return *this;
258  }
259 
263  inline int GetScreenWidth() const {
264  return ::GetScreenWidth();
265  }
266 
270  inline int GetScreenHeight() const {
271  return ::GetScreenHeight();
272  }
273 
277  inline Vector2 GetPosition() const {
278  return ::GetWindowPosition();
279  }
280 
284  inline Vector2 GetScaleDPI() const {
285  return ::GetWindowScaleDPI();
286  }
287 
291  std::string GetMonitorName(int monitor) const {
292  return ::GetMonitorName(monitor);
293  }
294 
298  std::string GetClipboardText() const {
299  return ::GetClipboardText();
300  }
301 
305  inline Window& SetClipboardText(const std::string& text) {
306  ::SetClipboardText(text.c_str());
307  return *this;
308  }
309 
313  inline Window& SetTargetFPS(int fps) {
314  ::SetTargetFPS(fps);
315  return *this;
316  }
317 
321  inline int GetFPS() const {
322  return ::GetFPS();
323  }
324 
328  inline float GetFrameTime() const {
329  return ::GetFrameTime();
330  }
331 
335  inline double GetTime() const {
336  return ::GetTime();
337  }
338 };
339 } // namespace raylib
340 
341 #endif // RAYLIB_CPP_INCLUDE_WINDOW_HPP_
raylib::Window::GetHandle
void * GetHandle() const
Get native window handle.
Definition: Window.hpp:240
raylib
Provides all the classes associated with raylib-cpp.
Definition: AudioDevice.hpp:31
raylib::Window::SetMonitor
Window & SetMonitor(int monitor)
Set monitor for the current window.
Definition: Window.hpp:216
raylib::Window::GetTime
double GetTime() const
Returns elapsed time in seconds since InitWindow()
Definition: Window.hpp:335
raylib::Window::~Window
~Window()
Definition: Window.hpp:56
raylib::Window::IsHidden
bool IsHidden() const
Check if window is currently hidden.
Definition: Window.hpp:102
raylib::Window::Close
void Close()
Close window and unload OpenGL context.
Definition: Window.hpp:74
raylib::Window::SetIcon
Window & SetIcon(::Image image)
Set icon for window.
Definition: Window.hpp:192
raylib::Image
Definition: Image.hpp:34
raylib::Window::SetMinSize
Window & SetMinSize(int width, int height)
Set window minimum dimensions.
Definition: Window.hpp:224
raylib::Window::SetState
Window & SetState(unsigned int flag)
Set window configuration state using flags.
Definition: Window.hpp:144
raylib::Window::GetFrameTime
float GetFrameTime() const
Returns time in seconds for last frame drawn.
Definition: Window.hpp:328
raylib::Window::ShouldClose
bool ShouldClose() const
Check if KEY_ESCAPE pressed or Close icon pressed.
Definition: Window.hpp:67
raylib::Window::Init
void Init(int width, int height, const std::string &title)
Definition: Window.hpp:60
raylib::Window::GetMonitorName
std::string GetMonitorName(int monitor) const
Get the human-readable, UTF-8 encoded name of the primary monitor.
Definition: Window.hpp:291
raylib::Window::SetPosition
Window & SetPosition(int x, int y)
Set window position on screen.
Definition: Window.hpp:208
raylib::Window::IsMaximized
bool IsMaximized() const
Check if window is currently minimized.
Definition: Window.hpp:116
raylib::Window::GetScaleDPI
Vector2 GetScaleDPI() const
Get window scale DPI factor.
Definition: Window.hpp:284
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:49
raylib::Window::IsFocused
bool IsFocused() const
Check if window is currently focused.
Definition: Window.hpp:123
raylib::Window::IsResized
bool IsResized() const
Check if window has been resized last frame.
Definition: Window.hpp:130
raylib::Window::EndDrawing
Window & EndDrawing()
End canvas drawing and swap buffers (double buffering)
Definition: Window.hpp:255
raylib::Window::SetSize
Window & SetSize(int width, int height)
Set window dimensions.
Definition: Window.hpp:232
raylib::Vector2
Definition: Vector2.hpp:37
raylib::Window::GetFPS
int GetFPS() const
Returns current FPS.
Definition: Window.hpp:321
raylib::Window::Minimize
Window & Minimize()
Set window state: minimized, if resizable (only PLATFORM_DESKTOP)
Definition: Window.hpp:176
raylib::Window::GetScreenHeight
int GetScreenHeight() const
Get current screen height.
Definition: Window.hpp:270
raylib::Window::ToggleFullscreen
Window & ToggleFullscreen()
Toggle window state: fullscreen/windowed.
Definition: Window.hpp:160
raylib::Window::Maximize
Window & Maximize()
Set window state: maximized, if resizable (only PLATFORM_DESKTOP)
Definition: Window.hpp:168
raylib::Window::SetTitle
Window & SetTitle(const std::string &title)
Set title for window.
Definition: Window.hpp:200
raylib::Window::IsCursorOnScreen
bool IsCursorOnScreen() const
Check if cursor is on the current screen.
Definition: Window.hpp:81
raylib::Window::IsFullscreen
bool IsFullscreen() const
Check if window is currently fullscreen.
Definition: Window.hpp:95
raylib::Window::IsReady
static bool IsReady()
Check if window has been initialized successfully.
Definition: Window.hpp:88
raylib::Window::GetScreenWidth
int GetScreenWidth() const
Get current screen width.
Definition: Window.hpp:263
raylib::Window::GetClipboardText
std::string GetClipboardText() const
Get clipboard text content.
Definition: Window.hpp:298
raylib::Window::BeginDrawing
Window & BeginDrawing()
Setup canvas (framebuffer) to start drawing.
Definition: Window.hpp:247
raylib::Window::SetClipboardText
Window & SetClipboardText(const std::string &text)
Set clipboard text content.
Definition: Window.hpp:305
raylib::Window::ClearState
Window & ClearState(unsigned int flag)
Clear window configuration state flags.
Definition: Window.hpp:152
raylib::Window::IsState
bool IsState(unsigned int flag) const
Check if one specific window flag is enabled.
Definition: Window.hpp:137
raylib::Window::SetTargetFPS
Window & SetTargetFPS(int fps)
Set target FPS (maximum)
Definition: Window.hpp:313
raylib::Window::IsMinimized
bool IsMinimized() const
Check if window is currently minimized.
Definition: Window.hpp:109
raylib::Window::Restore
Window & Restore()
Set window state: not minimized/maximized (only PLATFORM_DESKTOP)
Definition: Window.hpp:184
raylib::Window::GetPosition
Vector2 GetPosition() const
Get window position XY on monitor.
Definition: Window.hpp:277
raylib::Window
Window and Graphics Device Functions.
Definition: Window.hpp:44