libgui 2.01
libgui is a GUI library for the GameCube, Wii, and Wii U
 
Loading...
Searching...
No Matches
GuiTrigger.cpp
1/****************************************************************************
2 * libgui
3 * Daryl Borth 2009-2026
4 * GuiTrigger.cpp
5 ***************************************************************************/
6
7#include "Gui.h"
8
9GuiTrigger::GuiTrigger() :
10 type(TRIGGER_TYPE::SIMPLE),
11 action(TRIGGER_ACTION::NONE),
12 chan(-1),
13 conditionMask(INPUT_BTN_NONE)
14{}
15
17 type = TRIGGER_TYPE::SIMPLE;
18 action = TRIGGER_ACTION::PRIMARY;
19 chan = ch;
20 conditionMask = INPUT_BTN_NONE; // Handled dynamically in resolveMask
21}
22
24 type = TRIGGER_TYPE::BUTTON_ONLY;
25 action = TRIGGER_ACTION::SECONDARY;
26 chan = ch;
27 conditionMask = INPUT_BTN_NONE; // Handled dynamically in resolveMask
28}
29
30void GuiTrigger::setSimpleTrigger(int ch, uint32_t buttonMask) {
31 type = TRIGGER_TYPE::SIMPLE;
32 action = TRIGGER_ACTION::NONE;
33 chan = ch;
34 conditionMask = buttonMask;
35}
36
37void GuiTrigger::setHeldTrigger(int ch, uint32_t buttonMask) {
38 type = TRIGGER_TYPE::HELD;
39 action = TRIGGER_ACTION::NONE;
40 chan = ch;
41 conditionMask = buttonMask;
42}
43
44void GuiTrigger::setButtonOnlyTrigger(int ch, uint32_t buttonMask) {
45 type = TRIGGER_TYPE::BUTTON_ONLY;
46 action = TRIGGER_ACTION::NONE;
47 chan = ch;
48 conditionMask = buttonMask;
49}
50
51void GuiTrigger::setButtonOnlyInFocusTrigger(int ch, uint32_t buttonMask) {
52 type = TRIGGER_TYPE::BUTTON_ONLY_IN_FOCUS;
53 action = TRIGGER_ACTION::NONE;
54 chan = ch;
55 conditionMask = buttonMask;
56}
57
58uint32_t GuiTrigger::resolveMask(const InputController* controller) const {
59 if (action == TRIGGER_ACTION::PRIMARY) {
60 return controller->isSideways() ? INPUT_BTN_2 : INPUT_BTN_A;
61 }
62 else if (action == TRIGGER_ACTION::SECONDARY) {
63 return controller->isSideways() ? INPUT_BTN_1 : INPUT_BTN_B;
64 }
65
66 return conditionMask; // Fallback to explicit mask for non-semantic triggers
67}
68
69// A sideways Wiimote swaps A/B for 2/1, but only the Wiimote is held that way
70static uint32_t UnrotatedHwMask(TRIGGER_ACTION action, const InputController* c)
71{
72 if (!c->isSideways())
73 return INPUT_BTN_NONE;
74 if (action == TRIGGER_ACTION::PRIMARY)
75 return INPUT_BTN_A;
76 if (action == TRIGGER_ACTION::SECONDARY)
77 return INPUT_BTN_B;
78 return INPUT_BTN_NONE;
79}
80
81bool GuiTrigger::isClicked(const InputController* controller) const {
82 if (!controller || (chan != -1 && controller->getChannel() != chan)) {
83 return false;
84 }
85 const InputPadData& d = controller->getPadData();
86 return ((d.buttons_d & resolveMask(controller)) |
87 (d.hw_buttons_d[INPUT_HW_DRC] & UnrotatedHwMask(action, controller))) != 0;
88}
89
90bool GuiTrigger::isHeld(const InputController* controller) const {
91 if (!controller || (chan != -1 && controller->getChannel() != chan)) {
92 return false;
93 }
94 const InputPadData& d = controller->getPadData();
95 return ((d.buttons_h & resolveMask(controller)) |
96 (d.hw_buttons_h[INPUT_HW_DRC] & UnrotatedHwMask(action, controller))) != 0;
97}
98
99bool GuiTrigger::isReleased(const InputController* controller) const {
100 if (!controller || (chan != -1 && controller->getChannel() != chan)) {
101 return false;
102 }
103 const InputPadData& d = controller->getPadData();
104 return ((d.buttons_r & resolveMask(controller)) |
105 (d.hw_buttons_r[INPUT_HW_DRC] & UnrotatedHwMask(action, controller))) != 0;
106}
Umbrella header for the platform-agnostic libgui core.
void setSimpleTrigger(int ch, uint32_t buttonMask)
Sets a simple trigger.
bool isReleased(const InputController *controller) const
void setButtonOnlyInFocusTrigger(int ch, uint32_t buttonMask)
Sets a button-only trigger.
bool isClicked(const InputController *controller) const
bool isHeld(const InputController *controller) const
void setPrimaryTrigger(int ch=-1)
Semantic Triggers.
void setHeldTrigger(int ch, uint32_t buttonMask)
Sets a held trigger.
void setButtonOnlyTrigger(int ch, uint32_t buttonMask)
Sets a button-only trigger.
void setSecondaryTrigger(int ch=-1)
Logical controller for one input channel.
bool isSideways() const
TRIGGER_TYPE
How a GuiTrigger matches input: simple, held, button-only, or button-only-in-focus.
Definition GuiTrigger.h:15
TRIGGER_ACTION
Whether a GuiTrigger uses an explicit button mask or a semantic primary (Accept) / secondary (Cancel)...
Definition GuiTrigger.h:24
The universal input payload for UI elements.
Definition InputData.h:57
uint32_t buttons_d
Pressed this frame (down)
Definition InputData.h:61
uint32_t hw_buttons_d[INPUT_HW_MAX]
Buttons pressed this frame, per profile.
Definition InputData.h:86
uint32_t hw_buttons_h[INPUT_HW_MAX]
Buttons held this frame, per profile.
Definition InputData.h:87
uint32_t buttons_r
Released this frame.
Definition InputData.h:63
uint32_t buttons_h
Held this frame.
Definition InputData.h:62
uint32_t hw_buttons_r[INPUT_HW_MAX]
Buttons released this frame, per profile.
Definition InputData.h:88