Fix some IHid behavior

This commit is contained in:
piepie62 2020-02-22 17:58:23 -07:00
parent 8ddd0c61b6
commit 8a79ecdf5d
6 changed files with 83 additions and 138 deletions

View file

@ -43,14 +43,14 @@ private:
bool upDown() const override { return hidKeysDown() & KEY_UP; } bool upDown() const override { return hidKeysDown() & KEY_UP; }
bool leftDown() const override { return hidKeysDown() & KEY_LEFT; } bool leftDown() const override { return hidKeysDown() & KEY_LEFT; }
bool rightDown() const override { return hidKeysDown() & KEY_RIGHT; } bool rightDown() const override { return hidKeysDown() & KEY_RIGHT; }
bool leftTriggerDown() const override { return hidKeysDown() & KEY_L; } bool leftTriggerDown() const override { return hidKeysDown() & KEY_L || hidKeysDown() & KEY_ZL; }
bool rightTriggerDown() const override { return hidKeysDown() & KEY_R; } bool rightTriggerDown() const override { return hidKeysDown() & KEY_R || hidKeysDown() & KEY_ZR; }
bool downHeld() const override { return hidKeysHeld() & KEY_DOWN; } bool downHeld() const override { return hidKeysHeld() & KEY_DOWN; }
bool upHeld() const override { return hidKeysHeld() & KEY_UP; } bool upHeld() const override { return hidKeysHeld() & KEY_UP; }
bool leftHeld() const override { return hidKeysHeld() & KEY_LEFT; } bool leftHeld() const override { return hidKeysHeld() & KEY_LEFT; }
bool rightHeld() const override { return hidKeysHeld() & KEY_RIGHT; } bool rightHeld() const override { return hidKeysHeld() & KEY_RIGHT; }
bool leftTriggerHeld() const override { return hidKeysHeld() & KEY_L; } bool leftTriggerHeld() const override { return hidKeysHeld() & KEY_L || hidKeysHeld() & KEY_ZL; }
bool rightTriggerHeld() const override { return hidKeysHeld() & KEY_R; } bool rightTriggerHeld() const override { return hidKeysHeld() & KEY_R || hidKeysHeld() & KEY_ZR; }
u64 tick() const override { return svcGetSystemTick(); } u64 tick() const override { return svcGetSystemTick(); }
}; };

View file

@ -276,13 +276,6 @@ void MainScreen::updateSelector(void)
if (getTitleCount() > 0) { if (getTitleCount() > 0) {
size_t count = getTitleCount(); size_t count = getTitleCount();
hid.update(count); hid.update(count);
// change page
if (hidKeysDown() & KEY_L) {
hid.pageBack(count);
}
else if (hidKeysDown() & KEY_R) {
hid.pageForward(count);
}
directoryList->resetIndex(); directoryList->resetIndex();
} }
} }
@ -559,4 +552,4 @@ void MainScreen::updateButtons(void)
std::string MainScreen::nameFromCell(size_t index) const std::string MainScreen::nameFromCell(size_t index) const
{ {
return directoryList->cellName(index); return directoryList->cellName(index);
} }

View file

