aboutsummaryrefslogtreecommitdiff
path: root/src/crepe/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/crepe/api')
-rw-r--r--src/crepe/api/Button.cpp3
-rw-r--r--src/crepe/api/Button.h12
-rw-r--r--src/crepe/api/Config.h5
-rw-r--r--src/crepe/api/Event.h96
-rw-r--r--src/crepe/api/KeyCodes.h11
5 files changed, 80 insertions, 47 deletions
diff --git a/src/crepe/api/Button.cpp b/src/crepe/api/Button.cpp
index 76f74f0..305922c 100644
--- a/src/crepe/api/Button.cpp
+++ b/src/crepe/api/Button.cpp
@@ -3,9 +3,8 @@
namespace crepe {
Button::Button(game_object_id_t id, const vec2 & dimensions, const vec2 & offset,
- const std::function<void()> & on_click, bool is_toggle)
+ const std::function<void()> & on_click)
: UIObject(id, dimensions, offset),
- is_toggle(is_toggle),
on_click(on_click) {}
} // namespace crepe
diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h
index 61b18d7..08f5dec 100644
--- a/src/crepe/api/Button.h
+++ b/src/crepe/api/Button.h
@@ -15,19 +15,11 @@ public:
* \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);
+ const std::function<void()> & on_click);
- /**
- * \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: create separate toggle button class
/**
* \brief The callback function to be executed when the button is clicked.
@@ -56,8 +48,6 @@ public:
private:
//! friend relation for is_pressed and hover variables
friend class InputSystem;
- //! Indicates whether the toggle button is pressed
- bool is_pressed = false;
//! Indicates whether the mouse is currently hovering over the button
bool hover = false;
diff --git a/src/crepe/api/Config.h b/src/crepe/api/Config.h
index ca2d3f1..ed1cf38 100644
--- a/src/crepe/api/Config.h
+++ b/src/crepe/api/Config.h
@@ -76,6 +76,11 @@ struct Config final {
*/
std::string root_pattern = ".crepe-root";
} asset;
+ //! Configuration for click tolerance.
+ struct {
+ //! The maximum number of pixels the mouse can move between MouseDown and MouseUp events to be considered a click.
+ int click_tolerance = 5;
+ } input;
//! Audio system settings
struct {
diff --git a/src/crepe/api/Event.h b/src/crepe/api/Event.h
index f2f3daf..66dd0cc 100644
--- a/src/crepe/api/Event.h
+++ b/src/crepe/api/Event.h
@@ -4,6 +4,7 @@
#include <string>
#include "KeyCodes.h"
+#include "types.h"
namespace crepe {
@@ -38,11 +39,8 @@ public:
*/
class MousePressEvent : public Event {
public:
- //! X-coordinate of the mouse position at the time of the event.
- int mouse_x = 0;
-
- //! Y-coordinate of the mouse position at the time of the event.
- int mouse_y = 0;
+ //! mouse position
+ ivec2 mouse_pos = {0, 0};
//! The mouse button that was pressed.
MouseButton button = MouseButton::NONE;
@@ -53,11 +51,8 @@ public:
*/
class MouseClickEvent : public Event {
public:
- //! X-coordinate of the mouse position at the time of the event.
- int mouse_x = 0;
-
- //! Y-coordinate of the mouse position at the time of the event.
- int mouse_y = 0;
+ //! mouse position
+ ivec2 mouse_pos = {0, 0};
//! The mouse button that was clicked.
MouseButton button = MouseButton::NONE;
@@ -68,11 +63,8 @@ public:
*/
class MouseReleaseEvent : public Event {
public:
- //! X-coordinate of the mouse position at the time of the event.
- int mouse_x = 0;
-
- //! Y-coordinate of the mouse position at the time of the event.
- int mouse_y = 0;
+ //! mouse position
+ ivec2 mouse_pos = {0, 0};
//! The mouse button that was released.
MouseButton button = MouseButton::NONE;
@@ -83,17 +75,10 @@ public:
*/
class MouseMoveEvent : public Event {
public:
- //! X-coordinate of the mouse position at the time of the event.
- int mouse_x = 0;
-
- //! Y-coordinate of the mouse position at the time of the event.
- int mouse_y = 0;
-
- // Movement since last event in x
- int delta_x = 0;
-
- // Movement since last event in y
- int delta_y = 0;
+ //! new mouse position
+ ivec2 mouse_pos = {0, 0};
+ //! The change in mouse position relative to the last position (in pixels).
+ ivec2 mouse_delta = {0, 0};
};
/**
@@ -101,12 +86,8 @@ public:
*/
class MouseScrollEvent : public Event {
public:
- //! X-coordinate of the mouse position at the time of the event.
- int mouse_x = 0;
-
- //! Y-coordinate of the mouse position at the time of the event.
- int mouse_y = 0;
-
+ //! mouse position when the scroll happened.
+ ivec2 mouse_pos = {0, 0};
//! scroll direction (-1 = down, 1 = up)
int scroll_direction = 0;
//! scroll amount in y axis (from and away from the person).
@@ -127,4 +108,55 @@ public:
*/
class ShutDownEvent : public Event {};
+/**
+ * \brief Event triggered to indicate the window is overlapped by another window.
+ *
+ * When two windows overlap the bottom window gets distorted and that window has to be redrawn.
+ */
+class WindowExposeEvent : public Event {};
+
+/**
+ * \brief Event triggered to indicate the window is resized.
+ */
+class WindowResizeEvent : public Event {
+public:
+ //! new window dimensions
+ ivec2 dimensions = {0, 0};
+};
+
+/**
+ * \brief Event triggered to indicate the window is moved.
+ */
+class WindowMoveEvent : public Event {
+public:
+ //! The change in position relative to the last position (in pixels).
+ ivec2 delta_move = {0, 0};
+};
+
+/**
+ * \brief Event triggered to indicate the window is minimized.
+ */
+class WindowMinimizeEvent : public Event {};
+
+/**
+ * \brief Event triggered to indicate the window is maximized
+ */
+class WindowMaximizeEvent : public Event {};
+
+/**
+ * \brief Event triggered to indicate the window gained focus
+ *
+ * This event is triggered when the window receives focus, meaning it becomes the active window
+ * for user interaction.
+ */
+class WindowFocusGainEvent : public Event {};
+
+/**
+ * \brief Event triggered to indicate the window lost focus
+ *
+ * This event is triggered when the window loses focus, meaning it is no longer the active window
+ * for user interaction.
+ */
+class WindowFocusLostEvent : public Event {};
+
} // namespace crepe
diff --git a/src/crepe/api/KeyCodes.h b/src/crepe/api/KeyCodes.h
index fcfc080..fa0d17c 100644
--- a/src/crepe/api/KeyCodes.h
+++ b/src/crepe/api/KeyCodes.h
@@ -1,4 +1,7 @@
#pragma once
+
+#include <unordered_map>
+
namespace crepe {
//! Enumeration for mouse button inputs, including standard and extended buttons.
enum class MouseButton {
@@ -13,7 +16,7 @@ enum class MouseButton {
};
//! Enumeration for keyboard key inputs, including printable characters, function keys, and keypad keys.
-enum class Keycode {
+typedef enum {
NONE = 0, //!< No key input.
SPACE = 32, //!< Spacebar.
APOSTROPHE = 39, //!< Apostrophe (').
@@ -150,5 +153,9 @@ enum class Keycode {
RIGHT_SUPER = 347,
/// \}
MENU = 348, //!< Menu key.
-};
+ //! Not actually a key instead its the amount of keycodes there are for array indexing
+ NUM_KEYCODES = 512,
+} Keycode;
+
+
} // namespace crepe