libGumball 0.0.2
C23-Based, libGimbal-powered UI Library
Loading...
Searching...
No Matches
gumball_controller.h
Go to the documentation of this file.
1#ifndef GUM_CONTROLLER_H
2#define GUM_CONTROLLER_H
3
4// View this file's documentation online: https://libgumball.psyops.studio/gumball__controller_8h.html
5
6/*! \file
7 * \ref GUM_Controller "GUM_Controller data structure and hierarchy graph"
8 * \ingroup elements
9 *
10 * GUM_Controller is responsible for handling input from gamepads and/or keyboards,
11 * and drawing a border around the currently selected button.
12 * Each controller is associated with a specific player id, allowing you to have multiple
13 * controllers at once.
14 *
15 * \todo
16 * - Handle multiple controllers on the same button
17 * - Make pSelectedButton a property
18 * - Make variables private
19 * - Deprecate GUM_Controller_setSelectedButton once GUM_Property is implemented
20 *
21 * \author 2025 Agustín Bellagamba
22 * \copyright MIT License
23*/
24
25#include "gumball_button.h"
26
27/*! \name Type System
28 * \brief Type UUID and cast operators
29 * @{
30 */
31#define GUM_CONTROLLER_TYPE (GBL_TYPEID (GUM_Controller)) //!< Returns the GUM_Controller Type UUID
32#define GUM_CONTROLLER(self) (GBL_CAST (GUM_Controller, self)) //!< Casts an instance of a compatible element to a GUM_Controller
33#define GUM_CONTROLLER_CLASS(klass) (GBL_CLASS_CAST (GUM_Controller, klass)) //!< Casts a class of a compatible element to a GUM_ControllerClass
34#define GUM_CONTROLLER_CLASSOF(self) (GBL_CLASSOF (GUM_Controller, self)) //!< Casts an instance of a compatible element to a GUM_ControllerClass
35//! @}
36
37#define GBL_SELF_TYPE GUM_Controller
38
39GBL_DECLS_BEGIN
40GBL_FORWARD_DECLARE_STRUCT(GUM_Controller);
41
42typedef enum : uint8_t {
43 GUM_CONTROLLER_BUTTON_PRESS,
44 GUM_CONTROLLER_BUTTON_RELEASE
45} GUM_CONTROLLER_BUTTON_STATE;
46
47typedef enum : uint8_t {
48 GUM_CONTROLLER_UP,
49 GUM_CONTROLLER_RIGHT,
50 GUM_CONTROLLER_DOWN,
51 GUM_CONTROLLER_LEFT,
52 GUM_CONTROLLER_PRIMARY,
53 GUM_CONTROLLER_SECONDARY,
54 GUM_CONTROLLER_TERTIARY
55} GUM_CONTROLLER_BUTTON_ID;
56
57/*!
58 * \struct GUM_ControllerClass
59 * \extends GUM_WidgetClass
60 * \brief GUM_Controller structure
61 *
62 * GUM_ControllerClass derives from GUM_WidgetClass, adding nothing new.
63*/
64GBL_CLASS_DERIVE_EMPTY(GUM_Controller, GUM_Widget)
65
66/*!
67 * \struct GUM_Controller
68 * \extends GUM_Widget
69 * \brief Controller element responsible for handling input used for UI interaction
70*/
71
72/*!
73 * \name Properties
74 * \brief Properties you can set/get at or after creation.
75 * \note You can also set/get properties from parent classes (see \ref GUM_Controller).
76 * @{
77*/
78//! \cond
79GBL_INSTANCE_DERIVE(GUM_Controller, GUM_Widget)
80//! \endcond
81 GUM_Button *pSelectedButton; // The currently selected button
82 uint8_t controllerId; //!< Which id is this controller associated with. Default value is 0
83 bool isKeyboard; //!< If the controller is a keyboard. Default value is false
84GBL_INSTANCE_END
85
86//! @}
87
88GBL_PROPERTIES(GUM_Controller,
89 (controllerId, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
90 (isKeyboard, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE)
91)
92
93
94GblType GUM_Controller_type(void);
95
96// Takes a list of Name/Value pairs
97#define GUM_Controller_create(...) GBL_NEW(GUM_Controller __VA_OPT__(,) __VA_ARGS__)
98
99/*!
100 * Takes in a GUM_Controller,
101 * a GUM_CONTROLLER_BUTTON_STATE, and a GUM_CONTROLLER_BUTTON_ID.
102 * Handles the event.
103*/
104GBL_EXPORT void GUM_Controller_sendButton (GBL_SELF, GUM_CONTROLLER_BUTTON_STATE state, GUM_CONTROLLER_BUTTON_ID button) GBL_NOEXCEPT;
105
106//! Takes in a GUM_Controller, and sets its selected button to the passed GUM_Button
107GBL_EXPORT void GUM_Controller_setSelectedButton (GBL_SELF, GUM_Button *pButton) GBL_NOEXCEPT;
108
109GBL_DECLS_END
110#undef GBL_SELF_TYPE
111
112#endif // GUM_CONTROLLER_H
uint8_t controllerId
Which id is this controller associated with.
Definition gumball_controller.h:82
bool isKeyboard
If the controller is a keyboard.
Definition gumball_controller.h:83