-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWindow.h
336 lines (285 loc) · 6.75 KB
/
Window.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
#pragma once
#ifndef RAYLIB_WINDOW_CPP
#define RAYLIB_WINDOW_CPP
#include <stdexcept>
#include <string>
#include <raylib.h>
class window
{
public:
window(int width, int height, const std::string& title, bool late_init);
static bool init(int width, int height, const std::string& title);
static bool should_close();
static bool is_cursor_on_screen();
static bool is_ready();
static bool is_fullscreen();
static bool is_hidden();
static bool is_minimized();
static bool is_maximized();
static bool is_focused();
static bool is_resized();
static bool is_state(unsigned int flag);
window& set_state(unsigned int flag);
window& clear_state(unsigned int flag);
window& clear_background(const Color& color = BLACK);
window& toggle_fullscreen();
window& set_fullscreen(bool fullscreen);
window& maximize();
window& minimize();
window& restore();
window& set_icon(const Image& image);
window& set_title(const std::string& title);
window& set_position(int x, int y);
window& set_position(const Vector2& position);
window& set_monitor(int monitor);
window& set_min_size(int width, int height);
window& set_min_size(const Vector2& size);
window& set_size(int width, int height);
window& set_size(const Vector2& size);
static Vector2 get_size();
static void* get_handle();
window& begin_drawing();
window& end_drawing();
static int get_width();
static int get_height();
static Vector2 get_position();
static Vector2 get_scale_dpi();
window& set_target_fps(int fps);
static int get_fps();
window& draw_fps(int pos_x = 10, int pos_y = 10);
static float get_frame_time();
static double get_time();
~window();
private:
};
inline window::window(const int width, const int height, const std::string& title = "raylib", const bool late_init = false)
{
if (!late_init)
{
if (!init(width, height, title))
{
throw std::runtime_error("Failed to create Window");
}
}
}
inline bool window::init(const int width = 800, const int height = 450, const std::string& title = "raylib")
{
InitWindow(width, height, title.c_str());
return IsWindowReady();
}
inline bool window::should_close()
{
return WindowShouldClose();
}
inline bool window::is_cursor_on_screen()
{
return IsCursorOnScreen();
}
inline bool window::is_ready()
{
return IsWindowReady();
}
inline bool window::is_fullscreen()
{
return IsWindowFullscreen();
}
inline bool window::is_hidden()
{
return IsWindowHidden();
}
inline bool window::is_minimized()
{
return IsWindowMinimized();
}
inline bool window::is_maximized()
{
return IsWindowMaximized();
}
inline bool window::is_focused()
{
return IsWindowFocused();
}
inline bool window::is_resized()
{
return IsWindowResized();
}
inline bool window::is_state(const unsigned int flag)
{
return IsWindowState(flag);
}
inline window& window::set_state(const unsigned int flag)
{
// TODO: insert return statement here
SetWindowState(flag);
return *this;
}
inline window& window::clear_state(const unsigned int flag)
{
// TODO: insert return statement here
ClearWindowState(flag);
return *this;
}
inline window& window::clear_background(const Color& color)
{
// TODO: insert return statement here
::ClearBackground(color);
return *this;
}
inline window& window::toggle_fullscreen()
{
// TODO: insert return statement here
::ToggleFullscreen();
return *this;
}
inline window& window::set_fullscreen(const bool fullscreen)
{
// TODO: insert return statement here
if (fullscreen)
{
if (!is_fullscreen())
{
toggle_fullscreen();
}
}
else
{
if (is_fullscreen())
{
toggle_fullscreen();
}
}
return *this;
}
inline window& window::maximize()
{
// TODO: insert return statement here
MaximizeWindow();
return *this;
}
inline window& window::minimize()
{
// TODO: insert return statement here
MinimizeWindow();
return *this;
}
inline window& window::restore()
{
// TODO: insert return statement here
RestoreWindow();
return *this;
}
inline window& window::set_icon(const Image& image)
{
// TODO: insert return statement here
SetWindowIcon(image);
return *this;
}
inline window& window::set_title(const std::string& title)
{
// TODO: insert return statement here
SetWindowTitle(title.c_str());
return *this;
}
inline window& window::set_position(int x, int y)
{
// TODO: insert return statement here
SetWindowPosition(x, y);
return *this;
}
inline window& window::set_position(const Vector2& position)
{
SetWindowPosition(static_cast<int>(position.x), static_cast<int>(position.y));
return *this;
}
inline window& window::set_monitor(int monitor)
{
SetWindowMonitor(monitor);
return *this;
}
inline window& window::set_min_size(int width, int height)
{
// TODO: insert return statement here
SetWindowMinSize(width, height);
return *this;
}
inline window& window::set_min_size(const Vector2& size)
{
SetWindowMinSize(static_cast<int>(size.x), static_cast<int>(size.y));
return *this;
}
inline window& window::set_size(int width, int height)
{
// TODO: insert return statement here
SetWindowSize(width, height);
return *this;
}
inline window& window::set_size(const Vector2& size)
{
// TODO: insert return statement here
return set_size(static_cast<int>(size.x), static_cast<int>(size.y));
}
inline Vector2 window::get_size()
{
return {static_cast<float>(get_width()), static_cast<float>(get_height())};
}
inline void* window::get_handle()
{
return GetWindowHandle();
}
inline window& window::begin_drawing()
{
// TODO: insert return statement here
::BeginDrawing();
return *this;
}
inline window& window::end_drawing()
{
// TODO: insert return statement here
::EndDrawing();
return *this;
}
inline int window::get_width()
{
return GetScreenWidth();
}
inline int window::get_height()
{
return GetScreenHeight();
}
inline Vector2 window::get_position()
{
return GetWindowPosition();
}
inline Vector2 window::get_scale_dpi()
{
return GetWindowScaleDPI();
}
inline window& window::set_target_fps(int fps)
{
::SetTargetFPS(fps);
return *this;
// TODO: insert return statement here
}
inline int window::get_fps()
{
return ::GetFPS();
}
inline window& window::draw_fps(int pos_x, int pos_y)
{
// TODO: insert return statement here
::DrawFPS(pos_x, pos_y);
return *this;
}
inline float window::get_frame_time()
{
return ::GetFrameTime();
}
inline double window::get_time()
{
return ::GetTime();
}
inline window::~window()
{
CloseWindow();
}
#endif // !RAYLIB_WINDOW_CPP