diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-28 09:02:02 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-11-28 09:02:02 +0100 |
commit | 34218886689a57004576486976038027732d8bcc (patch) | |
tree | 28eb5b594920fbb3c668564e01818bfa50b6fc56 /src/crepe/system | |
parent | 570acb7e9258edcd6a06fff4dd2ce0ff12a3e873 (diff) |
make format
Diffstat (limited to 'src/crepe/system')
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 57 |
1 files changed, 28 insertions, 29 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 4695620..beeef87 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -80,46 +80,45 @@ void InputSystem::update() { } void InputSystem::handle_move(const SDLContext::EventData & event_data) { - ComponentManager & mgr = this->component_manager; + ComponentManager & mgr = this->component_manager; - RefVector<Button> buttons = mgr.get_components_by_type<Button>(); - + RefVector<Button> buttons = mgr.get_components_by_type<Button>(); - for (Button & button : buttons) { - RefVector<Transform> transform_vec = mgr.get_components_by_id<Transform>(button.game_object_id); + for (Button & button : buttons) { + RefVector<Transform> transform_vec + = mgr.get_components_by_id<Transform>(button.game_object_id); OptionalRef<Transform> transform(transform_vec.front().get()); - if (!transform) continue; - - bool was_hovering = button.hover; // Store previous hover state - - // Check if the mouse is inside the button - if (button.active && is_mouse_inside_button(event_data, button, transform)) { - button.hover = true; - - // Trigger the on_enter callback if the hover state just changed to true - if (!was_hovering && button.on_enter) { - button.on_enter(); - } - } else { - button.hover = false; - - // Trigger the on_exit callback if the hover state just changed to false - if (was_hovering && button.on_exit) { - button.on_exit(); - } - } - } -} + if (!transform) continue; + + bool was_hovering = button.hover; // Store previous hover state + // Check if the mouse is inside the button + if (button.active && is_mouse_inside_button(event_data, button, transform)) { + button.hover = true; + + // Trigger the on_enter callback if the hover state just changed to true + if (!was_hovering && button.on_enter) { + button.on_enter(); + } + } else { + button.hover = false; + + // Trigger the on_exit callback if the hover state just changed to false + if (was_hovering && button.on_exit) { + button.on_exit(); + } + } + } +} void InputSystem::handle_click(const SDLContext::EventData & event_data) { ComponentManager & mgr = this->component_manager; RefVector<Button> buttons = mgr.get_components_by_type<Button>(); - for (Button & button : buttons) { - RefVector<Transform> transform_vec = mgr.get_components_by_id<Transform>(button.game_object_id); + RefVector<Transform> transform_vec + = mgr.get_components_by_id<Transform>(button.game_object_id); OptionalRef<Transform> transform(transform_vec.front().get()); if (button.active && is_mouse_inside_button(event_data, button, transform)) { |