From 2ad609ac1b08894b607fb56d74f45fffaba6c9ed Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 4 Dec 2024 11:55:07 +0100 Subject: make format --- src/crepe/system/InputSystem.cpp | 58 +++++++++++++++++++++++----------------- src/example/button.cpp | 28 +++++++++---------- 2 files changed, 46 insertions(+), 40 deletions(-) diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index e746ab0..f590649 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -6,7 +6,6 @@ #include using namespace crepe; - void InputSystem::update() { ComponentManager & mgr = this->component_manager; EventManager & event_mgr = EventManager::get_instance(); @@ -21,18 +20,24 @@ void InputSystem::update() { break; } if (!curr_cam_ref) return; - Camera& current_cam = curr_cam_ref; - RefVector transform_vec = mgr.get_components_by_id(current_cam.game_object_id); - Transform& cam_transform = transform_vec.front().get(); - int camera_origin_x = cam_transform.position.x + current_cam.offset.x - (current_cam.viewport_size.x / 2); - int camera_origin_y = cam_transform.position.y + current_cam.offset.y - (current_cam.viewport_size.y / 2); - + Camera & current_cam = curr_cam_ref; + RefVector transform_vec + = mgr.get_components_by_id(current_cam.game_object_id); + Transform & cam_transform = transform_vec.front().get(); + int camera_origin_x + = cam_transform.position.x + current_cam.offset.x - (current_cam.viewport_size.x / 2); + int camera_origin_y + = cam_transform.position.y + current_cam.offset.y - (current_cam.viewport_size.y / 2); + for (const SDLContext::EventData & event : event_list) { int world_mouse_x = event.mouse_position.first + camera_origin_x; int world_mouse_y = event.mouse_position.second + camera_origin_y; // check if the mouse is within the viewport - bool mouse_in_viewport = !(world_mouse_x < camera_origin_x || world_mouse_x > camera_origin_x + current_cam.viewport_size.x || - world_mouse_y < camera_origin_y || world_mouse_y > camera_origin_y + current_cam.viewport_size.y); + bool mouse_in_viewport + = !(world_mouse_x < camera_origin_x + || world_mouse_x > camera_origin_x + current_cam.viewport_size.x + || world_mouse_y < camera_origin_y + || world_mouse_y > camera_origin_y + current_cam.viewport_size.y); switch (event.event_type) { case SDLContext::EventType::KEYDOWN: @@ -47,7 +52,7 @@ void InputSystem::update() { }); break; case SDLContext::EventType::MOUSEDOWN: - if(!mouse_in_viewport){ + if (!mouse_in_viewport) { break; } event_mgr.queue_event(MousePressEvent{ @@ -59,7 +64,7 @@ void InputSystem::update() { last_mouse_button = event.mouse_button; break; case SDLContext::EventType::MOUSEUP: { - if(!mouse_in_viewport){ + if (!mouse_in_viewport) { break; } event_mgr.queue_event(MouseReleaseEvent{ @@ -84,7 +89,7 @@ void InputSystem::update() { } } break; case SDLContext::EventType::MOUSEMOVE: - if(!mouse_in_viewport){ + if (!mouse_in_viewport) { break; } event_mgr.queue_event(MouseMoveEvent{ @@ -110,7 +115,8 @@ void InputSystem::update() { } } } -void InputSystem::handle_move(const SDLContext::EventData & event_data, const int& world_mouse_x, const int& world_mouse_y) { +void InputSystem::handle_move(const SDLContext::EventData & event_data, + const int & world_mouse_x, const int & world_mouse_y) { ComponentManager & mgr = this->component_manager; RefVector