diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-09 14:20:39 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-09 14:20:39 +0100 |
commit | 2ff3369a7aaf98936bf93f1c7c0dbfcaa38c31d7 (patch) | |
tree | b8b3fae16111f4d5df73077c5e0e28a1639c9f3f /src/crepe/system/InputSystem.cpp | |
parent | b6167713c11e26f513f0c5b82701e6cee88de8cb (diff) |
make format
Diffstat (limited to 'src/crepe/system/InputSystem.cpp')
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 33 |
1 files changed, 20 insertions, 13 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index dd45821..f5d8536 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -30,13 +30,13 @@ void InputSystem::update() { ivec2 camera_origin; camera_origin.y = cam_transform.position.y + current_cam.data.postion_offset.y - - (current_cam.viewport_size.y / 2); + - (current_cam.viewport_size.y / 2); camera_origin.x = cam_transform.position.x + current_cam.data.postion_offset.x - - (current_cam.viewport_size.x / 2); + - (current_cam.viewport_size.x / 2); for (const SDLContext::EventData & event : event_list) { // Only calculate mouse coordinates for relevant events - if (event.event_type == SDLContext::EventType::MOUSEDOWN + if (event.event_type == SDLContext::EventType::MOUSEDOWN || event.event_type == SDLContext::EventType::MOUSEUP || event.event_type == SDLContext::EventType::MOUSEMOVE || event.event_type == SDLContext::EventType::MOUSEWHEEL) { @@ -45,10 +45,11 @@ void InputSystem::update() { int adjusted_mouse_y = event.mouse_data.mouse_position.y + camera_origin.y; // Check if the mouse is within the viewport - bool mouse_in_viewport = !(adjusted_mouse_x < camera_origin.x - || adjusted_mouse_x > camera_origin.x + current_cam.viewport_size.x - || adjusted_mouse_y < camera_origin.y - || adjusted_mouse_y > camera_origin.y + current_cam.viewport_size.y); + bool mouse_in_viewport + = !(adjusted_mouse_x < camera_origin.x + || adjusted_mouse_x > camera_origin.x + current_cam.viewport_size.x + || adjusted_mouse_y < camera_origin.y + || adjusted_mouse_y > camera_origin.y + current_cam.viewport_size.y); if (!mouse_in_viewport) continue; @@ -78,7 +79,8 @@ void InputSystem::update() { .mouse_pos = {adjusted_mouse_x, adjusted_mouse_y}, .button = event.mouse_data.mouse_button, }); - this->handle_click(event.mouse_data.mouse_button, adjusted_mouse_x, adjusted_mouse_y); + this->handle_click(event.mouse_data.mouse_button, adjusted_mouse_x, + adjusted_mouse_y); } break; } @@ -106,7 +108,8 @@ void InputSystem::update() { // Handle non-mouse events switch (event.event_type) { case SDLContext::EventType::KEYDOWN: - event_mgr.queue_event<KeyPressEvent>({.repeat = event.key_data.key_repeat, .key = event.key_data.key}); + event_mgr.queue_event<KeyPressEvent>( + {.repeat = event.key_data.key_repeat, .key = event.key_data.key}); break; case SDLContext::EventType::KEYUP: event_mgr.queue_event<KeyReleaseEvent>({.key = event.key_data.key}); @@ -118,10 +121,12 @@ void InputSystem::update() { event_mgr.queue_event<WindowExposeEvent>({}); break; case SDLContext::EventType::WINDOW_RESIZE: - event_mgr.queue_event<WindowResizeEvent>(WindowResizeEvent{.dimensions = event.window_data.resize_dimension}); + event_mgr.queue_event<WindowResizeEvent>( + WindowResizeEvent{.dimensions = event.window_data.resize_dimension}); break; case SDLContext::EventType::WINDOW_MOVE: - event_mgr.queue_event<WindowMoveEvent>({.delta_move = event.window_data.move_delta}); + event_mgr.queue_event<WindowMoveEvent>( + {.delta_move = event.window_data.move_delta}); break; case SDLContext::EventType::WINDOW_MINIMIZE: event_mgr.queue_event<WindowMinimizeEvent>({}); @@ -155,7 +160,8 @@ void InputSystem::handle_move(const SDLContext::EventData & event_data, bool was_hovering = button.hover; if (button.active - && this->is_mouse_inside_button(adjusted_mouse_x, adjusted_mouse_y, button, transform)) { + && this->is_mouse_inside_button(adjusted_mouse_x, adjusted_mouse_y, button, + transform)) { button.hover = true; if (!was_hovering && button.on_mouse_enter) { button.on_mouse_enter(); @@ -182,7 +188,8 @@ void InputSystem::handle_click(const MouseButton & mouse_button, const int adjus Transform & transform = transform_vec.front().get(); if (button.active - && this->is_mouse_inside_button(adjusted_mouse_x, adjusted_mouse_y, button, transform)) { + && this->is_mouse_inside_button(adjusted_mouse_x, adjusted_mouse_y, button, + transform)) { this->handle_button_press(button); } } |