libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
InputController.h
1/****************************************************************************
2 * Platform Abstraction Layer
3 * Daryl Borth 2026
4 * InputController.h
5 *
6 * Represents a single connected logical controller.
7 * Handles device-specific translation (like sideways Wiimote mapping)
8 * and repeat-delay logic for UI navigation.
9 ***************************************************************************/
10#pragma once
11
12#include "InputData.h"
13
17public:
19 InputController(int channel);
20 ~InputController() = default;
21
27 void update(const InputPadData& data, float deltaTime);
28
30 void setSideways(bool s) { sideways = s; }
32 bool isSideways() const { return sideways; }
34 int getChannel() const { return channel; }
35
42 void setChannel(int c) { channel = c; }
43
45 void setContinuousRumble(bool continuous);
46
48 const InputPadData& getPadData() const { return currentData; }
49
51 bool isPressed(uint32_t logicalButtonMask) const;
53 bool isHeld(uint32_t logicalButtonMask) const;
55 bool isPrimaryPressed() const;
57 bool isSecondaryPressed() const;
58
59 // Navigation helpers: each returns true on the initial press and then
60 // repeats while the d-pad or stick is held, using the scroll delays below.
61 // They account for sideways orientation.
62
64 bool up() const;
66 bool down() const;
68 bool left() const;
70 bool right() const;
71
72private:
73 int channel;
74 bool sideways;
75 InputPadData currentData;
76
77 // Analog stick deadzone
78 const float STICK_DEADZONE = 0.2f;
79
80 // Scrolling delay timers (in seconds)
81 const float SCROLL_DELAY_INITIAL = 0.3f;
82 const float SCROLL_DELAY_LOOP = 0.05f;
83
84 float scrollTimer;
85
86 // Internal helper to process directional holds and repeats
87 bool processDirection(uint32_t logicalButtonMask, float stickAxis, bool isNegativeAxis) const;
88
89 // Mutable state to allow the const navigation functions to reset the timer
90 // when a valid scroll triggers. (A common pattern to keep accessors clean).
91 mutable float internalScrollTimer;
92};
93
94extern InputController* controller[4];
95
96void InitUserInputControllers();
Logical controller for one input channel.
void setContinuousRumble(bool continuous)
Holds this controller's motor on or off (see InputDriver::setContinuousRumble()).
bool isPressed(uint32_t logicalButtonMask) const
int getChannel() const
bool isSecondaryPressed() const
void setChannel(int c)
Temporarily overrides the channel this controller reports via getChannel().
void update(const InputPadData &data, float deltaTime)
Updates the controller state.
bool isHeld(uint32_t logicalButtonMask) const
bool isPrimaryPressed() const
const InputPadData & getPadData() const
void setSideways(bool s)
Sets whether the Wiimote is held sideways; if so the d-pad and primary/secondary buttons are remapped...
InputController(int channel)
bool isSideways() const
The universal input payload for UI elements.
Definition InputData.h:57