2009-03-04 08:01:04 +01:00
|
|
|
/****************************************************************************
|
2009-04-10 09:51:55 +02:00
|
|
|
* libwiigui
|
2009-03-04 08:01:04 +01:00
|
|
|
*
|
2009-04-10 09:51:55 +02:00
|
|
|
* Tantric 2009
|
2009-03-04 08:01:04 +01:00
|
|
|
*
|
|
|
|
* gui_trigger.cpp
|
|
|
|
*
|
|
|
|
* GUI class definitions
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gui.h"
|
2009-11-04 22:27:16 +01:00
|
|
|
#include <ogc/lwp_watchdog.h>
|
|
|
|
#include <gctypes.h>
|
2009-03-04 08:01:04 +01:00
|
|
|
|
2009-11-04 22:27:16 +01:00
|
|
|
static u64 prev[4];
|
|
|
|
static u64 now[4];
|
|
|
|
static u32 delay[4];
|
2009-03-04 08:01:04 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the GuiTrigger class.
|
|
|
|
*/
|
|
|
|
GuiTrigger::GuiTrigger()
|
|
|
|
{
|
|
|
|
chan = -1;
|
2018-09-06 04:00:21 +02:00
|
|
|
memset(&wiidrcdata, 0, sizeof(GamePadData));
|
2009-10-13 02:49:08 +02:00
|
|
|
memset(&wpaddata, 0, sizeof(WPADData));
|
2009-03-04 08:01:04 +01:00
|
|
|
memset(&pad, 0, sizeof(PADData));
|
2009-10-13 02:49:08 +02:00
|
|
|
wpad = &wpaddata;
|
2009-03-04 08:01:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the GuiTrigger class.
|
|
|
|
*/
|
|
|
|
GuiTrigger::~GuiTrigger()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a simple trigger. Requires:
|
|
|
|
* - Element is selected
|
|
|
|
* - Trigger button is pressed
|
|
|
|
*/
|
2018-09-06 04:00:21 +02:00
|
|
|
void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
|
|
|
type = TRIGGER_SIMPLE;
|
|
|
|
chan = ch;
|
2018-09-06 04:00:21 +02:00
|
|
|
wiidrcdata.btns_d = wiidrcbtns;
|
2009-10-13 02:49:08 +02:00
|
|
|
wpaddata.btns_d = wiibtns;
|
2009-03-04 08:01:04 +01:00
|
|
|
pad.btns_d = gcbtns;
|
|
|
|
}
|
|
|
|
|
2009-04-10 09:51:55 +02:00
|
|
|
/**
|
|
|
|
* Sets a held trigger. Requires:
|
|
|
|
* - Element is selected
|
|
|
|
* - Trigger button is pressed and held
|
|
|
|
*/
|
2018-09-06 04:00:21 +02:00
|
|
|
void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns)
|
2009-04-10 09:51:55 +02:00
|
|
|
{
|
|
|
|
type = TRIGGER_HELD;
|
|
|
|
chan = ch;
|
2018-09-06 04:00:21 +02:00
|
|
|
wiidrcdata.btns_h = wiidrcbtns;
|
2009-10-13 02:49:08 +02:00
|
|
|
wpaddata.btns_h = wiibtns;
|
2009-04-10 09:51:55 +02:00
|
|
|
pad.btns_h = gcbtns;
|
|
|
|
}
|
|
|
|
|
2009-03-04 08:01:04 +01:00
|
|
|
/**
|
|
|
|
* Sets a button trigger. Requires:
|
|
|
|
* - Trigger button is pressed
|
|
|
|
*/
|
2018-09-06 04:00:21 +02:00
|
|
|
void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
|
|
|
type = TRIGGER_BUTTON_ONLY;
|
|
|
|
chan = ch;
|
2018-09-06 04:00:21 +02:00
|
|
|
wiidrcdata.btns_d = wiidrcbtns;
|
2009-10-13 02:49:08 +02:00
|
|
|
wpaddata.btns_d = wiibtns;
|
2009-03-04 08:01:04 +01:00
|
|
|
pad.btns_d = gcbtns;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a button trigger. Requires:
|
|
|
|
* - Trigger button is pressed
|
|
|
|
* - Parent window is in focus
|
|
|
|
*/
|
2018-09-06 04:00:21 +02:00
|
|
|
void GuiTrigger::SetButtonOnlyInFocusTrigger(s32 ch, u32 wiibtns, u16 gcbtns, u16 wiidrcbtns)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
|
|
|
type = TRIGGER_BUTTON_ONLY_IN_FOCUS;
|
|
|
|
chan = ch;
|
2018-09-06 04:00:21 +02:00
|
|
|
wiidrcdata.btns_d = wiidrcbtns;
|
2009-10-13 02:49:08 +02:00
|
|
|
wpaddata.btns_d = wiibtns;
|
2009-03-04 08:01:04 +01:00
|
|
|
pad.btns_d = gcbtns;
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* WPAD_Stick
|
|
|
|
*
|
|
|
|
* Get X/Y value from Wii Joystick (classic, nunchuk) input
|
|
|
|
***************************************************************************/
|
|
|
|
|
2009-10-15 09:43:25 +02:00
|
|
|
s8 GuiTrigger::WPAD_Stick(u8 stick, int axis)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2009-04-07 04:57:49 +02:00
|
|
|
#ifdef HW_RVL
|
2018-08-16 22:00:36 +02:00
|
|
|
struct joystick_t* js = NULL;
|
2009-04-07 04:57:49 +02:00
|
|
|
|
2018-08-16 22:00:36 +02:00
|
|
|
switch (wpad->exp.type) {
|
2009-03-04 08:01:04 +01:00
|
|
|
case WPAD_EXP_NUNCHUK:
|
2018-08-16 22:00:36 +02:00
|
|
|
js = stick ? NULL : &wpad->exp.nunchuk.js;
|
2009-03-04 08:01:04 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
case WPAD_EXP_CLASSIC:
|
2018-08-16 22:00:36 +02:00
|
|
|
js = stick ? &wpad->exp.classic.rjs : &wpad->exp.classic.ljs;
|
2009-03-04 08:01:04 +01:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2018-08-16 22:00:36 +02:00
|
|
|
if (js) {
|
|
|
|
int pos;
|
|
|
|
int min;
|
|
|
|
int max;
|
|
|
|
int center;
|
|
|
|
|
|
|
|
if(axis == 1) {
|
|
|
|
pos = js->pos.y;
|
|
|
|
min = js->min.y;
|
|
|
|
max = js->max.y;
|
|
|
|
center = js->center.y;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
pos = js->pos.x;
|
|
|
|
min = js->min.x;
|
|
|
|
max = js->max.x;
|
|
|
|
center = js->center.x;
|
|
|
|
}
|
|
|
|
|
2019-01-01 22:34:12 +01:00
|
|
|
if(min == max) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2018-08-16 22:00:36 +02:00
|
|
|
if (pos > max) return 127;
|
|
|
|
if (pos < min) return -128;
|
|
|
|
|
|
|
|
pos -= center;
|
|
|
|
|
|
|
|
if (pos > 0) {
|
|
|
|
return (s8)(127.0 * ((float)pos / (float)(max - center)));
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return (s8)(128.0 * ((float)pos / (float)(center - min)));
|
|
|
|
}
|
|
|
|
}
|
2009-04-07 04:57:49 +02:00
|
|
|
#endif
|
2018-08-16 22:00:36 +02:00
|
|
|
return 0;
|
2009-03-04 08:01:04 +01:00
|
|
|
}
|
|
|
|
|
2009-10-15 09:43:25 +02:00
|
|
|
s8 GuiTrigger::WPAD_StickX(u8 stick)
|
|
|
|
{
|
|
|
|
return WPAD_Stick(stick, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
s8 GuiTrigger::WPAD_StickY(u8 stick)
|
|
|
|
{
|
|
|
|
return WPAD_Stick(stick, 1);
|
|
|
|
}
|
|
|
|
|
2009-03-04 08:01:04 +01:00
|
|
|
bool GuiTrigger::Left()
|
|
|
|
{
|
|
|
|
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_UP : WPAD_BUTTON_LEFT;
|
|
|
|
|
2009-10-13 02:49:08 +02:00
|
|
|
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_LEFT
|
2009-04-07 04:57:49 +02:00
|
|
|
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT
|
2009-03-04 08:01:04 +01:00
|
|
|
|| pad.stickX < -PADCAL
|
2018-09-06 04:00:21 +02:00
|
|
|
|| WPAD_StickX(0) < -PADCAL
|
|
|
|
|| wiidrcdata.stickX < -WIIDRCCAL)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2018-08-01 20:41:41 +02:00
|
|
|
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_LEFT)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| wiidrcdata.btns_d & WIIDRC_BUTTON_LEFT
|
2018-08-01 20:41:41 +02:00
|
|
|
|| pad.btns_d & PAD_BUTTON_LEFT)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = gettime();
|
2009-11-04 22:31:58 +01:00
|
|
|
delay[chan] = SCROLL_DELAY_INITIAL; // reset scroll delay
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-11-04 22:27:16 +01:00
|
|
|
|
|
|
|
now[chan] = gettime();
|
|
|
|
|
|
|
|
if(diff_usec(prev[chan], now[chan]) > delay[chan])
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = now[chan];
|
|
|
|
|
2009-11-04 22:31:58 +01:00
|
|
|
if(delay[chan] == SCROLL_DELAY_INITIAL)
|
2009-11-04 22:27:16 +01:00
|
|
|
delay[chan] = SCROLL_DELAY_LOOP;
|
|
|
|
else if(delay[chan] > SCROLL_DELAY_DECREASE)
|
|
|
|
delay[chan] -= SCROLL_DELAY_DECREASE;
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiTrigger::Right()
|
|
|
|
{
|
|
|
|
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_DOWN : WPAD_BUTTON_RIGHT;
|
|
|
|
|
2009-10-13 02:49:08 +02:00
|
|
|
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_RIGHT
|
2009-04-07 04:57:49 +02:00
|
|
|
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT
|
2009-03-04 08:01:04 +01:00
|
|
|
|| pad.stickX > PADCAL
|
2018-09-06 04:00:21 +02:00
|
|
|
|| WPAD_StickX(0) > PADCAL
|
|
|
|
|| wiidrcdata.stickX > WIIDRCCAL)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2018-08-01 20:41:41 +02:00
|
|
|
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_RIGHT)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| wiidrcdata.btns_d & WIIDRC_BUTTON_RIGHT
|
2009-03-04 08:01:04 +01:00
|
|
|
|| pad.btns_d & PAD_BUTTON_RIGHT)
|
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = gettime();
|
2009-11-04 22:31:58 +01:00
|
|
|
delay[chan] = SCROLL_DELAY_INITIAL; // reset scroll delay
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-11-04 22:27:16 +01:00
|
|
|
|
|
|
|
now[chan] = gettime();
|
|
|
|
|
|
|
|
if(diff_usec(prev[chan], now[chan]) > delay[chan])
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = now[chan];
|
|
|
|
|
2009-11-04 22:31:58 +01:00
|
|
|
if(delay[chan] == SCROLL_DELAY_INITIAL)
|
2009-11-04 22:27:16 +01:00
|
|
|
delay[chan] = SCROLL_DELAY_LOOP;
|
|
|
|
else if(delay[chan] > SCROLL_DELAY_DECREASE)
|
|
|
|
delay[chan] -= SCROLL_DELAY_DECREASE;
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiTrigger::Up()
|
|
|
|
{
|
|
|
|
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_RIGHT : WPAD_BUTTON_UP;
|
|
|
|
|
2018-08-01 20:41:41 +02:00
|
|
|
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_UP
|
2009-04-07 04:57:49 +02:00
|
|
|
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_UP
|
2009-03-04 08:01:04 +01:00
|
|
|
|| pad.stickY > PADCAL
|
2018-09-06 04:00:21 +02:00
|
|
|
|| WPAD_StickY(0) > PADCAL
|
|
|
|
|| wiidrcdata.stickY > WIIDRCCAL)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2018-08-01 20:41:41 +02:00
|
|
|
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_UP)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| wiidrcdata.btns_d & WIIDRC_BUTTON_UP
|
2009-03-04 08:01:04 +01:00
|
|
|
|| pad.btns_d & PAD_BUTTON_UP)
|
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = gettime();
|
2009-11-04 22:31:58 +01:00
|
|
|
delay[chan] = SCROLL_DELAY_INITIAL; // reset scroll delay
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-11-04 22:27:16 +01:00
|
|
|
|
|
|
|
now[chan] = gettime();
|
|
|
|
|
|
|
|
if(diff_usec(prev[chan], now[chan]) > delay[chan])
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = now[chan];
|
|
|
|
|
|
|
|
if(delay[chan] == SCROLL_DELAY_INITIAL)
|
|
|
|
delay[chan] = SCROLL_DELAY_LOOP;
|
|
|
|
else if(delay[chan] > SCROLL_DELAY_DECREASE)
|
|
|
|
delay[chan] -= SCROLL_DELAY_DECREASE;
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiTrigger::Down()
|
|
|
|
{
|
|
|
|
u32 wiibtn = GCSettings.WiimoteOrientation ? WPAD_BUTTON_LEFT : WPAD_BUTTON_DOWN;
|
|
|
|
|
2018-08-01 20:41:41 +02:00
|
|
|
if((wpad->btns_d | wpad->btns_h) & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| (wiidrcdata.btns_d | wiidrcdata.btns_h) & WIIDRC_BUTTON_DOWN
|
2009-03-04 08:01:04 +01:00
|
|
|
|| (pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN
|
|
|
|
|| pad.stickY < -PADCAL
|
2018-09-06 04:00:21 +02:00
|
|
|
|| WPAD_StickY(0) < -PADCAL
|
|
|
|
|| wiidrcdata.stickY < -WIIDRCCAL)
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2018-08-01 20:41:41 +02:00
|
|
|
if(wpad->btns_d & (wiibtn | WPAD_CLASSIC_BUTTON_DOWN)
|
2018-09-06 04:00:21 +02:00
|
|
|
|| wiidrcdata.btns_d & WIIDRC_BUTTON_DOWN
|
2009-03-04 08:01:04 +01:00
|
|
|
|| pad.btns_d & PAD_BUTTON_DOWN)
|
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = gettime();
|
2009-11-04 22:31:58 +01:00
|
|
|
delay[chan] = SCROLL_DELAY_INITIAL; // reset scroll delay
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
2009-11-04 22:27:16 +01:00
|
|
|
|
|
|
|
now[chan] = gettime();
|
|
|
|
|
|
|
|
if(diff_usec(prev[chan], now[chan]) > delay[chan])
|
2009-03-04 08:01:04 +01:00
|
|
|
{
|
2009-11-04 22:27:16 +01:00
|
|
|
prev[chan] = now[chan];
|
|
|
|
|
2009-11-04 22:31:58 +01:00
|
|
|
if(delay[chan] == SCROLL_DELAY_INITIAL)
|
2009-11-04 22:27:16 +01:00
|
|
|
delay[chan] = SCROLL_DELAY_LOOP;
|
|
|
|
else if(delay[chan] > SCROLL_DELAY_DECREASE)
|
|
|
|
delay[chan] -= SCROLL_DELAY_DECREASE;
|
2009-03-04 08:01:04 +01:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|