aboutsummaryrefslogtreecommitdiff
path: root/src/crepe
diff options
context:
space:
mode:
authorWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-03 12:39:41 +0100
committerWBoerenkamps <wrj.boerenkamps@student.avans.nl>2024-12-03 12:39:41 +0100
commitdb181bafbe57e8df5f1df5c0871865701ac62ecc (patch)
tree7667a2492a9b49d4fa47634fd23d4f3a814e2e49 /src/crepe
parent0c9d708d4d44b2de0bb8c8f59e7e6fb098eca272 (diff)
make format
Diffstat (limited to 'src/crepe')
-rw-r--r--src/crepe/api/Button.h1
-rw-r--r--src/crepe/facade/SDLContext.cpp2
-rw-r--r--src/crepe/facade/SDLContext.h5
-rw-r--r--src/crepe/system/InputSystem.cpp43
-rw-r--r--src/crepe/system/InputSystem.h33
5 files changed, 45 insertions, 39 deletions
diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h
index 0dfad5d..290bb2f 100644
--- a/src/crepe/api/Button.h
+++ b/src/crepe/api/Button.h
@@ -4,7 +4,6 @@
#include "UiObject.h"
-
namespace crepe {
/**
diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp
index 03b0cdc..a657373 100644
--- a/src/crepe/facade/SDLContext.cpp
+++ b/src/crepe/facade/SDLContext.cpp
@@ -16,8 +16,8 @@
#include <stdexcept>
#include "../api/Camera.h"
-#include "../api/EventManager.h"
#include "../api/Config.h"
+#include "../api/EventManager.h"
#include "../api/Sprite.h"
#include "../api/Texture.h"
#include "../util/Log.h"
diff --git a/src/crepe/facade/SDLContext.h b/src/crepe/facade/SDLContext.h
index a56232f..2228950 100644
--- a/src/crepe/facade/SDLContext.h
+++ b/src/crepe/facade/SDLContext.h
@@ -12,13 +12,12 @@
#include <utility>
#include "api/Camera.h"
+#include "api/Color.h"
#include "api/Event.h"
#include "api/KeyCodes.h"
#include "api/Sprite.h"
-#include "api/Transform.h"
-#include "api/Camera.h"
-#include "api/Color.h"
#include "api/Texture.h"
+#include "api/Transform.h"
#include "types.h"
namespace crepe {
diff --git a/src/crepe/system/InputSystem.cpp b/src/crepe/system/InputSystem.cpp
index 1cd3974..0cf5af1 100644
--- a/src/crepe/system/InputSystem.cpp
+++ b/src/crepe/system/InputSystem.cpp
@@ -6,7 +6,6 @@
using namespace crepe;
-
void InputSystem::update() {
ComponentManager & mgr = this->component_manager;
EventManager & event_mgr = EventManager::get_instance();
@@ -21,11 +20,14 @@ void InputSystem::update() {
break;
}
if (!curr_cam_ref) return;
- Camera& current_cam = curr_cam_ref;
- RefVector<Transform> transform_vec = mgr.get_components_by_id<Transform>(current_cam.game_object_id);
- Transform& cam_transform = transform_vec.front().get();
- int camera_origin_x = cam_transform.position.x + current_cam.offset.x - (current_cam.viewport_size.x / 2);
- int camera_origin_y = cam_transform.position.y + current_cam.offset.y - (current_cam.viewport_size.y / 2);
+ Camera & current_cam = curr_cam_ref;
+ RefVector<Transform> transform_vec
+ = mgr.get_components_by_id<Transform>(current_cam.game_object_id);
+ Transform & cam_transform = transform_vec.front().get();
+ int camera_origin_x
+ = cam_transform.position.x + current_cam.offset.x - (current_cam.viewport_size.x / 2);
+ int camera_origin_y
+ = cam_transform.position.y + current_cam.offset.y - (current_cam.viewport_size.y / 2);
for (const SDLContext::EventData & event : event_list) {
int world_mouse_x = event.mouse_position.first + camera_origin_x;
int world_mouse_y = event.mouse_position.second + camera_origin_y;
@@ -98,7 +100,8 @@ void InputSystem::update() {
}
}
-void InputSystem::handle_move(const SDLContext::EventData & event_data, const int& world_mouse_x, const int& world_mouse_y) {
+void InputSystem::handle_move(const SDLContext::EventData & event_data,
+ const int & world_mouse_x, const int & world_mouse_y) {
ComponentManager & mgr = this->component_manager;
RefVector<Button> buttons = mgr.get_components_by_type<Button>();
@@ -110,7 +113,8 @@ void InputSystem::handle_move(const SDLContext::EventData & event_data, const in
if (!transform) continue;
bool was_hovering = button.hover;
- if (button.active && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
+ if (button.active
+ && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
button.hover = true;
if (!was_hovering && button.on_enter) {
button.on_enter();
@@ -125,7 +129,8 @@ void InputSystem::handle_move(const SDLContext::EventData & event_data, const in
}
}
-void InputSystem::handle_click(const MouseButton& mouse_button, const int& world_mouse_x, const int& world_mouse_y) {
+void InputSystem::handle_click(const MouseButton & mouse_button, const int & world_mouse_x,
+ const int & world_mouse_y) {
ComponentManager & mgr = this->component_manager;
RefVector<Button> buttons = mgr.get_components_by_type<Button>();
@@ -135,21 +140,21 @@ void InputSystem::handle_click(const MouseButton& mouse_button, const int& world
= mgr.get_components_by_id<Transform>(button.game_object_id);
OptionalRef<Transform> transform(transform_vec.front().get());
- if (button.active && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
+ if (button.active
+ && is_mouse_inside_button(world_mouse_x, world_mouse_y, button, transform)) {
handle_button_press(button);
}
}
}
-bool InputSystem::is_mouse_inside_button(
- const int& mouse_x, const int& mouse_y,
- const Button & button, const Transform & transform) {
- int half_width = button.width / 2;
- int half_height = button.height / 2;
- return mouse_x >= transform.position.x - half_width
- && mouse_x <= transform.position.x + half_width
- && mouse_y >= transform.position.y - half_height
- && mouse_y <= transform.position.y + half_height;
+bool InputSystem::is_mouse_inside_button(const int & mouse_x, const int & mouse_y,
+ const Button & button, const Transform & transform) {
+ int half_width = button.width / 2;
+ int half_height = button.height / 2;
+ return mouse_x >= transform.position.x - half_width
+ && mouse_x <= transform.position.x + half_width
+ && mouse_y >= transform.position.y - half_height
+ && mouse_y <= transform.position.y + half_height;
}
void InputSystem::handle_button_press(Button & button) {
diff --git a/src/crepe/system/InputSystem.h b/src/crepe/system/InputSystem.h
index 4244d91..53f2c4e 100644
--- a/src/crepe/system/InputSystem.h
+++ b/src/crepe/system/InputSystem.h
@@ -21,26 +21,26 @@ class Transform;
*/
class InputSystem : public System {
public:
- using System::System;
+ using System::System;
- /**
+ /**
* \brief Updates the system, processing all input events.
* This method processes all events and triggers corresponding actions.
*/
- void update() override;
+ void update() override;
private:
- //! Reference to the currently active camera.
- OptionalRef<Camera> curr_cam_ref;
+ //! Reference to the currently active camera.
+ OptionalRef<Camera> curr_cam_ref;
- //! Stores the last position of the mouse when the button was pressed.
- std::pair<int, int> last_mouse_down_position{INFINITY, INFINITY};
+ //! Stores the last position of the mouse when the button was pressed.
+ std::pair<int, int> last_mouse_down_position{INFINITY, INFINITY};
- //! Stores the last mouse button pressed.
- MouseButton last_mouse_button = MouseButton::NONE;
+ //! Stores the last mouse button pressed.
+ MouseButton last_mouse_button = MouseButton::NONE;
//
- //! The tolerance in game units for detecting a mouse click.
- const int click_tolerance = 5;
+ //! The tolerance in game units for detecting a mouse click.
+ const int click_tolerance = 5;
/**
* \brief Handles the mouse click event.
@@ -50,7 +50,8 @@ private:
*
* This method processes the mouse click event and triggers the corresponding button action.
*/
- void handle_click(const MouseButton& mouse_button, const int& world_mouse_x, const int& world_mouse_y);
+ void handle_click(const MouseButton & mouse_button, const int & world_mouse_x,
+ const int & world_mouse_y);
/**
* \brief Handles the mouse movement event.
@@ -60,7 +61,8 @@ private:
*
* This method processes the mouse movement event and updates the button hover state.
*/
- void handle_move(const SDLContext::EventData& event_data, const int& world_mouse_x, const int& world_mouse_y);
+ void handle_move(const SDLContext::EventData & event_data, const int & world_mouse_x,
+ const int & world_mouse_y);
/**
* \brief Checks if the mouse position is inside the bounds of the button.
@@ -70,7 +72,8 @@ private:
* \param transform The transform component of the button.
* \return True if the mouse is inside the button, false otherwise.
*/
- bool is_mouse_inside_button(const int& world_mouse_x, const int& world_mouse_y, const Button& button, const Transform& transform);
+ bool is_mouse_inside_button(const int & world_mouse_x, const int & world_mouse_y,
+ const Button & button, const Transform & transform);
/**
* \brief Handles the button press event, calling the on_click callback if necessary.
@@ -78,7 +81,7 @@ private:
*
* This method triggers the on_click action for the button when it is pressed.
*/
- void handle_button_press(Button& button);
+ void handle_button_press(Button & button);
};
} // namespace crepe