2009-10-01 01:10:58 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* libwiigui
|
|
|
|
*
|
|
|
|
* Tantric 2009
|
|
|
|
*
|
|
|
|
* gui_trigger.cpp
|
|
|
|
*
|
|
|
|
* GUI class definitions
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#include "gui.h"
|
|
|
|
|
|
|
|
static int scrollDelay = 0;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Constructor for the GuiTrigger class.
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
GuiTrigger::GuiTrigger()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
chan = -1;
|
|
|
|
memset(&wpad, 0, sizeof(WPADData));
|
|
|
|
memset(&pad, 0, sizeof(PADData));
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Destructor for the GuiTrigger class.
|
|
|
|
*/
|
2010-02-09 11:59:55 +01:00
|
|
|
GuiTrigger::~GuiTrigger()
|
|
|
|
{
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a simple trigger. Requires:
|
|
|
|
* - Element is selected
|
|
|
|
* - Trigger button is pressed
|
|
|
|
*/
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiTrigger::SetSimpleTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
type = TRIGGER_SIMPLE;
|
|
|
|
chan = ch;
|
|
|
|
wpad.btns_d = wiibtns;
|
|
|
|
pad.btns_d = gcbtns;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a held trigger. Requires:
|
|
|
|
* - Element is selected
|
|
|
|
* - Trigger button is pressed and held
|
|
|
|
*/
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiTrigger::SetHeldTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
type = TRIGGER_HELD;
|
|
|
|
chan = ch;
|
|
|
|
wpad.btns_h = wiibtns;
|
|
|
|
pad.btns_h = gcbtns;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets a button trigger. Requires:
|
|
|
|
* - Trigger button is pressed
|
|
|
|
*/
|
2010-09-24 02:48:03 +02:00
|
|
|
void GuiTrigger::SetButtonOnlyTrigger(s32 ch, u32 wiibtns, u16 gcbtns)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
type = TRIGGER_BUTTON_ONLY;
|
|
|
|
chan = ch;
|
|
|
|
wpad.btns_d = wiibtns;
|
|
|
|
pad.btns_d = gcbtns;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* WPAD_Stick
|
|
|
|
*
|
|
|
|
* Get X/Y value from Wii Joystick (classic, nunchuk) input
|
|
|
|
***************************************************************************/
|
|
|
|
|
2010-09-24 02:48:03 +02:00
|
|
|
s8 GuiTrigger::WPAD_Stick(u8 right, int axis)
|
2010-02-09 11:59:55 +01:00
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
float mag = 0.0;
|
|
|
|
float ang = 0.0;
|
|
|
|
|
|
|
|
switch ( wpad.exp.type )
|
|
|
|
{
|
2011-12-29 09:26:49 +01:00
|
|
|
default:
|
2011-07-26 00:28:22 +02:00
|
|
|
case WPAD_EXP_NUNCHUK:
|
|
|
|
case WPAD_EXP_GUITARHERO3:
|
|
|
|
{
|
2011-12-28 17:27:30 +01:00
|
|
|
if ( right == 0 )
|
|
|
|
{
|
|
|
|
mag = wpad.exp.nunchuk.js.mag;
|
|
|
|
ang = wpad.exp.nunchuk.js.ang;
|
|
|
|
}
|
|
|
|
break;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
case WPAD_EXP_CLASSIC:
|
|
|
|
{
|
2011-12-28 17:27:30 +01:00
|
|
|
if ( right == 0 )
|
|
|
|
{
|
|
|
|
mag = wpad.exp.classic.ljs.mag;
|
|
|
|
ang = wpad.exp.classic.ljs.ang;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
mag = wpad.exp.classic.rjs.mag;
|
|
|
|
ang = wpad.exp.classic.rjs.ang;
|
|
|
|
}
|
|
|
|
break;
|
2011-07-26 00:28:22 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calculate x/y value (angle need to be converted into radian) */
|
2011-12-28 17:27:30 +01:00
|
|
|
if ( mag > 1.0 )
|
|
|
|
mag = 1.0;
|
|
|
|
else if ( mag < -1.0 )
|
|
|
|
mag = -1.0;
|
|
|
|
|
|
|
|
float val;
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
if ( axis == 0 ) // x-axis
|
2011-12-28 17:27:30 +01:00
|
|
|
val = (float) (mag * sin( (PI * ang) / 180.0f ));
|
2011-07-26 00:28:22 +02:00
|
|
|
else // y-axis
|
2011-12-28 17:27:30 +01:00
|
|
|
val = (float) (mag * cos( (PI * ang) / 180.0f ));
|
2011-07-26 00:28:22 +02:00
|
|
|
|
|
|
|
return ( s8 )( val * 128.0f );
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
bool GuiTrigger::Left()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
u32 wiibtn = WPAD_BUTTON_LEFT;
|
|
|
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
|
|
|
wiibtn = WPAD_CLASSIC_BUTTON_LEFT;
|
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
if ( ((wpad.btns_d | wpad.btns_h) & wiibtn)
|
2011-12-29 09:26:49 +01:00
|
|
|
|| ((pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT))
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_LEFT))
|
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-28 17:27:30 +01:00
|
|
|
else if (--scrollDelay <= 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_LOOP_DELAY;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
bool GuiTrigger::Right()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
u32 wiibtn = WPAD_BUTTON_RIGHT;
|
|
|
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
|
|
|
wiibtn = WPAD_CLASSIC_BUTTON_RIGHT;
|
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
if ( ((wpad.btns_d | wpad.btns_h) & wiibtn)
|
2011-12-29 09:26:49 +01:00
|
|
|
|| ((pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT))
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_RIGHT))
|
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-28 17:27:30 +01:00
|
|
|
else if (--scrollDelay <= 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_LOOP_DELAY;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
bool GuiTrigger::Up()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
u32 wiibtn = WPAD_BUTTON_UP;
|
|
|
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
|
|
|
wiibtn = WPAD_CLASSIC_BUTTON_UP;
|
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
if ( ((wpad.btns_d | wpad.btns_h) & wiibtn)
|
2011-12-29 09:26:49 +01:00
|
|
|
|| ((pad.btns_d | pad.btns_h) & PAD_BUTTON_UP))
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_UP))
|
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-28 17:27:30 +01:00
|
|
|
else if (--scrollDelay <= 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_LOOP_DELAY;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|
|
|
|
|
2010-02-09 11:59:55 +01:00
|
|
|
bool GuiTrigger::Down()
|
|
|
|
{
|
2011-07-26 00:28:22 +02:00
|
|
|
u32 wiibtn = WPAD_BUTTON_DOWN;
|
|
|
|
if(wpad.exp.type == WPAD_EXP_CLASSIC)
|
|
|
|
wiibtn = WPAD_CLASSIC_BUTTON_DOWN;
|
|
|
|
|
2011-12-28 17:27:30 +01:00
|
|
|
if ( ((wpad.btns_d | wpad.btns_h) & wiibtn)
|
2011-12-29 09:26:49 +01:00
|
|
|
|| ((pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN))
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_DOWN))
|
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
|
|
|
|
return true;
|
|
|
|
}
|
2011-12-28 17:27:30 +01:00
|
|
|
else if (--scrollDelay <= 0)
|
2011-07-26 00:28:22 +02:00
|
|
|
{
|
|
|
|
scrollDelay = SCROLL_LOOP_DELAY;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
2009-10-01 01:10:58 +02:00
|
|
|
}
|