@ -57,7 +57,7 @@ public:
size_t fullIndex(void) const { return mIndex + mPage * mMaxVisibleEntries; } size_t fullIndex(void) const { return mIndex + mPage * mMaxVisibleEntries; }
size_t index(void) const { return mIndex; } size_t index(void) const { return mIndex; }
void index(size_t v) { mIndex = v;} void index(size_t v) { mIndex = v; }
size_t maxVisibleEntries(void) const { return mMaxVisibleEntries; } size_t maxVisibleEntries(void) const { return mMaxVisibleEntries; }
int page(void) const { return mPage; } int page(void) const { return mPage; }
void page(int v) { mPage = v; } void page(int v) { mPage = v; }
@ -65,7 +65,7 @@ public:
{ {
return (count - mPage * mMaxVisibleEntries) > mMaxVisibleEntries ? mMaxVisibleEntries - 1 : count - mPage * mMaxVisibleEntries - 1; return (count - mPage * mMaxVisibleEntries) > mMaxVisibleEntries ? mMaxVisibleEntries - 1 : count - mPage * mMaxVisibleEntries - 1;
} }
void pageBack(size_t count) void pageBack()
{ {
if (mPage > 0) if (mPage > 0)
{ {
@ -75,12 +75,8 @@ public:
{ {
mPage = mMaxPages - 1; mPage = mMaxPages - 1;
} }
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
} }
void pageForward(size_t count) void pageForward()
{ {
if (mPage < (int)mMaxPages - 1) if (mPage < (int)mMaxPages - 1)
{ {
@ -90,16 +86,31 @@ public:
{ {
mPage = 0; mPage = 0;
} }
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
} }
void reset(void) void reset(void)
{ {
mIndex = 0; mIndex = 0;
mPage = 0; mPage = 0;
} }
void correctIndex(size_t count)
{
if (mIndex > maxEntries(count))
{
if constexpr (ListDirection == HidDirection::HORIZONTAL)
{
mIndex = mIndex % mColumns;
}
else
{
mIndex = mIndex % mRows;
}
// If the above doesn't fix, then forcibly fix
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
}
}
void update(size_t count); void update(size_t count);

View file

@ -24,8 +24,6 @@
* reasonable ways as different from the original version. * reasonable ways as different from the original version.
*/ */
#include "ihid.hpp"
#ifndef IHID_HPP #ifndef IHID_HPP
#error "This file should not be directly included!" #error "This file should not be directly included!"
#endif #endif
@ -39,19 +37,11 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
if (leftTriggerDown()) if (leftTriggerDown())
{ {
pageBack(count); pageBack();
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
} }
else if (rightTriggerDown()) else if (rightTriggerDown())
{ {
pageForward(count); pageForward();
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
} }
else if (leftTriggerHeld()) else if (leftTriggerHeld())
{ {
@ -60,11 +50,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
return; return;
} }
pageBack(count); pageBack();
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
} }
else if (rightTriggerHeld()) else if (rightTriggerHeld())
{ {
@ -73,11 +59,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
return; return;
} }
pageForward(count); pageForward();
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
} }
if constexpr (ListDirection == HidDirection::HORIZONTAL) if constexpr (ListDirection == HidDirection::HORIZONTAL)
@ -88,7 +70,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageBack(count); pageBack();
} }
mIndex += mColumns * (mRows - 1); mIndex += mColumns * (mRows - 1);
} }
@ -99,17 +81,14 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
} }
else if (downDown()) else if (downDown())
{ {
if (mIndex >= mColumns * (mRows - 1)) mIndex += mColumns;
if (mIndex > maxEntries(count))
{ {
mIndex %= mColumns;
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageForward(count); pageForward();
} }
mIndex -= mColumns * (mRows - 1);
}
else
{
mIndex += mColumns;
} }
} }
else if (upHeld()) else if (upHeld())
@ -122,7 +101,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageBack(count); pageBack();
} }
mIndex += mColumns * (mRows - 1); mIndex += mColumns * (mRows - 1);
} }
@ -137,17 +116,14 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
return; return;
} }
if (mIndex >= mColumns * (mRows - 1)) mIndex += mColumns;
if (mIndex > maxEntries(count))
{ {
mIndex %= mColumns;
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageForward(count); pageForward();
} }
mIndex -= mColumns * (mRows - 1);
}
else
{
mIndex += mColumns;
} }
} }
@ -159,35 +135,32 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
} }
else else
{ {
mIndex += mColumns - 1;
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageBack(count); pageBack();
} }
mIndex += mColumns - 1;
} }
} }
else if (rightDown()) else if (rightDown())
{ {
if (mIndex % mColumns != mColumns - 1) if (mIndex % mColumns != mColumns - 1)
{ {
if (mIndex + mPage * mMaxVisibleEntries == count - 1) mIndex++;
if (mIndex > maxEntries(count))
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageForward(count); pageForward();
} }
mIndex = (mIndex / mColumns) * mColumns; mIndex = mIndex - (mIndex % mColumns);
}
else
{
mIndex++;
} }
} }
else else
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageForward(count); pageForward();
} }
mIndex -= mColumns - 1; mIndex -= mColumns - 1;
} }
@ -206,7 +179,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageBack(count); pageBack();
} }
mIndex += mColumns - 1; mIndex += mColumns - 1;
} }
@ -219,24 +192,21 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
} }
if (mIndex % mColumns != mColumns - 1) if (mIndex % mColumns != mColumns - 1)
{ {
if (mIndex + mPage * mMaxVisibleEntries == count - 1) mIndex++;
if (mIndex > maxEntries(count))
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageForward(count); pageForward();
} }
mIndex = (mIndex / mColumns) * mColumns; mIndex = mIndex - (mIndex % mColumns);
}
else
{
mIndex++;
} }
} }
else else
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageForward(count); pageForward();
} }
mIndex -= mColumns - 1; mIndex -= mColumns - 1;
} }
@ -246,7 +216,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if (leftDown()) if (leftDown())
{ {
if (mIndex % mRows != mIndex) if (mIndex / mRows != 0)
{ {
mIndex -= mRows; mIndex -= mRows;
} }
@ -254,31 +224,21 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageBack(count); pageBack();
} }
mIndex += mRows; mIndex += mRows * (mColumns - 1);
} }
} }
else if (rightDown()) else if (rightDown())
{ {
if (maxEntries(count) < mRows) mIndex += mRows;
if (mIndex > maxEntries(count))
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageForward(count); pageForward();
} }
} mIndex %= mRows;
else if (mIndex + mRows < mMaxVisibleEntries)
{
mIndex += mRows;
}
else
{
if constexpr (PageDirection == HidDirection::HORIZONTAL)
{
pageForward(count);
}
mIndex -= mRows;
} }
} }
else if (leftHeld()) else if (leftHeld())
@ -287,7 +247,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
return; return;
} }
if (mIndex % mRows != mIndex) if (mIndex / mRows != 0)
{ {
mIndex -= mRows; mIndex -= mRows;
} }
@ -295,9 +255,9 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageBack(count); pageBack();
} }
mIndex += mRows; mIndex += mRows * (mColumns - 1);
} }
} }
else if (rightHeld()) else if (rightHeld())
@ -306,24 +266,14 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
return; return;
} }
if (maxEntries(count) < mRows) mIndex += mRows;
if (mIndex > maxEntries(count))
{ {
if constexpr (PageDirection == HidDirection::HORIZONTAL) if constexpr (PageDirection == HidDirection::HORIZONTAL)
{ {
pageForward(count); pageForward();
} }
} mIndex %= mRows;
else if (mIndex + mRows < mMaxVisibleEntries)
{
mIndex += mRows;
}
else
{
if constexpr (PageDirection == HidDirection::HORIZONTAL)
{
pageForward(count);
}
mIndex -= mRows;
} }
} }
@ -337,7 +287,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageBack(count); pageBack();
} }
mIndex = mIndex + mRows - 1; mIndex = mIndex + mRows - 1;
} }
@ -350,9 +300,9 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageForward(count); pageForward();
} }
mIndex = (mIndex / mRows) * mRows; mIndex = mIndex - (mIndex % mRows);
} }
else else
{ {
@ -363,7 +313,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageForward(count); pageForward();
} }
mIndex = mIndex + 1 - mRows; mIndex = mIndex + 1 - mRows;
} }
@ -382,7 +332,7 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageBack(count); pageBack();
} }
mIndex = mIndex + mRows - 1; mIndex = mIndex + mRows - 1;
} }
@ -399,9 +349,9 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageForward(count); pageForward();
} }
mIndex = (mIndex / mRows) * mRows; mIndex = mIndex - (mIndex % mRows);
} }
else else
{ {
@ -412,16 +362,14 @@ void IHid<ListDirection, PageDirection, Delay>::update(size_t count)
{ {
if constexpr (PageDirection == HidDirection::VERTICAL) if constexpr (PageDirection == HidDirection::VERTICAL)
{ {
pageForward(count); pageForward();
} }
mIndex = mIndex + 1 - mRows; mIndex = mIndex + 1 - mRows;
} }
} }
} }
if (mIndex > maxEntries(count)) correctIndex(count);
{
mIndex = maxEntries(count);
}
mLastTime = currentTime; mLastTime = currentTime;
} }

