5#include <unordered_map>
9static const std::unordered_map<int, sys::virtual_key> glfw_key_to_virtual_key = {{GLFW_KEY_UNKNOWN,
sys::virtual_key::NONE},
61 for(
auto it = glfw_key_to_virtual_key.begin(); it != glfw_key_to_virtual_key.end(); ++it)
63 return glfwGetKey(game_state.
win_ptr->window, it->first) == GLFW_PRESS;
69 glfwGetWindowSize(game_state.
win_ptr->window, &width, &height);
81 glfwGetFramebufferSize(game_state.
win_ptr->window, &width, &height);
82 state->x_size = width;
83 state->y_size = height;
85 GLFWmonitor* monitor = glfwGetPrimaryMonitor();
88 glfwGetWindowSize(game_state.
win_ptr->window, &width, &height);
89 const GLFWvidmode* mode = glfwGetVideoMode(monitor);
90 glfwSetWindowMonitor(game_state.
win_ptr->window, monitor, 0, 0, mode->width, mode->height, mode->refreshRate);
91 game_state.
win_ptr->in_fullscreen=
true;
93 const GLFWvidmode* mode = glfwGetVideoMode(monitor);
94 glfwSetWindowMonitor(game_state.
win_ptr->window,
nullptr, 0, 0, width, height, mode->refreshRate);
95 glfwMaximizeWindow(game_state.
win_ptr->window);
96 game_state.
win_ptr->in_fullscreen=
false;
103 glfwSetWindowShouldClose(game_state.
win_ptr->window, 1);
108 (glfwGetKey(
window, GLFW_KEY_LEFT_CONTROL) == GLFW_PRESS) || (glfwGetKey(
window, GLFW_KEY_RIGHT_CONTROL) == GLFW_PRESS);
109 bool alt = (glfwGetKey(
window, GLFW_KEY_LEFT_ALT) == GLFW_PRESS) || (glfwGetKey(
window, GLFW_KEY_RIGHT_ALT) == GLFW_PRESS);
111 (glfwGetKey(
window, GLFW_KEY_LEFT_SHIFT) == GLFW_PRESS) || (glfwGetKey(
window, GLFW_KEY_RIGHT_SHIFT) == GLFW_PRESS);
126static void glfw_error_callback(
int error,
char const* description) {
127 emit_error_message(std::string{
"Glfw Error " } + std::to_string(error) + std::string{ description },
false);
130static void key_callback(GLFWwindow*
window,
int key,
int scancode,
int action,
int mods) {
142 switch(virtual_key) {
161static void cursor_position_callback(GLFWwindow*
window,
double xpos,
double ypos) {
164 int32_t
x = (xpos > 0 ? (int32_t)std::round(xpos) : 0);
165 int32_t
y = (ypos > 0 ? (int32_t)std::round(ypos) : 0);
168 if(glfwGetMouseButton(
window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
171 state->mouse_x_position =
x;
172 state->mouse_y_position =
y;
179 glfwGetCursorPos(
window, &xpos, &ypos);
180 int32_t x = (xpos > 0 ? (int32_t)std::round(xpos) : 0);
181 int32_t y = (ypos > 0 ? (int32_t)std::round(ypos) : 0);
185 if(button == GLFW_MOUSE_BUTTON_LEFT) {
187 state->win_ptr->left_mouse_down =
true;
188 }
else if(button == GLFW_MOUSE_BUTTON_RIGHT) {
190 }
else if(button == GLFW_MOUSE_BUTTON_MIDDLE) {
193 state->mouse_x_position = x;
194 state->mouse_y_position = y;
197 if(button == GLFW_MOUSE_BUTTON_LEFT) {
199 state->win_ptr->left_mouse_down =
false;
200 }
else if(button == GLFW_MOUSE_BUTTON_RIGHT) {
202 }
else if(button == GLFW_MOUSE_BUTTON_MIDDLE) {
205 state->mouse_x_position = x;
206 state->mouse_y_position = y;
215 glfwGetCursorPos(
window, &xpos, &ypos);
216 int32_t x = (xpos > 0 ? (int32_t)std::round(xpos) : 0);
217 int32_t y = (ypos > 0 ? (int32_t)std::round(ypos) : 0);
220 state->mouse_x_position = x;
221 state->mouse_y_position = y;
226 if(state->ui_state.edit_target) {
227 state->on_text(codepoint);
235 if(glfwGetWindowAttrib(
window, GLFW_MAXIMIZED) == GLFW_MAXIMIZED)
237 else if(glfwGetWindowAttrib(
window, GLFW_ICONIFIED) == GLFW_ICONIFIED)
242 glfwGetFramebufferSize(
window, &width, &height);
243 state->on_resize(width, height, t);
244 state->x_size = width;
245 state->y_size = height;
268 if(state->user_settings.mute_on_focus_lost) {
272 if(state->user_settings.mute_on_focus_lost) {
279 game_state.
win_ptr = std::make_unique<window_data_impl>();
285 glfwSetErrorCallback(glfw_error_callback);
289 glfwWindowHint(GLFW_RESIZABLE, GL_TRUE);
290 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
291 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 5);
292 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
293 glfwWindowHint(GLFW_OPENGL_DEBUG_CONTEXT, GL_TRUE);
297 auto*
window = glfwCreateWindow(params.
size_x, params.
size_y,
"Project Alice", NULL, NULL);
302 glfwSetWindowUserPointer(
window, &game_state);
306 glfwSetKeyCallback(
window, key_callback);
307 glfwSetCursorPosCallback(
window, cursor_position_callback);
316 glfwSetWindowSizeLimits(
window, 640, 400, 2400, 1800);
319 glfwGetFramebufferSize(game_state.
win_ptr->window, &width, &height);
320 glfwGetWindowSize(game_state.
win_ptr->window, &width, &height);
321 const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor());
322 glfwSetWindowMonitor(
window, glfwGetPrimaryMonitor(), 0, 0, mode->width, mode->height, mode->refreshRate);
323 game_state.
win_ptr->in_fullscreen=
true;
337 while(!glfwWindowShouldClose(
window)) {
347 glfwDestroyWindow(
window);
356 std::fprintf(stderr,
"%s", content.c_str());
358 std::exit(EXIT_FAILURE);
void initialize_opengl(sys::state &state)
void pause_all(sys::state &state)
void initialize_sound_system(sys::state &state)
void resume_all(sys::state &state)
void update_music_track(sys::state &state)
void start_music(sys::state &state, float v)
void set_borderless_full_screen(sys::state &game_state, bool fullscreen)
void get_window_size(sys::state const &game_state, int &width, int &height)
bool is_key_depressed(sys::state const &game_state, sys::virtual_key key)
void framebuffer_size_callback(GLFWwindow *window, int width, int height)
bool is_in_fullscreen(sys::state const &game_state)
sys::key_modifiers get_current_modifiers()
void window_maximize_callback(GLFWwindow *window, int maximized)
void emit_error_message(std::string const &content, bool fatal)
void window_size_callback(GLFWwindow *window, int width, int height)
void close_window(sys::state &game_state)
void focus_callback(GLFWwindow *window, int focused)
void window_iconify_callback(GLFWwindow *window, int iconified)
void change_cursor(sys::state &state, cursor_type type)
void on_window_change(GLFWwindow *window)
void mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
void scroll_callback(GLFWwindow *window, double xoffset, double yoffset)
void create_window(sys::state &game_state, creation_parameters const ¶ms)
void character_callback(GLFWwindow *window, unsigned int codepoint)
user_settings_s user_settings
std::unique_ptr< window::window_data_impl > win_ptr
bool borderless_fullscreen