From 45c799f71e6f0db1de27bdd601c0d441f0012468 Mon Sep 17 00:00:00 2001 From: WBoerenkamps Date: Wed, 18 Dec 2024 14:43:41 +0100 Subject: camera space working --- src/test/InputTest.cpp | 59 ++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 12 deletions(-) (limited to 'src/test') diff --git a/src/test/InputTest.cpp b/src/test/InputTest.cpp index 2d844d4..a7b1b25 100644 --- a/src/test/InputTest.cpp +++ b/src/test/InputTest.cpp @@ -37,10 +37,10 @@ public: RenderSystem render{mediator}; EventManager event_manager{mediator}; //GameObject camera; - + int offset = 100; protected: void SetUp() override { - GameObject obj = mgr.new_object("camera", "camera", vec2{0, 0}, 0, 1); + GameObject obj = mgr.new_object("camera", "camera", vec2{offset, offset}, 0, 1); auto & camera = obj.add_component(ivec2{500, 500}, vec2{500, 500}, Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f}); @@ -76,8 +76,8 @@ TEST_F(InputTest, MouseDown) { EventHandler on_mouse_down = [&](const MousePressEvent & event) { mouse_triggered = true; //middle of the screen = 0,0 - EXPECT_EQ(event.mouse_pos.x, 0); - EXPECT_EQ(event.mouse_pos.y, 0); + EXPECT_EQ(event.mouse_pos.x, offset); + EXPECT_EQ(event.mouse_pos.y, offset); EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE); return false; }; @@ -101,8 +101,8 @@ TEST_F(InputTest, MouseUp) { bool function_triggered = false; EventHandler on_mouse_release = [&](const MouseReleaseEvent & e) { function_triggered = true; - EXPECT_EQ(e.mouse_pos.x, 0); - EXPECT_EQ(e.mouse_pos.y, 0); + EXPECT_EQ(e.mouse_pos.x, offset); + EXPECT_EQ(e.mouse_pos.y, offset); EXPECT_EQ(e.button, MouseButton::LEFT_MOUSE); return false; }; @@ -125,8 +125,8 @@ TEST_F(InputTest, MouseMove) { bool function_triggered = false; EventHandler on_mouse_move = [&](const MouseMoveEvent & e) { function_triggered = true; - EXPECT_EQ(e.mouse_pos.x, 0); - EXPECT_EQ(e.mouse_pos.y, 0); + EXPECT_EQ(e.mouse_pos.x, offset); + EXPECT_EQ(e.mouse_pos.y, offset); EXPECT_EQ(e.mouse_delta.x, 10); EXPECT_EQ(e.mouse_delta.y, 10); return false; @@ -199,8 +199,8 @@ TEST_F(InputTest, MouseClick) { EventHandler on_mouse_click = [&](const MouseClickEvent & event) { on_click_triggered = true; EXPECT_EQ(event.button, MouseButton::LEFT_MOUSE); - EXPECT_EQ(event.mouse_pos.x, 0); - EXPECT_EQ(event.mouse_pos.y, 0); + EXPECT_EQ(event.mouse_pos.x, offset); + EXPECT_EQ(event.mouse_pos.y, offset); return false; }; event_manager.subscribe(on_mouse_click); @@ -215,8 +215,8 @@ TEST_F(InputTest, testButtonClick) { GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1); bool button_clicked = false; std::function on_click = [&]() { button_clicked = true; }; - auto & button = button_obj.add_component