Skip to content

Commit 709c2ca

Browse files
Update keyboard.h
1 parent 93615f0 commit 709c2ca

File tree

1 file changed

+224
-32
lines changed

1 file changed

+224
-32
lines changed

code/logic/fossil/io/keyboard.h

Lines changed: 224 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -93,20 +93,54 @@ void fossil_io_keyboard_unregister_binding(fossil_io_keyboard_event_t event);
9393
*/
9494
void fossil_io_keyboard_poll_events(void);
9595

96-
// Functions for mouse handling
97-
void fossil_io_mouse_init(void); // Initialize the mouse event library
98-
void fossil_io_mouse_shutdown(void); // Shut down the mouse event library
96+
/** @brief Initialize the mouse event library. */
97+
void fossil_io_mouse_init(void);
98+
99+
/** @brief Shut down the mouse event library. */
100+
void fossil_io_mouse_shutdown(void);
101+
102+
/** @brief Clear all mouse event bindings. */
99103
void fossil_io_mouse_clear_bindings(void);
100-
void fossil_io_mouse_register_binding(fossil_io_mouse_event_t event, fossil_io_mouse_callback_t callback); // Register a mouse binding
101-
void fossil_io_mouse_unregister_binding(fossil_io_mouse_event_t event); // Unregister a mouse binding
104+
105+
/**
106+
* @brief Register a mouse event binding.
107+
* @param event The mouse event to bind.
108+
* @param callback The callback function to invoke when the event occurs.
109+
*/
110+
void fossil_io_mouse_register_binding(fossil_io_mouse_event_t event, fossil_io_mouse_callback_t callback);
111+
112+
/**
113+
* @brief Unregister a mouse event binding.
114+
* @param event The mouse event to unbind.
115+
*/
116+
void fossil_io_mouse_unregister_binding(fossil_io_mouse_event_t event);
117+
118+
/** @brief Poll and dispatch pending mouse events. */
102119
void fossil_io_mouse_poll_events(void);
103120

104-
// Functions for touch handling
105-
void fossil_io_touch_init(void); // Initialize the touch event library
106-
void fossil_io_touch_shutdown(void); // Shut down the touch event library
121+
/** @brief Initialize the touch event library. */
122+
void fossil_io_touch_init(void);
123+
124+
/** @brief Shut down the touch event library. */
125+
void fossil_io_touch_shutdown(void);
126+
127+
/** @brief Clear all touch event bindings. */
107128
void fossil_io_touch_clear_bindings(void);
108-
void fossil_io_touch_register_binding(fossil_io_touch_event_t event, fossil_io_touch_callback_t callback); // Register a touch binding
109-
void fossil_io_touch_unregister_binding(fossil_io_touch_event_t event); // Unregister a touch binding
129+
130+
/**
131+
* @brief Register a touch event binding.
132+
* @param event The touch event to bind.
133+
* @param callback The callback function to invoke when the event occurs.
134+
*/
135+
void fossil_io_touch_register_binding(fossil_io_touch_event_t event, fossil_io_touch_callback_t callback);
136+
137+
/**
138+
* @brief Unregister a touch event binding.
139+
* @param event The touch event to unbind.
140+
*/
141+
void fossil_io_touch_unregister_binding(fossil_io_touch_event_t event);
142+
143+
/** @brief Poll and dispatch pending touch events. */
110144
void fossil_io_touch_poll_events(void);
111145

