diff --git a/common/menu-list.c b/common/menu-list.c index 64fd6e3..dd8cb1a 100644 --- a/common/menu-list.c +++ b/common/menu-list.c @@ -35,6 +35,7 @@ static void _menuAddEntry(menu_s *m, menuEntry_s* me) { m->lastEntry = me; } m->xPos = 0; + m->slideSpeed = 0; m->nEntries ++; } @@ -59,6 +60,7 @@ static void menuAddEntryToFront(menuEntry_s* me) { m->lastEntry = me; } m->xPos = 0; + m->slideSpeed = 0; m->nEntries ++; } diff --git a/common/menu.c b/common/menu.c index cd184bd..5bdb82a 100644 --- a/common/menu.c +++ b/common/menu.c @@ -800,14 +800,35 @@ void menuLoop(void) { int entries_count = layoutobj->posEnd[0]; layoutobj = &themeCurrent.layoutObjects[ThemeLayoutId_MenuList]; - if (menu->nEntries > entries_count) { - int wanted_x = clamp(-menu->curEntry * layoutobj->posEnd[0], -(menu->nEntries - entries_count) * layoutobj->posEnd[0], 0); - menu->xPos += v; - v += (wanted_x - menu->xPos) / 3; - v /= 2; + // Gentle Realign only when not manually moving + if (menu->slideSpeed == 0) { + if (menu->nEntries > entries_count) { + int wanted_x = clamp(-menu->curEntry * layoutobj->posEnd[0], -(menu->nEntries - entries_count) * layoutobj->posEnd[0], 0); + menu->xPos += v; + v += (wanted_x - menu->xPos) / 3; + v /= 2; + } + else { + menu->xPos = v = 0; + } } else { - menu->xPos = v = 0; + menu->xPos += menu->slideSpeed; + + if (abs(menu->slideSpeed) > 2) { + // Slow down way faster when outside the normal bounds + if (menu->xPos > 0 || menu->xPos < -(menu->nEntries) * layoutobj->posEnd[0]) { + menu->slideSpeed *= .5f; + } + else { + menu->slideSpeed *= .9f; + } + } + else { + menu->slideSpeed = 0; + } + + menu->curEntry = clamp(roundf(-((float) menu->xPos / layoutobj->posEnd[0])), 0, menu->nEntries); } menuEntry_s *active_entry = NULL; diff --git a/common/menu.h b/common/menu.h index 5db2950..e7ae396 100644 --- a/common/menu.h +++ b/common/menu.h @@ -33,6 +33,7 @@ struct menu_s_tag int nEntries; int curEntry; int xPos; + int slideSpeed; char dirname[PATH_MAX+1]; }; diff --git a/nx_main/nx_touch.c b/nx_main/nx_touch.c index ec38810..9143c74 100644 --- a/nx_main/nx_touch.c +++ b/nx_main/nx_touch.c @@ -15,6 +15,7 @@ void touchInit() { touchInfo.isTap = true; touchInfo.initMenuXPos = 0; touchInfo.initMenuIndex = 0; + touchInfo.lastSlideSpeed = 0; } void handleTappingOnApp(menu_s* menu, int px) { @@ -72,25 +73,25 @@ void handleTouch(menu_s* menu) { touchInfo.isTap = true; touchInfo.initMenuXPos = menu->xPos; touchInfo.initMenuIndex = menu->curEntry; + touchInfo.lastSlideSpeed = 0; + menu->slideSpeed = 0; } // On touch moving. else if (touches >= 1 && touchInfo.gestureInProgress) { hidTouchRead(¤tTouch, 0); + touchInfo.lastSlideSpeed = ((int)(currentTouch.px - touchInfo.prevTouch.px)); + touchInfo.prevTouch = currentTouch; if (touchInfo.isTap && (abs(touchInfo.firstTouch.px - currentTouch.px) > TAP_MOVEMENT_GAP || abs(touchInfo.firstTouch.py - currentTouch.py) > 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) { - menu->xPos = touchInfo.initMenuXPos + (currentTouch.px - touchInfo.firstTouch.px); - menu->curEntry = touchInfo.initMenuIndex + ((int) (touchInfo.firstTouch.px - currentTouch.px) / layoutobj->posEnd[0]); - if (menu->curEntry < 0) - menu->curEntry = 0; - - if (menu->curEntry >= menu->nEntries - entries_count - 1) - menu->curEntry = menu->nEntries - entries_count; + if (!touchInfo.isTap) { + menu->slideSpeed = touchInfo.lastSlideSpeed; + } } } // On touch end. @@ -100,6 +101,10 @@ void handleTouch(menu_s* menu) { int x2 = touchInfo.prevTouch.px; int y2 = touchInfo.prevTouch.py; + if (!touchInfo.isTap) { + menu->slideSpeed = touchInfo.lastSlideSpeed; + } + bool netloader_active = menuIsNetloaderActive(); if (menuIsMsgBoxOpen() && !netloader_active) { diff --git a/nx_main/nx_touch.h b/nx_main/nx_touch.h index cea6010..2ef9f21 100644 --- a/nx_main/nx_touch.h +++ b/nx_main/nx_touch.h @@ -10,6 +10,7 @@ struct touchInfo_s { bool isTap; int initMenuXPos; int initMenuIndex; + int lastSlideSpeed; }; void handleTouch(menu_s* menu); \ No newline at end of file