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 leftDown() const override { return hidKeysDown() & KEY_LEFT; }
bool rightDown() const override { return hidKeysDown() & KEY_RIGHT; }
bool leftTriggerDown() const override { return hidKeysDown() & KEY_L; }
bool rightTriggerDown() const override { return hidKeysDown() & KEY_R; }
bool leftTriggerDown() const override { return hidKeysDown() & KEY_L || hidKeysDown() & KEY_ZL; }
bool rightTriggerDown() const override { return hidKeysDown() & KEY_R || hidKeysDown() & KEY_ZR; }
bool downHeld() const override { return hidKeysHeld() & KEY_DOWN; }
bool upHeld() const override { return hidKeysHeld() & KEY_UP; }
bool leftHeld() const override { return hidKeysHeld() & KEY_LEFT; }
bool rightHeld() const override { return hidKeysHeld() & KEY_RIGHT; }
bool leftTriggerHeld() const override { return hidKeysHeld() & KEY_L; }
bool rightTriggerHeld() const override { return hidKeysHeld() & KEY_R; }
bool leftTriggerHeld() const override { return hidKeysHeld() & KEY_L || hidKeysHeld() & KEY_ZL; }
bool rightTriggerHeld() const override { return hidKeysHeld() & KEY_R || hidKeysHeld() & KEY_ZR; }
u64 tick() const override { return svcGetSystemTick(); }
};

View file

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

View file

@ -57,7 +57,7 @@ public:
size_t fullIndex(void) const { return mIndex + mPage * mMaxVisibleEntries; }
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; }
int page(void) const { return mPage; }
void page(int v) { mPage = v; }
@ -65,7 +65,7 @@ public:
{
return (count - mPage * mMaxVisibleEntries) > mMaxVisibleEntries ? mMaxVisibleEntries - 1 : count - mPage * mMaxVisibleEntries - 1;
}
void pageBack(size_t count)
void pageBack()
{
if (mPage > 0)
{
@ -75,12 +75,8 @@ public:
{
mPage = mMaxPages - 1;
}
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
}
void pageForward(size_t count)
void pageForward()
{
if (mPage < (int)mMaxPages - 1)
{
@ -90,16 +86,31 @@ public:
{
mPage = 0;
}
if (mIndex > maxEntries(count))
{
mIndex = maxEntries(count);
}
}
void reset(void)
{
mIndex = 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);

View file

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

View file

@ -43,14 +43,14 @@ private:
bool upDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_UP; }
bool leftDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_LEFT; }
bool rightDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_RIGHT; }
bool leftTriggerDown() const override { return false; }
bool rightTriggerDown() const override { return false; }
bool leftTriggerDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_L; }
bool rightTriggerDown() const override { return hidKeysDown(CONTROLLER_P1_AUTO) & KEY_R; }
bool downHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_DOWN; }
bool upHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_UP; }
bool leftHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_LEFT; }
bool rightHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_RIGHT; }
bool leftTriggerHeld() const override { return false; }
bool rightTriggerHeld() const override { return false; }
bool leftTriggerHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_L; }
bool rightTriggerHeld() const override { return hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_R; }
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 oldindex = hid.index();
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
for (u8 row = 0; row < rowlen; row++) {
@ -636,4 +629,4 @@ std::string MainScreen::sortMode() const
break;
}
return "";
}
}