aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/system/InputSystem.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-25 11:17:20 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-11-25 11:17:20 +0100
commit596358ffea72aec48b389609349f717e76396ae2 (patch)
tree4c023d4797f18c5b240765b5fef07fc793f52f42 /src/crepe/system/InputSystem.cpp
parent327154fd428e0798eea544d9f073f8e1293aa158 (diff)
button test working
Diffstat (limited to 'src/crepe/system/InputSystem.cpp')
-rw-r--r--src/crepe/system/InputSystem.cpp31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp
index 4560411..a3e28e4 100644
--- a/src/crepe/system/InputSystem.cpp
+++ b/src/crepe/system/InputSystem.cpp
@@ -56,10 +56,6 @@ void InputSystem::update() {
if (last_mouse_button == event.mouse_button &&
std::abs(delta_x) <= click_tolerance &&
std::abs(delta_y) <= click_tolerance) {
- std::cout << "Click registered at (" << event.mouse_position.first
- << ", " << event.mouse_position.second << ") with button "
- << static_cast<int>(event.mouse_button) << std::endl;
-
event_mgr.queue_event<MouseClickEvent>(MouseClickEvent{
.mouse_x = event.mouse_position.first,
.mouse_y = event.mouse_position.second,
@@ -67,8 +63,6 @@ void InputSystem::update() {
});
this->handle_click(mouse_release_event);
- } else {
- std::cout << "Mouse release did not register as a click." << std::endl;
}
break;
@@ -101,6 +95,25 @@ void InputSystem::update() {
}
}
+void InputSystem::handle_move(const MouseMoveEvent){
+ ComponentManager &mgr = this->component_manager;
+
+ // Get the buttons and transforms
+ std::vector<std::reference_wrapper<Button>> buttons = mgr.get_components_by_type<Button>();
+ std::vector<std::reference_wrapper<Transform>> transforms = mgr.get_components_by_type<Transform>();
+
+ for (Button &button : buttons) {
+ Transform* transform = find_transform_for_button(button, transforms);
+ if (!transform) continue;
+
+ if (button.interactable && is_mouse_inside_button(event, button, *transform)) {
+ button.hover = true;
+ }else{
+ button.hover = false;
+ }
+ }
+}
+
void InputSystem::handle_click(const MouseReleaseEvent event) {
ComponentManager &mgr = this->component_manager;
@@ -134,11 +147,11 @@ bool InputSystem::is_mouse_inside_button(const MouseReleaseEvent &event, const B
void InputSystem::handle_button_press(Button &button, const MouseReleaseEvent &event) {
if (button.is_toggle) {
- if (!button.is_pressed) {
- button.on_click();
+ if (!button.is_pressed && button.on_click) {
+ button.on_click();
}
button.is_pressed = !button.is_pressed;
- } else {
+ } else if(button.on_click) {
button.on_click();
}
}