libGumball 0.0.1
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))
32#define GUM_CONTROLLER(self) (GBL_CAST (GUM_Controller, self))
33#define GUM_CONTROLLER_CLASS(klass) (GBL_CLASS_CAST (GUM_Controller, klass))
34#define GUM_CONTROLLER_CLASSOF(self) (GBL_CLASSOF (GUM_Controller, self))
35//! @}
36
37#define GBL_SELF_TYPE GUM_Controller
38
39GBL_DECLS_BEGIN
40GBL_FORWARD_DECLARE_STRUCT(GUM_Controller);
41
42typedef enum {
43 GUM_CONTROLLER_BUTTON_PRESS,
44 GUM_CONTROLLER_BUTTON_RELEASE
45} GUM_CONTROLLER_BUTTON_STATE;
46
47typedef enum {
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,
63 * adding nothing new.
64*/
65GBL_CLASS_DERIVE_EMPTY(GUM_Controller, GUM_Widget)
66
67/*!
68 * \struct GUM_Controller
69 * \extends GUM_Widget
70 * \brief Controller element responsible for handling input used for UI interaction
71*/
72
73/*!
74 * \name Properties
75 * \brief Properties you can set/get at or after creation.
76 * \note You can also set/get properties from parent classes (see \ref GUM_Controller).
77 * @{
78*/
79//! \cond
80GBL_INSTANCE_DERIVE(GUM_Controller, GUM_Widget)
81//! \endcond
82 GUM_Button* pSelectedButton; // The currently selected button
83 uint8_t controllerId; //!< Which id is this controller associated with. Default value is 0
84 bool isKeyboard; //!< If the controller is a keyboard. Default value is false
85GBL_INSTANCE_END
86
87//! @}
88
89GBL_PROPERTIES(GUM_Controller,
90 (controllerId, GBL_GENERIC, (READ, WRITE), GBL_UINT8_TYPE),
91 (isKeyboard, GBL_GENERIC, (READ, WRITE), GBL_BOOL_TYPE)
92)
93
94
95GblType GUM_Controller_type(void);
96
97// Takes a list of Name/Value pairs
98#define GUM_Controller_create(...) GBL_NEW(GUM_Controller __VA_OPT__(,) __VA_ARGS__)
99
100/*!
101 * Takes in a GUM_Controller,
102 * a GUM_CONTROLLER_BUTTON_STATE, and a GUM_CONTROLLER_BUTTON_ID.
103 * Handles the event.
104*/
105GBL_EXPORT void GUM_Controller_sendButton (GBL_SELF, GUM_CONTROLLER_BUTTON_STATE state, GUM_CONTROLLER_BUTTON_ID button) GBL_NOEXCEPT;
106
107//! Takes in a GUM_Controller, and sets its selected button to the passed GUM_Button
108GBL_EXPORT void GUM_Controller_setSelectedButton (GBL_SELF, GUM_Button *pButton) GBL_NOEXCEPT;
109
110GBL_DECLS_END
111#undef GBL_SELF_TYPE
112
113#endif // GUM_CONTROLLER_H
uint8_t controllerId
Which id is this controller associated with.
Definition gumball_controller.h:83
bool isKeyboard
If the controller is a keyboard.
Definition gumball_controller.h:84