usbloadergx/source/GUI/gui_trigger.cpp

224 lines
4.7 KiB
C++
Raw Normal View History

/****************************************************************************
* libwiigui
*
* Tantric 2009
*
* gui_trigger.cpp
*
* GUI class definitions
***************************************************************************/
#include "gui.h"
static int scrollDelay = 0;
/**
* Constructor for the GuiTrigger class.
*/
GuiTrigger::GuiTrigger()
{
chan = -1;
memset(&wpad, 0, sizeof(WPADData));
memset(&pad, 0, sizeof(PADData));
}
/**
* Destructor for the GuiTrigger class.
*/
GuiTrigger::~GuiTrigger()
{
}
/**
* 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)
{
type = TRIGGER_SIMPLE;
chan = ch;
wpad.btns_d = wiibtns;
pad.btns_d = gcbtns;
}
/**
* 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)
{
type = TRIGGER_HELD;
chan = ch;
wpad.btns_h = wiibtns;
pad.btns_h = gcbtns;
}
/**
* 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)
{
type = TRIGGER_BUTTON_ONLY;
chan = ch;
wpad.btns_d = wiibtns;
pad.btns_d = gcbtns;
}
/****************************************************************************
* 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)
{
2021-08-01 19:00:13 +02:00
struct joystick_t *js = NULL;
2021-08-01 19:00:13 +02:00
switch (wpad.exp.type)
{
2021-08-01 19:00:13 +02:00
case WPAD_EXP_NUNCHUK:
js = right ? NULL : &wpad.exp.nunchuk.js;
break;
case WPAD_EXP_GUITARHERO3:
js = right ? NULL : &wpad.exp.nunchuk.js;
break;
case WPAD_EXP_CLASSIC:
js = right ? &wpad.exp.classic.rjs : &wpad.exp.classic.ljs;
break;
default:
break;
}
if (js)
{
int pos = axis ? js->pos.y : js->pos.x;
int min = axis ? js->min.y : js->min.x;
int max = axis ? js->max.y : js->max.x;
int center = axis ? js->center.y : js->center.x;
// Fix bad calibration values (libogc 2.2.0 also fixes this)
if ((min >= center) || (max <= center))
{
2021-08-01 19:00:13 +02:00
if (axis)
{
2021-08-01 19:00:13 +02:00
min = js->min.y = 0;
max = js->max.y = right ? 32 : 64;
center = js->center.y = right ? 16 : 32;
}
else
{
2021-08-01 19:00:13 +02:00
min = js->min.x = 0;
max = js->max.x = right ? 32 : 64;
center = js->center.x = right ? 16 : 32;
}
}
2021-08-01 19:00:13 +02:00
// Limit values
if (pos > max)
return 127;
if (pos < min)
return -128;
2021-08-01 19:00:13 +02:00
// Adjust against center position
pos -= center;
2021-08-01 19:00:13 +02:00
// Return interpolated range
if (pos > 0)
return (s8)(127.0 * ((float)pos / (float)(max - center)));
else
return (s8)(128.0 * ((float)pos / (float)(center - min)));
}
2021-08-01 19:00:13 +02:00
return 0;
}
bool GuiTrigger::Left()
{
u32 wiibtn = WPAD_BUTTON_LEFT;
2021-08-01 19:00:13 +02:00
if (wpad.exp.type == WPAD_EXP_CLASSIC)
* Fixed missing games in "GameCube Delete menu" if the "GameCube Source" setting has USB priority. * Fixed Playlog writing when using Hermes cIOS v4 (untested) (Requires AHB access). * Fixed EmuNAND when using cIOS revision 65535 (issue 2225) * Added Nintendont support: 1. Select Nintendont's boot.dol folder in userpath settings. 2. Set the "GameCube Mode" setting to Nintendont. 3. Nintendont share some of DIOS MIOS (Lite) settings. * Added sections in the Loader settings (Wii/gamecube/Devolution/DIOS MIOS/Nintendont). * Updated the GameCube game settings to display only the selected GameCube mode related settings. * Updated some menus to support more controller's input: - Prevent GC/CC X and Y buttons to change row number in Wall layout (use d-pad up/down only) - Added GC/CC support to carousel's arrow button - Added GC/CC support to Wall/Carousel continuous scroll (+/- on CC, L/R on GC) - Added GC support L/R and Start buttons in the settings/homebrew browser. - Added D-pad support in listing windows if not pointing the screen. The cursor now moves with the selection (not very good with high Overscan value) (issue 2093) * Changed the StartupProcess to speed up launch time by using AHB access to read config files. IOS argument in meta.xml has priority over AHB detection. * Added IOS58 + AHB support for launching the loader without cIOS (Wii games and EmuNAND still require cIOS). * Added a Loader's IOS setting (now Loader and Games use two separate settings: loader can use 58 and games 249). * Added LibruntimeIOSPatch to patch IOS58 and Hermes v4 to get ISFS access and enable Banner mode, Channel's title and System font with these IOSes (Requires AHB access) * Added a delete prompt if downloaded cheat file is empty. * Force all launched homebrew to reload to IOS58 if available. * Changed Gecko.c to send logs to wifigecko too. * Changed wifigecko IP to send logs to all IP 192.168.0.x * Updated French translation.
2013-10-01 23:13:08 +02:00
wiibtn |= WPAD_CLASSIC_BUTTON_LEFT;
2021-08-01 19:00:13 +02:00
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h) & PAD_BUTTON_LEFT))
{
2021-08-01 19:00:13 +02:00
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_LEFT))
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
return true;
}
else if (--scrollDelay <= 0)
{
scrollDelay = SCROLL_LOOP_DELAY;
return true;
}
}
return false;
}
bool GuiTrigger::Right()
{
u32 wiibtn = WPAD_BUTTON_RIGHT;
2021-08-01 19:00:13 +02:00
if (wpad.exp.type == WPAD_EXP_CLASSIC)
* Fixed missing games in "GameCube Delete menu" if the "GameCube Source" setting has USB priority. * Fixed Playlog writing when using Hermes cIOS v4 (untested) (Requires AHB access). * Fixed EmuNAND when using cIOS revision 65535 (issue 2225) * Added Nintendont support: 1. Select Nintendont's boot.dol folder in userpath settings. 2. Set the "GameCube Mode" setting to Nintendont. 3. Nintendont share some of DIOS MIOS (Lite) settings. * Added sections in the Loader settings (Wii/gamecube/Devolution/DIOS MIOS/Nintendont). * Updated the GameCube game settings to display only the selected GameCube mode related settings. * Updated some menus to support more controller's input: - Prevent GC/CC X and Y buttons to change row number in Wall layout (use d-pad up/down only) - Added GC/CC support to carousel's arrow button - Added GC/CC support to Wall/Carousel continuous scroll (+/- on CC, L/R on GC) - Added GC support L/R and Start buttons in the settings/homebrew browser. - Added D-pad support in listing windows if not pointing the screen. The cursor now moves with the selection (not very good with high Overscan value) (issue 2093) * Changed the StartupProcess to speed up launch time by using AHB access to read config files. IOS argument in meta.xml has priority over AHB detection. * Added IOS58 + AHB support for launching the loader without cIOS (Wii games and EmuNAND still require cIOS). * Added a Loader's IOS setting (now Loader and Games use two separate settings: loader can use 58 and games 249). * Added LibruntimeIOSPatch to patch IOS58 and Hermes v4 to get ISFS access and enable Banner mode, Channel's title and System font with these IOSes (Requires AHB access) * Added a delete prompt if downloaded cheat file is empty. * Force all launched homebrew to reload to IOS58 if available. * Changed Gecko.c to send logs to wifigecko too. * Changed wifigecko IP to send logs to all IP 192.168.0.x * Updated French translation.
2013-10-01 23:13:08 +02:00
wiibtn |= WPAD_CLASSIC_BUTTON_RIGHT;
2021-08-01 19:00:13 +02:00
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h) & PAD_BUTTON_RIGHT))
{
2021-08-01 19:00:13 +02:00
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_RIGHT))
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
return true;
}
else if (--scrollDelay <= 0)
{
scrollDelay = SCROLL_LOOP_DELAY;
return true;
}
}
return false;
}
bool GuiTrigger::Up()
{
u32 wiibtn = WPAD_BUTTON_UP;
2021-08-01 19:00:13 +02:00
if (wpad.exp.type == WPAD_EXP_CLASSIC)
* Fixed missing games in "GameCube Delete menu" if the "GameCube Source" setting has USB priority. * Fixed Playlog writing when using Hermes cIOS v4 (untested) (Requires AHB access). * Fixed EmuNAND when using cIOS revision 65535 (issue 2225) * Added Nintendont support: 1. Select Nintendont's boot.dol folder in userpath settings. 2. Set the "GameCube Mode" setting to Nintendont. 3. Nintendont share some of DIOS MIOS (Lite) settings. * Added sections in the Loader settings (Wii/gamecube/Devolution/DIOS MIOS/Nintendont). * Updated the GameCube game settings to display only the selected GameCube mode related settings. * Updated some menus to support more controller's input: - Prevent GC/CC X and Y buttons to change row number in Wall layout (use d-pad up/down only) - Added GC/CC support to carousel's arrow button - Added GC/CC support to Wall/Carousel continuous scroll (+/- on CC, L/R on GC) - Added GC support L/R and Start buttons in the settings/homebrew browser. - Added D-pad support in listing windows if not pointing the screen. The cursor now moves with the selection (not very good with high Overscan value) (issue 2093) * Changed the StartupProcess to speed up launch time by using AHB access to read config files. IOS argument in meta.xml has priority over AHB detection. * Added IOS58 + AHB support for launching the loader without cIOS (Wii games and EmuNAND still require cIOS). * Added a Loader's IOS setting (now Loader and Games use two separate settings: loader can use 58 and games 249). * Added LibruntimeIOSPatch to patch IOS58 and Hermes v4 to get ISFS access and enable Banner mode, Channel's title and System font with these IOSes (Requires AHB access) * Added a delete prompt if downloaded cheat file is empty. * Force all launched homebrew to reload to IOS58 if available. * Changed Gecko.c to send logs to wifigecko too. * Changed wifigecko IP to send logs to all IP 192.168.0.x * Updated French translation.
2013-10-01 23:13:08 +02:00
wiibtn |= WPAD_CLASSIC_BUTTON_UP;
2021-08-01 19:00:13 +02:00
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h) & PAD_BUTTON_UP))
{
2021-08-01 19:00:13 +02:00
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_UP))
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
return true;
}
else if (--scrollDelay <= 0)
{
scrollDelay = SCROLL_LOOP_DELAY;
return true;
}
}
return false;
}
bool GuiTrigger::Down()
{
u32 wiibtn = WPAD_BUTTON_DOWN;
2021-08-01 19:00:13 +02:00
if (wpad.exp.type == WPAD_EXP_CLASSIC)
* Fixed missing games in "GameCube Delete menu" if the "GameCube Source" setting has USB priority. * Fixed Playlog writing when using Hermes cIOS v4 (untested) (Requires AHB access). * Fixed EmuNAND when using cIOS revision 65535 (issue 2225) * Added Nintendont support: 1. Select Nintendont's boot.dol folder in userpath settings. 2. Set the "GameCube Mode" setting to Nintendont. 3. Nintendont share some of DIOS MIOS (Lite) settings. * Added sections in the Loader settings (Wii/gamecube/Devolution/DIOS MIOS/Nintendont). * Updated the GameCube game settings to display only the selected GameCube mode related settings. * Updated some menus to support more controller's input: - Prevent GC/CC X and Y buttons to change row number in Wall layout (use d-pad up/down only) - Added GC/CC support to carousel's arrow button - Added GC/CC support to Wall/Carousel continuous scroll (+/- on CC, L/R on GC) - Added GC support L/R and Start buttons in the settings/homebrew browser. - Added D-pad support in listing windows if not pointing the screen. The cursor now moves with the selection (not very good with high Overscan value) (issue 2093) * Changed the StartupProcess to speed up launch time by using AHB access to read config files. IOS argument in meta.xml has priority over AHB detection. * Added IOS58 + AHB support for launching the loader without cIOS (Wii games and EmuNAND still require cIOS). * Added a Loader's IOS setting (now Loader and Games use two separate settings: loader can use 58 and games 249). * Added LibruntimeIOSPatch to patch IOS58 and Hermes v4 to get ISFS access and enable Banner mode, Channel's title and System font with these IOSes (Requires AHB access) * Added a delete prompt if downloaded cheat file is empty. * Force all launched homebrew to reload to IOS58 if available. * Changed Gecko.c to send logs to wifigecko too. * Changed wifigecko IP to send logs to all IP 192.168.0.x * Updated French translation.
2013-10-01 23:13:08 +02:00
wiibtn |= WPAD_CLASSIC_BUTTON_DOWN;
2021-08-01 19:00:13 +02:00
if (((wpad.btns_d | wpad.btns_h) & wiibtn) || ((pad.btns_d | pad.btns_h) & PAD_BUTTON_DOWN))
{
2021-08-01 19:00:13 +02:00
if ((wpad.btns_d & wiibtn) || (pad.btns_d & PAD_BUTTON_DOWN))
{
scrollDelay = SCROLL_INITIAL_DELAY; // reset scroll delay.
return true;
}
else if (--scrollDelay <= 0)
{
scrollDelay = SCROLL_LOOP_DELAY;
return true;
}
}
return false;
}