View file

@ -43,14 +43,14 @@ private:
bool upDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_UP; } bool upDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_UP; }
bool leftDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_LEFT; } bool leftDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_LEFT; }
bool rightDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_RIGHT; } bool rightDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_RIGHT; }
bool leftTriggerDown() const override { return false; } bool leftTriggerDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_L; }
bool rightTriggerDown() const override { return false; } bool rightTriggerDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_R; }
bool downHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_DOWN; } bool downHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_DOWN; }
bool upHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_UP; } bool upHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_UP; }
bool leftHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_LEFT; } bool leftHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_LEFT; }
bool rightHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_RIGHT; } bool rightHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_RIGHT; }
bool leftTriggerHeld() const override { return false; } bool leftTriggerHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_L; }
bool rightTriggerHeld() const override { return false; } bool rightTriggerHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_R; }
u64 tick() const override { return armGetSystemTick(); } u64 tick() const override { return armGetSystemTick(); }
}; };

View file

@ -235,13 +235,6 @@ void MainScreen::updateSelector(touchPosition* touch)
size_t count = getTitleCount(g_currentUId); size_t count = getTitleCount(g_currentUId);
size_t oldindex = hid.index(); size_t oldindex = hid.index();
hid.update(count); hid.update(count);
// change page
if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_L) {
hid.pageBack(count);
}
else if (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_R) {
hid.pageForward(count);
}
// loop through every rendered title // loop through every rendered title
for (u8 row = 0; row < rowlen; row++) { for (u8 row = 0; row < rowlen; row++) {
@ -636,4 +629,4 @@ std::string MainScreen::sortMode() const
break; break;
} }
return ""; return "";
} }