aboutsummaryrefslogtreecommitdiff
path: root/src/test/InputTest.cpp
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-18 14:43:41 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-18 14:43:41 +0100
commit45c799f71e6f0db1de27bdd601c0d441f0012468 (patch)
treee776e6455f1499d643f8f282c9b2c60b0af69d07 /src/test/InputTest.cpp
parent81404db80bbf9463c3d535ae389e7fbb753a902c (diff)
camera space working
Diffstat (limited to 'src/test/InputTest.cpp')
-rw-r--r--src/test/InputTest.cpp59
1 files changed, 47 insertions, 12 deletions
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<Camera>(ivec2{500, 500}, vec2{500, 500},
Camera::Data{.bg_color = Color::WHITE, .zoom = 1.0f});
@@ -76,8 +76,8 @@ TEST_F(InputTest, MouseDown) {
EventHandler<MousePressEvent> 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<MouseReleaseEvent> 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<MouseMoveEvent> 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<MouseClickEvent> 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<MouseClickEvent>(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<void()> on_click = [&]() { button_clicked = true; };
- auto & button = button_obj.add_component<Button>(vec2{100, 100}, vec2{0, 0}, on_click);
-
+ auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0}, on_click);
+ // button.world_space =
bool hover = false;
button.active = true;
this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
@@ -229,7 +229,42 @@ TEST_F(InputTest, testButtonClick) {
event_manager.dispatch_events();
EXPECT_TRUE(button_clicked);
}
+TEST_F(InputTest, buttonPositionCamera) {
+ GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1);
+ bool button_clicked = false;
+ std::function<void()> on_click = [&]() { button_clicked = true; };
+ auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0}, on_click);
+ button.world_space = false;
+ bool hover = false;
+ button.active = true;
+ this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
+ input_system.update();
+ event_manager.dispatch_events();
+ EXPECT_FALSE(button_clicked);
+
+ this->simulate_mouse_click(300, 300, SDL_BUTTON_LEFT);
+ input_system.update();
+ event_manager.dispatch_events();
+ EXPECT_TRUE(button_clicked);
+}
+TEST_F(InputTest, buttonPositionWorld) {
+ GameObject button_obj = mgr.new_object("body", "person", vec2{50, 50}, 0, 1);
+ bool button_clicked = false;
+ std::function<void()> on_click = [&]() { button_clicked = true; };
+ auto & button = button_obj.add_component<Button>(vec2{10, 10}, vec2{0, 0}, on_click);
+ button.world_space = true;
+ bool hover = false;
+ button.active = true;
+ this->simulate_mouse_click(999, 999, SDL_BUTTON_LEFT);
+ input_system.update();
+ event_manager.dispatch_events();
+ EXPECT_FALSE(button_clicked);
+ this->simulate_mouse_click(300, 300, SDL_BUTTON_LEFT);
+ input_system.update();
+ event_manager.dispatch_events();
+ EXPECT_FALSE(button_clicked);
+}
TEST_F(InputTest, testButtonHover) {
GameObject button_obj = mgr.new_object("body", "person", vec2{0, 0}, 0, 1);
bool button_clicked = false;