aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-05 17:11:09 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-05 17:11:35 +0100
commit1f4e961d7f9d6887c807cac1a362f2d178b0860b (patch)
treec786c952924be7cd3cb54d603d512323f8adfbc2 /src/crepe/api
parentea764e4d4c8688953637f4afba96ec2223f5a7c1 (diff)
nitpick #55
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Button.h56
-rw-r--r--src/crepe/api/EventHandler.h58
-rw-r--r--src/crepe/api/IKeyListener.h22
-rw-r--r--src/crepe/api/IMouseListener.h42
-rw-r--r--src/crepe/api/UIObject.h6
5 files changed, 86 insertions, 98 deletions
diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h
index 578f21e..26e7526 100644
--- a/src/crepe/api/Button.h
+++ b/src/crepe/api/Button.h
@@ -6,38 +6,35 @@
namespace crepe {
-/**
- * \brief Represents a clickable UI button, derived from the UiObject class.
- *
- */
+//! Represents a clickable UI button, derived from the UiObject class.
class Button : public UIObject {
public:
/**
- * \brief Constructs a Button with the specified game object ID and dimensions.
- *
- * \param id The unique ID of the game object associated with this button.
- * \param Dimensions The width and height of the UIObject
- * \param offset The offset relative this GameObjects Transform
- * \param is_toggle Optional flag to indicate if the button is a toggle button. Defaults to false.
- * \param on_click callback function that will be invoked when the button is clicked.
- */
+ * \brief Constructs a Button with the specified game object ID and dimensions.
+ *
+ * \param id The unique ID of the game object associated with this button.
+ * \param dimensions The width and height of the UIObject
+ * \param offset The offset relative this GameObjects Transform
+ * \param is_toggle Optional flag to indicate if the button is a toggle button. Defaults to false.
+ * \param on_click callback function that will be invoked when the button is clicked.
+ */
Button(game_object_id_t id, const vec2 & dimensions, const vec2 & offset,
const std::function<void()> & on_click, bool is_toggle = false);
/**
- * \brief Indicates if the button is a toggle button (can be pressed and released).
- *
- * A toggle button allows for a pressed/released state, whereas a regular button
- * typically only has an on-click state.
- */
+ * \brief Indicates if the button is a toggle button (can be pressed and released).
+ *
+ * A toggle button allows for a pressed/released state, whereas a regular button
+ * typically only has an on-click state.
+ */
bool is_toggle = false;
- // TODO: toggle button in new class
+ // TODO: create separate toggle button class
/**
- * \brief The callback function to be executed when the button is clicked.
- *
- * This function is invoked whenever the button is clicked. It can be set to any
- * function that matches the signature `void()`.
- */
+ * \brief The callback function to be executed when the button is clicked.
+ *
+ * This function is invoked whenever the button is clicked. It can be set to any
+ * function that matches the signature `void()`.
+ */
std::function<void()> on_click = nullptr;
/**
@@ -59,18 +56,9 @@ public:
private:
//! friend relation for is_pressed and hover variables
friend class InputSystem;
- /**
- * \brief Indicates whether the toggle button is pressed
- *
- * This state indicates if the toggle button is pressed or not
- */
+ //! Indicates whether the toggle button is pressed
bool is_pressed = false;
-
- /**
- * \brief Indicates whether the mouse is currently hovering over the button.
- *
- * This is set to true when the mouse is over the button and false otherwise.
- */
+ //! Indicates whether the mouse is currently hovering over the button
bool hover = false;
public:
diff --git a/src/crepe/api/EventHandler.h b/src/crepe/api/EventHandler.h
index ef659fd..7bdd9a3 100644
--- a/src/crepe/api/EventHandler.h
+++ b/src/crepe/api/EventHandler.h
@@ -29,29 +29,29 @@ using EventHandler = std::function<bool(const EventType & e)>;
class IEventHandlerWrapper {
public:
/**
- * \brief Virtual destructor for IEventHandlerWrapper.
- */
+ * \brief Virtual destructor for IEventHandlerWrapper.
+ */
virtual ~IEventHandlerWrapper() = default;
/**
- * \brief Executes the handler with the given event.
- *
- * This method calls the `call()` method of the derived class, passing the event to the handler.
- *
- * \param e The event to be processed.
- * \return A boolean value indicating whether the event is handled.
- */
+ * \brief Executes the handler with the given event.
+ *
+ * This method calls the `call()` method of the derived class, passing the event to the handler.
+ *
+ * \param e The event to be processed.
+ * \return A boolean value indicating whether the event is handled.
+ */
bool exec(const Event & e);
private:
/**
- * \brief The method responsible for handling the event.
- *
- * This method is implemented by derived classes to process the event.
- *
- * \param e The event to be processed.
- * \return A boolean value indicating whether the event is handled.
- */
+ * \brief The method responsible for handling the event.
+ *
+ * This method is implemented by derived classes to process the event.
+ *
+ * \param e The event to be processed.
+ * \return A boolean value indicating whether the event is handled.
+ */
virtual bool call(const Event & e) = 0;
};
@@ -69,23 +69,23 @@ template <typename EventType>
class EventHandlerWrapper : public IEventHandlerWrapper {
public:
/**
- * \brief Constructs an EventHandlerWrapper with a given handler.
- *
- * The constructor takes an event handler function and stores it in the wrapper.
- *
- * \param handler The event handler function.
- */
+ * \brief Constructs an EventHandlerWrapper with a given handler.
+ *
+ * The constructor takes an event handler function and stores it in the wrapper.
+ *
+ * \param handler The event handler function.
+ */
explicit EventHandlerWrapper(const EventHandler<EventType> & handler);
private:
/**
- * \brief Calls the stored event handler with the event.
- *
- * This method casts the event to the appropriate type and calls the handler.
- *
- * \param e The event to be handled.
- * \return A boolean value indicating whether the event is handled.
- */
+ * \brief Calls the stored event handler with the event.
+ *
+ * This method casts the event to the appropriate type and calls the handler.
+ *
+ * \param e The event to be handled.
+ * \return A boolean value indicating whether the event is handled.
+ */
bool call(const Event & e) override;
//! The event handler function.
EventHandler<EventType> handler;
diff --git a/src/crepe/api/IKeyListener.h b/src/crepe/api/IKeyListener.h
index 6ded107..180a0a6 100644
--- a/src/crepe/api/IKeyListener.h
+++ b/src/crepe/api/IKeyListener.h
@@ -14,9 +14,9 @@ namespace crepe {
class IKeyListener {
public:
/**
- * \brief Constructs an IKeyListener with a specified channel.
- * \param channel The channel ID for event handling.
- */
+ * \brief Constructs an IKeyListener with a specified channel.
+ * \param channel The channel ID for event handling.
+ */
IKeyListener(event_channel_t channel = EventManager::CHANNEL_ALL);
virtual ~IKeyListener();
IKeyListener(const IKeyListener &) = delete;
@@ -25,17 +25,17 @@ public:
IKeyListener(IKeyListener &&) = delete;
/**
- * \brief Pure virtual function to handle key press events.
- * \param event The key press event to handle.
- * \return True if the event was handled, false otherwise.
- */
+ * \brief Pure virtual function to handle key press events.
+ * \param event The key press event to handle.
+ * \return True if the event was handled, false otherwise.
+ */
virtual bool on_key_pressed(const KeyPressEvent & event) = 0;
/**
- * \brief Pure virtual function to handle key release events.
- * \param event The key release event to handle.
- * \return True if the event was handled, false otherwise.
- */
+ * \brief Pure virtual function to handle key release events.
+ * \param event The key release event to handle.
+ * \return True if the event was handled, false otherwise.
+ */
virtual bool on_key_released(const KeyReleaseEvent & event) = 0;
private:
diff --git a/src/crepe/api/IMouseListener.h b/src/crepe/api/IMouseListener.h
index 9e4fdf7..e19897d 100644
--- a/src/crepe/api/IMouseListener.h
+++ b/src/crepe/api/IMouseListener.h
@@ -14,9 +14,9 @@ namespace crepe {
class IMouseListener {
public:
/**
- * \brief Constructs an IMouseListener with a specified channel.
- * \param channel The channel ID for event handling.
- */
+ * \brief Constructs an IMouseListener with a specified channel.
+ * \param channel The channel ID for event handling.
+ */
IMouseListener(event_channel_t channel = EventManager::CHANNEL_ALL);
virtual ~IMouseListener();
IMouseListener & operator=(const IMouseListener &) = delete;
@@ -25,36 +25,36 @@ public:
IMouseListener(IMouseListener &&) = delete;
/**
- * \brief Move assignment operator (deleted).
- */
+ * \brief Move assignment operator (deleted).
+ */
IMouseListener & operator=(IMouseListener &&) = delete;
/**
- * \brief Handles a mouse click event.
- * \param event The mouse click event to handle.
- * \return True if the event was handled, false otherwise.
- */
+ * \brief Handles a mouse click event.
+ * \param event The mouse click event to handle.
+ * \return True if the event was handled, false otherwise.
+ */
virtual bool on_mouse_clicked(const MouseClickEvent & event) = 0;
/**
- * \brief Handles a mouse press event.
- * \param event The mouse press event to handle.
- * \return True if the event was handled, false otherwise.
- */
+ * \brief Handles a mouse press event.
+ * \param event The mouse press event to handle.
+ * \return True if the event was handled, false otherwise.
+ */
virtual bool on_mouse_pressed(const MousePressEvent & event) = 0;
/**
- * \brief Handles a mouse release event.
- * \param event The mouse release event to handle.
- * \return True if the event was handled, false otherwise.
- */
+ * \brief Handles a mouse release event.
+ * \param event The mouse release event to handle.
+ * \return True if the event was handled, false otherwise.
+ */
virtual bool on_mouse_released(const MouseReleaseEvent & event) = 0;
/**
- * \brief Handles a mouse move event.
- * \param event The mouse move event to handle.
- * \return True if the event was handled, false otherwise.
- */
+ * \brief Handles a mouse move event.
+ * \param event The mouse move event to handle.
+ * \return True if the event was handled, false otherwise.
+ */
virtual bool on_mouse_moved(const MouseMoveEvent & event) = 0;
private:
diff --git a/src/crepe/api/UIObject.h b/src/crepe/api/UIObject.h
index c8987dc..f7f4fba 100644
--- a/src/crepe/api/UIObject.h
+++ b/src/crepe/api/UIObject.h
@@ -10,11 +10,11 @@ namespace crepe {
class UIObject : public Component {
public:
/**
- * \brief Constructs a UiObject with the specified game object ID.
- * \param id The unique ID of the game object associated with this UI object.
+ * \brief Constructs a UiObject with the specified game object ID.
+ * \param id The unique ID of the game object associated with this UI object.
* \param dimensions width and height of the UIObject
* \param offset Offset relative to the GameObject Transform
- */
+ */
UIObject(game_object_id_t id, const vec2 & dimensions, const vec2 & offset);
//! Width and height of the UIObject
vec2 dimensions;