diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-09 14:14:11 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-09 14:14:11 +0100 |
commit | 65747afc0dadd7f0d9d93f1d0984f442c11eec82 (patch) | |
tree | 553691ec8fdb71cf23992ad3d9dd431241cef892 /src | |
parent | b7127b9f389179f6f3cc2f903c7a8e898834bd96 (diff) |
resize/move tests working
Diffstat (limited to 'src')
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 3 | ||||
-rw-r--r-- | src/crepe/system/InputSystem.cpp | 5 | ||||
-rw-r--r-- | src/test/InputTest.cpp | 36 |
3 files changed, 30 insertions, 14 deletions
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index b761ca1..ce8218a 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -7,8 +7,6 @@ #include <SDL2/SDL_surface.h> #include <SDL2/SDL_video.h> -#include <iostream> - #include <array> #include <cmath> #include <cstddef> @@ -443,7 +441,6 @@ void SDLContext::handle_window_event(const SDL_WindowEvent& window_event, event_list.push_back({SDLContext::EventType::WINDOW_EXPOSE, {}, {}, {}}); break; case SDL_WINDOWEVENT_RESIZED: - std::cout << "window resize" << std::endl; event_list.push_back({SDLContext::EventType::WINDOW_RESIZE, {}, {}, {{}, {window_event.data1, window_event.data2}}}); break; diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp index 7c33308..dd45821 100644 --- a/src/crepe/system/InputSystem.cpp +++ b/src/crepe/system/InputSystem.cpp @@ -1,6 +1,4 @@ -#include <iostream> - #include "../api/Button.h" #include "../manager/ComponentManager.h" #include "../manager/EventManager.h" @@ -37,7 +35,6 @@ void InputSystem::update() { - (current_cam.viewport_size.x / 2); for (const SDLContext::EventData & event : event_list) { - std::cout << "event type: " << event.event_type << std::endl; // Only calculate mouse coordinates for relevant events if (event.event_type == SDLContext::EventType::MOUSEDOWN || event.event_type == SDLContext::EventType::MOUSEUP @@ -106,7 +103,6 @@ void InputSystem::update() { break; } } else { - std::cout << "non mouse event" << std::endl; // Handle non-mouse events switch (event.event_type) { case SDLContext::EventType::KEYDOWN: @@ -122,7 +118,6 @@ void InputSystem::update() { event_mgr.queue_event<WindowExposeEvent>({}); break; case SDLContext::EventType::WINDOW_RESIZE: - std::cout << "input system queue" << std::endl; event_mgr.queue_event<WindowResizeEvent>(WindowResizeEvent{.dimensions = event.window_data.resize_dimension}); break; case SDLContext::EventType::WINDOW_MOVE: diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp index 7d4a017..0c81cfa 100644 --- a/src/test/InputTest.cpp +++ b/src/test/InputTest.cpp @@ -1,7 +1,4 @@ #include <gtest/gtest.h> - -#include <iostream> - #define protected public #define private public #include "api/KeyCodes.h" @@ -294,12 +291,15 @@ TEST_F(InputTest, testButtonHover) { } TEST_F(InputTest, WindowResizeTest) { + GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1); + auto & camera = obj.add_component<Camera>( + ivec2{0, 0}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + camera.active = true; bool callback_triggered = false; EventHandler<WindowResizeEvent> on_window_resize = [&](const WindowResizeEvent & event) { - std::cout << "test callback" << std::endl; callback_triggered = true; - EXPECT_EQ(event.dimensions.x, 0); - EXPECT_EQ(event.dimensions.y, 0); + EXPECT_EQ(event.dimensions.x, 800); + EXPECT_EQ(event.dimensions.y, 600); return false; }; event_manager.subscribe<WindowResizeEvent>(on_window_resize); @@ -314,3 +314,27 @@ TEST_F(InputTest, WindowResizeTest) { event_manager.dispatch_events(); EXPECT_TRUE(callback_triggered); } +TEST_F(InputTest, WindowMoveTest) { + GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1); + auto & camera = obj.add_component<Camera>( + ivec2{0, 0}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); + camera.active = true; + bool callback_triggered = false; + EventHandler<WindowMoveEvent> on_window_move = [&](const WindowMoveEvent & event) { + callback_triggered = true; + EXPECT_EQ(event.delta_move.x, 800); + EXPECT_EQ(event.delta_move.y, 600); + return false; + }; + event_manager.subscribe<WindowMoveEvent>(on_window_move); + SDL_Event resize_event; + SDL_zero(resize_event); + resize_event.type = SDL_WINDOWEVENT; + resize_event.window.event = SDL_WINDOWEVENT_MOVED; + resize_event.window.data1 = 800; // new width + resize_event.window.data2 = 600; // new height + SDL_PushEvent(&resize_event); + input_system.update(); + event_manager.dispatch_events(); + EXPECT_TRUE(callback_triggered); +} |