diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-17 20:12:30 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-17 20:12:30 +0100 |
commit | eb9c76082d7d0ee0c3e55cb8eadfa5f8978bd8f2 (patch) | |
tree | 97b0a6c7ae7e0feaba856a1e3e3836fa91a4dc0b /src/test/InputTest.cpp | |
parent | b421eec1073c1fb4b99d46cc36c5c9cbd8d3c4a7 (diff) |
button improvements
Diffstat (limited to 'src/test/InputTest.cpp')
-rw-r--r-- | src/test/InputTest.cpp | 59 |
1 files changed, 38 insertions, 21 deletions
diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp index 2d844d4..6c40235 100644 --- a/src/test/InputTest.cpp +++ b/src/test/InputTest.cpp @@ -2,7 +2,6 @@ #include <crepe/manager/ResourceManager.h> #include <crepe/system/RenderSystem.h> - #define protected public #define private public @@ -214,8 +213,13 @@ TEST_F(InputTest, MouseClick) { TEST_F(InputTest, testButtonClick) { GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); bool button_clicked = false; - std::function<void()> on_click = [&]() { button_clicked = true; }; - auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click); + event_manager.subscribe<ButtonPressEvent>([&](const ButtonPressEvent & event) { + button_clicked = true; + EXPECT_EQ(event.meta_data.game_object_id, button_obj.id); + return false; + } + ); + auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}); bool hover = false; button.active = true; @@ -232,25 +236,21 @@ TEST_F(InputTest, testButtonClick) { TEST_F(InputTest, testButtonHover) { GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); - bool button_clicked = false; - std::function<void()> on_click = [&]() { button_clicked = true; }; - auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click); + bool button_hover = false; + event_manager.subscribe<ButtonEnterEvent>([&](const ButtonEnterEvent & event) { + button_hover = true; + EXPECT_EQ(event.meta_data.game_object_id, button_obj.id); + return false; + } + ); + event_manager.subscribe<ButtonExitEvent>([&](const ButtonExitEvent & event) { + button_hover = false; + EXPECT_EQ(event.meta_data.game_object_id, button_obj.id); + return false; + } + ); + auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}); button.active = true; - - // Mouse not on button - SDL_Event event; - SDL_zero(event); - event.type = SDL_MOUSEMOTION; - event.motion.x = 700; - event.motion.y = 700; - event.motion.xrel = 10; - event.motion.yrel = 10; - SDL_PushEvent(&event); - - input_system.update(); - event_manager.dispatch_events(); - EXPECT_FALSE(button.hover); - // Mouse on button SDL_Event hover_event; SDL_zero(hover_event); @@ -264,4 +264,21 @@ TEST_F(InputTest, testButtonHover) { input_system.update(); event_manager.dispatch_events(); EXPECT_TRUE(button.hover); + EXPECT_TRUE(button_hover); + // Mouse not on button + SDL_Event event; + SDL_zero(event); + event.type = SDL_MOUSEMOTION; + event.motion.x = 500; + event.motion.y = 500; + event.motion.xrel = 10; + event.motion.yrel = 10; + SDL_PushEvent(&event); + + input_system.update(); + event_manager.dispatch_events(); + EXPECT_FALSE(button.hover); + EXPECT_FALSE(button_hover); + + } |