112146
#ifdef __cplusplus
@@ -121,61 +155,219 @@ namespace fossil {
121155
* Namespace for I/O operations.
122156
*/
123157
namespace io {
158+
124159
/**
125-
* Class for interacting with the keyboard.
160+
* @brief Class for managing keyboard input.
161+
*
162+
* This class provides a high-level interface for handling keyboard input.
163+
* It wraps the underlying C API and manages initialization and cleanup automatically.
126164
*/
127-
class keyboard {
165+
class Keyboard {
128166
public:
129167
/**
130-
* Initialize the keyboard library.
131-
* Sets up any platform-specific configurations.
168+
* @brief Constructor that initializes the keyboard system.
169+
*
170+
* Call this to set up the keyboard event system.
171+
* Automatically prepares the library for receiving and processing keyboard events.
132172
*/
133-
static void init() {
173+
Keyboard() {
134174
fossil_io_keyboard_init();
135175
}
136176

137177
/**
138-
* Shut down the keyboard library.
139-
* Cleans up any platform-specific configurations.
178+
* @brief Destructor that shuts down the keyboard system.
179+
*
180+
* Automatically cleans up the keyboard event system on destruction.
181+
* This prevents memory leaks and releases any platform-specific resources.
140182
*/
141-
static void shutdown() {
183+
~Keyboard() {
142184
fossil_io_keyboard_shutdown();
143185
}
144186

145187
/**
146-
* Clear all keybindings from the library.
188+
* @brief Clear all registered keyboard bindings.
189+
*
190+
* Use this method to remove all current keyboard event bindings.
191+
* This is useful if you want to reset the input state or rebind controls dynamically.
147192
*/
148-
static void clear_bindings() {
193+
void clear_bindings() {
149194
fossil_io_keyboard_clear_bindings();
150195
}
151196

152197
/**
153-
* Register a keybinding with the library.
154-
*
155-
* @param event The keyboard event to bind to.
156-
* @param callback The callback function to call when the event occurs.
198+
* @brief Register a keyboard event binding.
199+
*
200+
* Binds a specific keyboard event to a callback function. When the event occurs,
201+
* the corresponding callback will be executed.
202+
*
203+
* @param event The keyboard event to listen for.
204+
* @param callback The function to call when the event is triggered.
157205
*/
158-
static void register_binding(fossil_io_keyboard_event_t event, fossil_io_keyboard_callback_t callback) {
206+
void register_binding(fossil_io_keyboard_event_t event, fossil_io_keyboard_callback_t callback) {
159207
fossil_io_keyboard_register_binding(event, callback);
160208
}
161209

162210
/**
163-
* Unregister a keybinding with the library.
164-
*
165-
* @param event The keyboard event to unbind.
211+
* @brief Unregister a specific keyboard event binding.
212+
*
213+
* Removes the callback associated with a particular keyboard event.
214+
*
215+
* @param event The event for which the callback should be removed.
166216
*/
167-
static void unregister_binding(fossil_io_keyboard_event_t event) {
217+
void unregister_binding(fossil_io_keyboard_event_t event) {
168218
fossil_io_keyboard_unregister_binding(event);
169219
}
170220

171221
/**
172-
* Poll for keyboard events and trigger any registered callbacks.
173-
* This function should be called in the main loop of the application.
222+
* @brief Poll for keyboard events and dispatch callbacks.
223+
*
224+
* Call this in your main loop to process pending keyboard events.
225+
* It will trigger any registered callbacks for events that have occurred.
174226
*/
175-
static void poll_events() {
227+
void poll_events() {
176228
fossil_io_keyboard_poll_events();
177229
}
178230
};
231+
232+
/**
233+
* @brief Class for managing mouse input.
234+
*
235+
* This class provides a modern C++ interface for handling mouse interactions.
236+
* It wraps the underlying mouse system and ensures proper initialization and cleanup.
237+
*/
238+
class Mouse {
239+
public:
240+
/**
241+
* @brief Constructor that initializes the mouse system.
242+
*
243+
* Prepares the internal state for processing mouse input.
244+
* Must be called before polling for events or registering bindings.
245+
*/
246+
Mouse() {
247+
fossil_io_mouse_init();
248+
}
249+
250+
/**
251+
* @brief Destructor that shuts down the mouse system.
252+
*
253+
* Cleans up resources associated with mouse input.
254+
* Should not be called manually if you're using stack allocation.
255+
*/
256+
~Mouse() {
257+
fossil_io_mouse_shutdown();
258+
}
259+
260+
/**
261+
* @brief Clear all mouse bindings.
262+
*
263+
* Removes all registered mouse event bindings.
264+
* Use this to reset or reconfigure the input system during runtime.
265+
*/
266+
void clear_bindings() {
267+
fossil_io_mouse_clear_bindings();
268+
}
269+
270+
/**
271+
* @brief Register a mouse event binding.
272+
*
273+
* Assigns a callback to a specific mouse event.
274+
*
275+
* @param event The mouse event (e.g., click, movement).
276+
* @param callback The function to invoke when the event occurs.
277+
*/
278+
void register_binding(fossil_io_mouse_event_t event, fossil_io_mouse_callback_t callback) {
279+
fossil_io_mouse_register_binding(event, callback);
280+
}
281+
282+
/**
283+
* @brief Unregister a mouse event binding.
284+
*
285+
* Detaches a callback from a previously bound mouse event.
286+
*
287+
* @param event The event to unbind.
288+
*/
289+
void unregister_binding(fossil_io_mouse_event_t event) {
290+
fossil_io_mouse_unregister_binding(event);
291+
}
292+
293+
/**
294+
* @brief Poll for mouse events and invoke callbacks.
295+
*
296+
* Should be called regularly (e.g., in your main loop) to process
297+
* incoming mouse events and dispatch them to registered handlers.
298+
*/
299+
void poll_events() {
300+
fossil_io_mouse_poll_events();
301+
}
302+
};
303+
304+
/**
305+
* @brief Class for managing touch input.
306+
*
307+
* Provides an abstraction layer for working with touchscreen input.
308+
* Ensures the input system is initialized and destroyed cleanly.
309+
*/
310+
class Touch {
311+
public:
312+
/**
313+
* @brief Constructor that initializes the touch system.
314+
*
315+
* Sets up the library to begin listening for touch interactions.
316+
*/
317+
Touch() {
318+
fossil_io_touch_init();
319+
}
320+
321+
/**
322+
* @brief Destructor that shuts down the touch system.
323+
*
324+
* Releases any resources used for handling touch input.
325+
*/
326+
~Touch() {
327+
fossil_io_touch_shutdown();
328+
}
329+
330+
/**
331+
* @brief Clear all touch bindings.
332+
*
333+
* Removes all existing event-to-callback mappings for touch input.
334+
*/
335+
void clear_bindings() {
336+
fossil_io_touch_clear_bindings();
337+
}
338+
339+
/**
340+
* @brief Register a touch event binding.
341+
*
342+
* Associates a callback with a specific touch event.
343+
*
344+
* @param event The type of touch event to respond to.
345+
* @param callback The function to invoke when the event occurs.
346+
*/
347+
void register_binding(fossil_io_touch_event_t event, fossil_io_touch_callback_t callback) {
348+
fossil_io_touch_register_binding(event, callback);
349+
}
350+
351+
/**
352+
* @brief Unregister a touch event binding.
353+
*
354+
* Removes the callback associated with the given touch event.
355+
*
356+
* @param event The event whose binding should be removed.
357+
*/
358+
void unregister_binding(fossil_io_touch_event_t event) {
359+
fossil_io_touch_unregister_binding(event);
360+
}
361+
362+
/**
363+
* @brief Poll for touch events and dispatch them to callbacks.
364+
*
365+
* Should be called frequently to handle active touch events.
366+
*/
367+
void poll_events() {
368+
fossil_io_touch_poll_events();
369+
}
370+
};
179371
}
180372
}
181373

0 commit comments

Comments
 (0)