Update for libnx hid-refactor
This commit is contained in:
parent
fcbc56acc4
commit
20c1f00972
@ -13,6 +13,9 @@
|
||||
uint8_t* g_framebuf;
|
||||
u32 g_framebuf_width;
|
||||
|
||||
PadState g_pad;
|
||||
PadRepeater g_pad_repeater;
|
||||
|
||||
bool menuUpdateErrorScreen(void);
|
||||
|
||||
#ifdef PERF_LOG
|
||||
@ -38,6 +41,12 @@ int main(int argc, char **argv)
|
||||
u64 start_tick=0;
|
||||
#endif
|
||||
|
||||
padConfigureInput(8, HidNpadStyleSet_NpadStandard);
|
||||
padInitializeAny(&g_pad);
|
||||
padRepeaterInitialize(&g_pad_repeater, 20, 10);
|
||||
hidSetNpadHandheldActivationMode(HidNpadHandheldActivationMode_Single);
|
||||
touchInit();
|
||||
|
||||
memset(errormsg, 0, sizeof(errormsg));
|
||||
|
||||
appletLockExit();
|
||||
@ -129,10 +138,11 @@ int main(int argc, char **argv)
|
||||
|
||||
while (appletMainLoop())
|
||||
{
|
||||
|
||||
|
||||
//Scan all the inputs. This should be done once for each frame
|
||||
hidScanInput();
|
||||
// Scan the gamepad. This should be done once for each frame
|
||||
padUpdate(&g_pad);
|
||||
padRepeaterUpdate(&g_pad_repeater, padGetButtons(&g_pad) & (
|
||||
HidNpadButton_AnyLeft | HidNpadButton_AnyUp | HidNpadButton_AnyRight | HidNpadButton_AnyDown
|
||||
));
|
||||
|
||||
if (!error_screen) {
|
||||
if (!uiUpdate()) break;
|
||||
@ -186,14 +196,9 @@ int main(int argc, char **argv)
|
||||
}
|
||||
|
||||
u64 menuGetKeysDown(void) {
|
||||
u64 down = 0;
|
||||
|
||||
for (u32 controller=0; controller<8; controller++) {
|
||||
if (hidIsControllerConnected(controller)) down |= hidKeysDown(controller);
|
||||
}
|
||||
if (hidIsControllerConnected(CONTROLLER_HANDHELD)) down |= hidKeysDown(CONTROLLER_HANDHELD);
|
||||
|
||||
return down;
|
||||
u64 keys = padGetButtonsDown(&g_pad);
|
||||
keys |= padRepeaterGetButtons(&g_pad_repeater);
|
||||
return keys;
|
||||
}
|
||||
|
||||
//This is implemented here due to the hid code.
|
||||
@ -206,26 +211,26 @@ bool menuUpdate(void) {
|
||||
|
||||
handleTouch(menu);
|
||||
|
||||
if (down & KEY_Y)
|
||||
if (down & HidNpadButton_Y)
|
||||
{
|
||||
launchMenuNetloaderTask();
|
||||
}
|
||||
else if (down & KEY_X)
|
||||
else if (down & HidNpadButton_X)
|
||||
{
|
||||
menuHandleXButton();
|
||||
}
|
||||
else if (down & KEY_A)
|
||||
else if (down & HidNpadButton_A)
|
||||
{
|
||||
menuHandleAButton();
|
||||
}
|
||||
else if (down & KEY_B)
|
||||
else if (down & HidNpadButton_B)
|
||||
{
|
||||
launchMenuBackTask();
|
||||
}
|
||||
else if(down & KEY_MINUS){
|
||||
else if(down & HidNpadButton_Minus){
|
||||
themeMenuStartup();
|
||||
}
|
||||
else if (down & KEY_PLUS)
|
||||
else if (down & HidNpadButton_Plus)
|
||||
{
|
||||
exitflag = 1;
|
||||
}
|
||||
@ -233,10 +238,10 @@ bool menuUpdate(void) {
|
||||
{
|
||||
int move = 0;
|
||||
|
||||
if (down & KEY_LEFT) move--;
|
||||
if (down & KEY_RIGHT) move++;
|
||||
if (down & KEY_DOWN) move-=entries_count;
|
||||
if (down & KEY_UP) move+=entries_count;
|
||||
if (down & HidNpadButton_AnyLeft) move--;
|
||||
if (down & HidNpadButton_AnyRight) move++;
|
||||
if (down & HidNpadButton_AnyDown) move-=entries_count;
|
||||
if (down & HidNpadButton_AnyUp) move+=entries_count;
|
||||
|
||||
int newEntry = menu->curEntry + move;
|
||||
if (newEntry < 0) newEntry = 0;
|
||||
@ -251,7 +256,7 @@ bool menuUpdateErrorScreen(void) {
|
||||
bool exitflag = 0;
|
||||
u64 down = menuGetKeysDown();
|
||||
|
||||
if (down & KEY_PLUS)
|
||||
if (down & HidNpadButton_Plus)
|
||||
{
|
||||
exitflag = 1;
|
||||
}
|
||||
|
@ -10,12 +10,13 @@
|
||||
|
||||
struct touchInfo_s touchInfo;
|
||||
|
||||
void touchInit() {
|
||||
void touchInit(void) {
|
||||
touchInfo.gestureInProgress = false;
|
||||
touchInfo.isTap = true;
|
||||
touchInfo.initMenuXPos = 0;
|
||||
touchInfo.initMenuIndex = 0;
|
||||
touchInfo.lastSlideSpeed = 0;
|
||||
hidInitializeTouchScreen();
|
||||
}
|
||||
|
||||
void handleTappingOnApp(menu_s* menu, int px) {
|
||||
@ -56,20 +57,18 @@ static inline bool checkInsideTextLayoutObject(ThemeLayoutId id, int x, int y) {
|
||||
|
||||
void handleTouch(menu_s* menu) {
|
||||
ThemeLayoutObject *layoutobj = NULL;
|
||||
touchPosition currentTouch;
|
||||
u32 touches = hidTouchCount();
|
||||
HidTouchScreenState touch = {0};
|
||||
hidGetTouchScreenStates(&touch, 1);
|
||||
|
||||
layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuListTiles];
|
||||
int entries_count = layoutobj->posEnd[0];
|
||||
layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuList];
|
||||
|
||||
// On touch start.
|
||||
if (touches == 1 && !touchInfo.gestureInProgress) {
|
||||
hidTouchRead(¤tTouch, 0);
|
||||
|
||||
if (touch.count == 1 && !touchInfo.gestureInProgress) {
|
||||
touchInfo.gestureInProgress = true;
|
||||
touchInfo.firstTouch = currentTouch;
|
||||
touchInfo.prevTouch = currentTouch;
|
||||
touchInfo.firstTouch = touch.touches[0];
|
||||
touchInfo.prevTouch = touch.touches[0];
|
||||
touchInfo.isTap = true;
|
||||
touchInfo.initMenuXPos = menu->xPos;
|
||||
touchInfo.initMenuIndex = menu->curEntry;
|
||||
@ -77,17 +76,15 @@ void handleTouch(menu_s* menu) {
|
||||
menu->slideSpeed = 0;
|
||||
}
|
||||
// On touch moving.
|
||||
else if (touches >= 1 && touchInfo.gestureInProgress) {
|
||||
hidTouchRead(¤tTouch, 0);
|
||||
else if (touch.count >= 1 && touchInfo.gestureInProgress) {
|
||||
touchInfo.lastSlideSpeed = ((int)(touch.touches[0].x - touchInfo.prevTouch.x));
|
||||
|
||||
touchInfo.lastSlideSpeed = ((int)(currentTouch.px - touchInfo.prevTouch.px));
|
||||
touchInfo.prevTouch = touch.touches[0];
|
||||
|
||||
touchInfo.prevTouch = currentTouch;
|
||||
|
||||
if (touchInfo.isTap && (abs(touchInfo.firstTouch.px - currentTouch.px) > TAP_MOVEMENT_GAP || abs(touchInfo.firstTouch.py - currentTouch.py) > TAP_MOVEMENT_GAP)) {
|
||||
if (touchInfo.isTap && (abs(touchInfo.firstTouch.x - touch.touches[0].x) > TAP_MOVEMENT_GAP || abs(touchInfo.firstTouch.y - touch.touches[0].y) > TAP_MOVEMENT_GAP)) {
|
||||
touchInfo.isTap = false;
|
||||
}
|
||||
if (!menuIsMsgBoxOpen() && touchInfo.firstTouch.py > layoutobj->posStart[1] && touchInfo.firstTouch.py < layoutobj->posStart[1]+layoutobj->size[1] && !touchInfo.isTap && menu->nEntries > entries_count) {
|
||||
if (!menuIsMsgBoxOpen() && touchInfo.firstTouch.y > layoutobj->posStart[1] && touchInfo.firstTouch.y < layoutobj->posStart[1]+layoutobj->size[1] && !touchInfo.isTap && menu->nEntries > entries_count) {
|
||||
|
||||
if (!touchInfo.isTap) {
|
||||
menu->slideSpeed = touchInfo.lastSlideSpeed;
|
||||
@ -96,10 +93,10 @@ void handleTouch(menu_s* menu) {
|
||||
}
|
||||
// On touch end.
|
||||
else if (touchInfo.gestureInProgress) {
|
||||
int x1 = touchInfo.firstTouch.px;
|
||||
int y1 = touchInfo.firstTouch.py;
|
||||
int x2 = touchInfo.prevTouch.px;
|
||||
int y2 = touchInfo.prevTouch.py;
|
||||
int x1 = touchInfo.firstTouch.x;
|
||||
int y1 = touchInfo.firstTouch.y;
|
||||
int x2 = touchInfo.prevTouch.x;
|
||||
int y2 = touchInfo.prevTouch.y;
|
||||
|
||||
if (!touchInfo.isTap) {
|
||||
menu->slideSpeed = touchInfo.lastSlideSpeed;
|
||||
@ -122,7 +119,7 @@ void handleTouch(menu_s* menu) {
|
||||
} else if (touchInfo.isTap && !netloader_active) {
|
||||
// App Icons
|
||||
if (y1 > layoutobj->posStart[1] && y1 < layoutobj->posStart[1]+layoutobj->size[1]) {
|
||||
handleTappingOnApp(menu, touchInfo.prevTouch.px);
|
||||
handleTappingOnApp(menu, touchInfo.prevTouch.x);
|
||||
}
|
||||
// Bottom Buttons
|
||||
else {
|
||||
|
@ -5,12 +5,13 @@
|
||||
|
||||
struct touchInfo_s {
|
||||
bool gestureInProgress;
|
||||
touchPosition firstTouch;
|
||||
touchPosition prevTouch;
|
||||
HidTouchState firstTouch;
|
||||
HidTouchState prevTouch;
|
||||
bool isTap;
|
||||
int initMenuXPos;
|
||||
int initMenuIndex;
|
||||
int lastSlideSpeed;
|
||||
};
|
||||
|
||||
void touchInit(void);
|
||||
void handleTouch(menu_s* menu);
|
Loading…
Reference in New Issue
Block a user