aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/InputSystem.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/system/InputSystem.cpp')
-rw-r--r--src/crepe/system/InputSystem.cpp43
1 files changed, 24 insertions, 19 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp
index 1cd3974..0cf5af1 100644
--- a/src/crepe/system/InputSystem.cpp
+++ b/src/crepe/system/InputSystem.cpp
@@ -6,7 +6,6 @@
using namespace crepe;
-
void InputSystem::update() {
ComponentManager & mgr = this->component_manager;
EventManager & event_mgr = EventManager::get_instance();
@@ -21,11 +20,14 @@ void InputSystem::update() {
break;
}
if (!curr_cam_ref) return;
- Camera& current_cam = curr_cam_ref;
- RefVector<Transform> transform_vec = mgr.get_components_by_id<Transform>(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> transform_vec
+ = mgr.get_components_by_id<Transform>(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;
@@ -98,7 +100,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<Button> buttons = mgr.get_components_by_type<Button>();
@@ -110,7 +113,8 @@ void InputSystem::handle_move(const SDLContext::EventData & event_data, const in
if (!transform) continue;
bool was_hovering = button.hover;
- if (button.active && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
+ if (button.active
+ && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
button.hover = true;
if (!was_hovering && button.on_enter) {
button.on_enter();
@@ -125,7 +129,8 @@ void InputSystem::handle_move(const SDLContext::EventData & event_data, const in
}
}
-void InputSystem::handle_click(const MouseButton& mouse_button, const int& world_mouse_x, const int& world_mouse_y) {
+void InputSystem::handle_click(const MouseButton & mouse_button, const int & world_mouse_x,
+ const int & world_mouse_y) {
ComponentManager & mgr = this->component_manager;
RefVector<Button> buttons = mgr.get_components_by_type<Button>();
@@ -135,21 +140,21 @@ void InputSystem::handle_click(const MouseButton& mouse_button, const int& world
= mgr.get_components_by_id<Transform>(button.game_object_id);
OptionalRef<Transform> transform(transform_vec.front().get());
- if (button.active && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
+ if (button.active
+ && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
handle_button_press(button);
}
}
}
-bool InputSystem::is_mouse_inside_button(
- const int& mouse_x, const int& mouse_y,
- const Button & button, const Transform & transform) {
- int half_width = button.width / 2;
- int half_height = button.height / 2;
- return mouse_x >= transform.position.x - half_width
- && mouse_x <= transform.position.x + half_width
- && mouse_y >= transform.position.y - half_height
- && mouse_y <= transform.position.y + half_height;
+bool InputSystem::is_mouse_inside_button(const int & mouse_x, const int & mouse_y,
+ const Button & button, const Transform & transform) {
+ int half_width = button.width / 2;
+ int half_height = button.height / 2;
+ return mouse_x >= transform.position.x - half_width
+ && mouse_x <= transform.position.x + half_width
+ && mouse_y >= transform.position.y - half_height
+ && mouse_y <= transform.position.y + half_height;
}
void InputSystem::handle_button_press(Button & button) {