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
|
// -- internal --
// public
#include "rodeo/window.h"
#include "rodeo/log.h"
// private
#include "window/irodeo_window.h"
// -- external --
#include "SDL.h"
#include "stc/cstr.h"
static irodeo_window_state_t irodeo_window_state = {0};
void
rodeo_window_init(
uint32_t width,
uint32_t height,
cstr title
)
{
irodeo_window_state.window = NULL;
irodeo_window_state.screen_surface = NULL;
irodeo_window_state.height = height;
irodeo_window_state.width = width;
rodeo_log(
rodeo_logLevel_info,
"Initializing SDL Video..."
);
if(SDL_InitSubSystem(SDL_INIT_VIDEO) < 0)
{
rodeo_log(
rodeo_logLevel_error,
"Failed to initialize SDL Video. SDL_Error: %s",
SDL_GetError()
);
exit(EXIT_FAILURE);
}
rodeo_log(
rodeo_logLevel_info,
"Success initializing SDL Video"
);
rodeo_log(
rodeo_logLevel_info,
"Initializing SDL window..."
);
irodeo_window_state.window = SDL_CreateWindow(
cstr_str(&title),
SDL_WINDOWPOS_UNDEFINED,
SDL_WINDOWPOS_UNDEFINED,
(int32_t)width,
(int32_t)height,
SDL_WINDOW_SHOWN //| SDL_WINDOW_RESIZABLE
);
if(irodeo_window_state.window == NULL)
{
rodeo_log(
rodeo_logLevel_error,
"Failed creating SDL window. SDL_Error: %s",
SDL_GetError()
);
exit(EXIT_FAILURE);
}
rodeo_log(
rodeo_logLevel_info,
"Success initializing SDL window"
);
#if !__EMSCRIPTEN__
rodeo_log(
rodeo_logLevel_info,
"SDL setting up driver specific information..."
);
SDL_VERSION(&irodeo_window_state.wmi.version);
if(
!SDL_GetWindowWMInfo(
irodeo_window_state.window,
&irodeo_window_state.wmi
)
)
{
rodeo_log(
rodeo_logLevel_error,
"SDL failed to get driver specific information. SDL Error: %s", SDL_GetError()
);
exit(EXIT_FAILURE);
}
rodeo_log(
rodeo_logLevel_info,
"Success getting driver specific information"
);
#endif
}
void
rodeo_window_deinit(void)
{
SDL_DestroyWindow(irodeo_window_state.window);
SDL_Quit();
}
void
irodeo_window_dimensions_update(void)
{
int32_t width = 0;
int32_t height = 0;
SDL_GetWindowSize(
irodeo_window_state.window,
&width,
&height
);
irodeo_window_state.width = (uint32_t)width;
irodeo_window_state.height = (uint32_t)height;
}
uint32_t
rodeo_window_width_get(void)
{
//irodeo_window_update_screen_size();
return irodeo_window_state.width;
}
uint32_t
rodeo_window_height_get(void)
{
//irodeo_window_update_screen_size();
return irodeo_window_state.height;
}
bool
rodeo_window_shouldQuit(void)
{
return irodeo_window_state.quit;
}
void
rodeo_window_quit(void)
{
irodeo_window_state.quit = true;
}
uint64_t
rodeo_window_elapsedTime_ms(void)
{
return SDL_GetTicks64();
}
SDL_Window *
irodeo_window_get(void)
{
return irodeo_window_state.window;
}
SDL_Surface *
irodeo_window_surface_get(void)
{
return irodeo_window_state.screen_surface;
}
SDL_SysWMinfo
irodeo_window_wmi_get(void)
{
return irodeo_window_state.wmi;
}
|