mirror of
https://github.com/BernardoGiordano/Checkpoint
synced 2024-12-01 04:49:10 +00:00
Fix #173
This commit is contained in:
parent
7efd3d4644
commit
d69400360d
10 changed files with 609 additions and 173 deletions
|
@ -30,15 +30,13 @@
|
|||
#include <3ds.h>
|
||||
#include "ihid.hpp"
|
||||
|
||||
#define DELAY_TICKS 50000000
|
||||
|
||||
class Hid : public IHid
|
||||
class HidHorizontal : public IHidHorizontal
|
||||
{
|
||||
public:
|
||||
Hid(size_t entries, size_t columns)
|
||||
: IHid(entries, columns) { }
|
||||
HidHorizontal(size_t entries, size_t columns)
|
||||
: IHidHorizontal(entries, columns) { mDelayTicks = 50000000; }
|
||||
|
||||
virtual ~Hid(void) { }
|
||||
virtual ~HidHorizontal(void) { }
|
||||
|
||||
u64 down(void) override
|
||||
{
|
||||
|
@ -50,14 +48,40 @@ public:
|
|||
return (u64)hidKeysHeld();
|
||||
}
|
||||
|
||||
void update(size_t count)
|
||||
u64 tick(void) override
|
||||
{
|
||||
mCurrentTime = svcGetSystemTick();
|
||||
if ((mCurrentTime > mLastTime + DELAY_TICKS))
|
||||
{
|
||||
IHid::update(count);
|
||||
mLastTime = mCurrentTime;
|
||||
}
|
||||
return svcGetSystemTick();
|
||||
}
|
||||
|
||||
u64 _KEY_ZL(void) override { return KEY_ZL; }
|
||||
u64 _KEY_ZR(void) override { return KEY_ZR; }
|
||||
u64 _KEY_LEFT(void) override { return KEY_LEFT; }
|
||||
u64 _KEY_RIGHT(void) override { return KEY_RIGHT; }
|
||||
u64 _KEY_UP(void) override { return KEY_UP; }
|
||||
u64 _KEY_DOWN(void) override { return KEY_DOWN; }
|
||||
};
|
||||
|
||||
class HidVertical : public IHidVertical
|
||||
{
|
||||
public:
|
||||
HidVertical(size_t entries, size_t columns)
|
||||
: IHidVertical(entries, columns) { mDelayTicks = 50000000; }
|
||||
|
||||
virtual ~HidVertical(void) { }
|
||||
|
||||
u64 down(void) override
|
||||
{
|
||||
return (u64)hidKeysDown();
|
||||
}
|
||||
|
||||
u64 held(void) override
|
||||
{
|
||||
return (u64)hidKeysHeld();
|
||||
}
|
||||
|
||||
u64 tick(void) override
|
||||
{
|
||||
return svcGetSystemTick();
|
||||
}
|
||||
|
||||
u64 _KEY_ZL(void) override { return KEY_ZL; }
|
||||
|
|
|
@ -40,7 +40,7 @@ public:
|
|||
Scrollable(int x, int y, u32 w, u32 h, size_t visibleEntries)
|
||||
: IScrollable(x, y, w, h, visibleEntries)
|
||||
{
|
||||
mHid = new Hid(visibleEntries, 1);
|
||||
mHid = new HidVertical(visibleEntries, 1);
|
||||
}
|
||||
|
||||
virtual ~Scrollable(void)
|
||||
|
@ -55,7 +55,7 @@ public:
|
|||
void updateSelection(void) override;
|
||||
|
||||
protected:
|
||||
Hid* mHid;
|
||||
HidVertical* mHid;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -51,7 +51,7 @@ static Scrollable* directoryList;
|
|||
static const size_t rowlen = 4;
|
||||
static const size_t collen = 8;
|
||||
static bool bottomScrollEnabled;
|
||||
static Hid* hid;
|
||||
static HidHorizontal* hid;
|
||||
|
||||
static void drawBackground(gfxScreen_t screen);
|
||||
static void drawSelector(void);
|
||||
|
@ -250,7 +250,7 @@ void Gui::init(void)
|
|||
bottom = C2D_CreateScreenTarget(GFX_BOTTOM, GFX_LEFT);
|
||||
|
||||
bottomScrollEnabled = false;
|
||||
hid = new Hid(rowlen * collen, collen);
|
||||
hid = new HidHorizontal(rowlen * collen, collen);
|
||||
|
||||
info = new Info();
|
||||
info->init("", "", 0, TYPE_INFO);
|
||||
|
@ -259,16 +259,16 @@ void Gui::init(void)
|
|||
copyList = new MessageBox(COLOR_GREY_DARK, COLOR_WHITE, GFX_TOP);
|
||||
directoryList = new Scrollable(6, 102, 196, 110, 5);
|
||||
messageBox = new MessageBox(COLOR_GREY_DARK, COLOR_WHITE, GFX_TOP);
|
||||
messageBox->push_message("Press \uE000 to enter target.");
|
||||
messageBox->push_message("Press \uE004 to backup target.");
|
||||
messageBox->push_message("Press \uE005 to restore target.");
|
||||
messageBox->push_message("Press \uE001 to exit target or deselect all titles.");
|
||||
messageBox->push_message("Press \uE002 to delete a backup.");
|
||||
messageBox->push_message("Press \uE003 to multiselect a title.");
|
||||
messageBox->push_message("Hold \uE003 to multiselect all titles.");
|
||||
messageBox->push_message("Press \uE006 to move between titles.");
|
||||
messageBox->push_message("Press \uE054\uE055 to switch page.");
|
||||
messageBox->push_message("Hold \uE001 to refresh titles.");
|
||||
messageBox->push_message("Press \uE000 to enter target");
|
||||
messageBox->push_message("Press \uE004 to backup target");
|
||||
messageBox->push_message("Press \uE005 to restore target");
|
||||
messageBox->push_message("Press \uE001 to exit target or deselect all titles");
|
||||
messageBox->push_message("Press \uE002 to delete a backup");
|
||||
messageBox->push_message("Press \uE003 to multiselect a title");
|
||||
messageBox->push_message("Hold \uE003 to multiselect all titles");
|
||||
messageBox->push_message("Press \uE006 to move between titles");
|
||||
messageBox->push_message("Press \uE054\uE055 to switch page");
|
||||
messageBox->push_message("Hold \uE001 to refresh titles");
|
||||
|
||||
spritesheet = C2D_SpriteSheetLoad("romfs:/gfx/sprites.t3x");
|
||||
flag = C2D_SpriteSheetGetImage(spritesheet, sprites_checkpoint_idx);
|
||||
|
|
126
common/ihid.cpp
126
common/ihid.cpp
|
@ -89,130 +89,4 @@ void IHid::page_forward(void)
|
|||
{
|
||||
mPage = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void IHid::update(size_t count) {
|
||||
mMaxPages = (count % mMaxVisibleEntries == 0) ? count / mMaxVisibleEntries : count / mMaxVisibleEntries + 1;
|
||||
|
||||
u64 kHeld = held();
|
||||
u64 kDown = down();
|
||||
|
||||
if (kDown & _KEY_ZL())
|
||||
{
|
||||
page_back();
|
||||
if (mIndex > maxEntries(count))
|
||||
{
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_ZR())
|
||||
{
|
||||
page_forward();
|
||||
if (mIndex > maxEntries(count))
|
||||
{
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (mColumns > 1)
|
||||
{
|
||||
if (kHeld & _KEY_LEFT())
|
||||
{
|
||||
if (mIndex > 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else if (mIndex == 0)
|
||||
{
|
||||
page_back();
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_RIGHT())
|
||||
{
|
||||
if (mIndex < maxEntries(count))
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
else if (mIndex == maxEntries(count))
|
||||
{
|
||||
page_forward();
|
||||
mIndex = 0;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_UP())
|
||||
{
|
||||
if (mIndex < mColumns)
|
||||
{
|
||||
// store the previous page
|
||||
int page = mPage;
|
||||
// update it
|
||||
page_back();
|
||||
// refresh the maximum amount of entries
|
||||
size_t maxentries = maxEntries(count);
|
||||
// if we went to the last page, make sure we go to the last valid row instead of the last absolute one
|
||||
mIndex = page == 0 ? (size_t)((floor(maxentries / mColumns) + 1)) * mColumns + mIndex - mColumns : mMaxVisibleEntries + mIndex - mColumns;
|
||||
// handle possible overflows
|
||||
if (mIndex > maxentries)
|
||||
{
|
||||
mIndex = maxentries;
|
||||
}
|
||||
}
|
||||
else if (mIndex >= mColumns)
|
||||
{
|
||||
mIndex -= mColumns;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_DOWN())
|
||||
{
|
||||
size_t maxentries = maxEntries(count);
|
||||
if ((int)(maxentries - mColumns) >= 0)
|
||||
{
|
||||
if (mIndex <= maxentries - mColumns)
|
||||
{
|
||||
mIndex += mColumns;
|
||||
}
|
||||
else if (mIndex >= maxentries - mColumns + 1)
|
||||
{
|
||||
// store the old maxentries value to use later
|
||||
maxentries = maxEntries(count);
|
||||
// change page
|
||||
page_forward();
|
||||
// we need to setup the index to be on a new row: quantize the row and evaluate it
|
||||
mIndex = (mIndex + mColumns) % (size_t)(floor(maxentries / mColumns) * mColumns + mColumns);
|
||||
// in case rows are not full of icons, handle possible overflows
|
||||
if (mIndex > maxEntries(count))
|
||||
{
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kHeld & _KEY_UP())
|
||||
{
|
||||
if (mIndex > 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else if (mIndex == 0)
|
||||
{
|
||||
page_back();
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_DOWN())
|
||||
{
|
||||
if (mIndex < maxEntries(count))
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
else if (mIndex == maxEntries(count))
|
||||
{
|
||||
page_forward();
|
||||
mIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -43,6 +43,7 @@ public:
|
|||
mMaxPages = 0;
|
||||
mCurrentTime = 0;
|
||||
mLastTime = 0;
|
||||
mDelayTicks = 1e10;
|
||||
}
|
||||
|
||||
virtual ~IHid(void) { }
|
||||
|
@ -55,14 +56,15 @@ public:
|
|||
int page(void);
|
||||
void page(int v);
|
||||
void reset(void);
|
||||
void update(size_t count);
|
||||
|
||||
protected:
|
||||
void page_back(void);
|
||||
void page_forward(void);
|
||||
void page_back(void);
|
||||
void page_forward(void);
|
||||
virtual void update(size_t count) = 0;
|
||||
|
||||
virtual u64 down(void) = 0;
|
||||
virtual u64 held(void) = 0;
|
||||
virtual u64 tick(void) = 0;
|
||||
virtual u64 _KEY_ZL(void) = 0;
|
||||
virtual u64 _KEY_ZR(void) = 0;
|
||||
virtual u64 _KEY_LEFT(void) = 0;
|
||||
|
@ -77,6 +79,29 @@ protected:
|
|||
size_t mColumns;
|
||||
u64 mCurrentTime;
|
||||
u64 mLastTime;
|
||||
u64 mDelayTicks;
|
||||
};
|
||||
|
||||
class IHidVertical : public IHid
|
||||
{
|
||||
public:
|
||||
IHidVertical(size_t entries, size_t columns)
|
||||
: IHid(entries, columns) { }
|
||||
|
||||
virtual ~IHidVertical(void) { }
|
||||
|
||||
void update(size_t count) override;
|
||||
};
|
||||
|
||||
class IHidHorizontal : public IHid
|
||||
{
|
||||
public:
|
||||
IHidHorizontal(size_t entries, size_t columns)
|
||||
: IHid(entries, columns) { }
|
||||
|
||||
virtual ~IHidHorizontal(void) { }
|
||||
|
||||
void update(size_t count) override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
245
common/ihidhorizontal.cpp
Normal file
245
common/ihidhorizontal.cpp
Normal file
|
@ -0,0 +1,245 @@
|
|||
/*
|
||||
* This file is part of Checkpoint
|
||||
* Copyright (C) 2017-2018 Bernardo Giordano
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "ihid.hpp"
|
||||
|
||||
void IHidHorizontal::update(size_t count)
|
||||
{
|
||||
mCurrentTime = tick();
|
||||
size_t rows = mMaxVisibleEntries / mColumns;
|
||||
mMaxPages = (count % mMaxVisibleEntries == 0) ? count / mMaxVisibleEntries : count / mMaxVisibleEntries + 1;
|
||||
u64 kHeld = held();
|
||||
u64 kDown = down();
|
||||
|
||||
if (kDown & _KEY_ZL())
|
||||
{
|
||||
page_back();
|
||||
if (mIndex > maxEntries(count))
|
||||
{
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_ZR())
|
||||
{
|
||||
page_forward();
|
||||
if (mIndex > maxEntries(count))
|
||||
{
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (mColumns > 1)
|
||||
{
|
||||
if (kDown & _KEY_LEFT())
|
||||
{
|
||||
if (mIndex % mColumns != 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else
|
||||
{
|
||||
page_back();
|
||||
mIndex += mColumns - 1;
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_RIGHT())
|
||||
{
|
||||
if (mIndex % mColumns != mColumns - 1)
|
||||
{
|
||||
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
|
||||
{
|
||||
page_forward();
|
||||
mIndex = (mIndex / mColumns) * mColumns;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
page_forward();
|
||||
mIndex -= mColumns - 1;
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_UP())
|
||||
{
|
||||
if (mIndex < mColumns)
|
||||
{
|
||||
mIndex += mColumns * (rows - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex -= mColumns;
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_DOWN())
|
||||
{
|
||||
if (mIndex >= mColumns * (rows - 1))
|
||||
{
|
||||
mIndex -= mColumns * (rows - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex += mColumns;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_LEFT())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex % mColumns != 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else
|
||||
{
|
||||
page_back();
|
||||
mIndex += mColumns - 1;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_RIGHT())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex % mColumns != mColumns - 1)
|
||||
{
|
||||
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
|
||||
{
|
||||
page_forward();
|
||||
mIndex = (mIndex / mColumns) * mColumns;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
page_forward();
|
||||
mIndex -= mColumns - 1;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_UP())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex < mColumns)
|
||||
{
|
||||
mIndex += mColumns * (rows - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex -= mColumns;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_DOWN())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex >= mColumns * (rows - 1))
|
||||
{
|
||||
mIndex -= mColumns * (rows - 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex += mColumns;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (kDown & _KEY_UP())
|
||||
{
|
||||
if (mIndex > 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else if (mIndex == 0)
|
||||
{
|
||||
page_back();
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_DOWN())
|
||||
{
|
||||
if (mIndex < maxEntries(count))
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
else if (mIndex == maxEntries(count))
|
||||
{
|
||||
page_forward();
|
||||
mIndex = 0;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_UP())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex > 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else if (mIndex == 0)
|
||||
{
|
||||
page_back();
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_DOWN())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex < maxEntries(count))
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
else if (mIndex == maxEntries(count))
|
||||
{
|
||||
page_forward();
|
||||
mIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mIndex > maxEntries(count))
|
||||
{
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
mLastTime = mCurrentTime;
|
||||
}
|
244
common/ihidvertical.cpp
Normal file
244
common/ihidvertical.cpp
Normal file
|
@ -0,0 +1,244 @@
|
|||
/*
|
||||
* This file is part of Checkpoint
|
||||
* Copyright (C) 2017-2018 Bernardo Giordano
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||
* * Requiring preservation of specified reasonable legal notices or
|
||||
* author attributions in that material or in the Appropriate Legal
|
||||
* Notices displayed by works containing it.
|
||||
* * Prohibiting misrepresentation of the origin of that material,
|
||||
* or requiring that modified versions of such material be marked in
|
||||
* reasonable ways as different from the original version.
|
||||
*/
|
||||
|
||||
#include "ihid.hpp"
|
||||
|
||||
void IHidVertical::update(size_t count)
|
||||
{
|
||||
mCurrentTime = tick();
|
||||
size_t rows = mMaxVisibleEntries / mColumns;
|
||||
mMaxPages = (count % mMaxVisibleEntries == 0) ? count / mMaxVisibleEntries : count / mMaxVisibleEntries + 1;
|
||||
u64 kHeld = held();
|
||||
u64 kDown = down();
|
||||
|
||||
if (kDown & _KEY_ZL())
|
||||
{
|
||||
page_back();
|
||||
}
|
||||
else if (kDown & _KEY_ZR())
|
||||
{
|
||||
page_forward();
|
||||
}
|
||||
else if (mColumns > 1)
|
||||
{
|
||||
if (kDown & _KEY_LEFT())
|
||||
{
|
||||
if (mIndex % rows != mIndex)
|
||||
{
|
||||
mIndex -= rows;
|
||||
}
|
||||
else
|
||||
{
|
||||
page_back();
|
||||
mIndex += rows;
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_RIGHT())
|
||||
{
|
||||
if (maxEntries(count) < rows)
|
||||
{
|
||||
page_forward();
|
||||
}
|
||||
else if (mIndex + rows < mMaxVisibleEntries)
|
||||
{
|
||||
mIndex += rows;
|
||||
}
|
||||
else
|
||||
{
|
||||
page_forward();
|
||||
mIndex -= rows;
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_UP())
|
||||
{
|
||||
if (mIndex % rows > 0)
|
||||
{
|
||||
mIndex -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex = mIndex == rows ? mMaxVisibleEntries - 1 : ((mMaxVisibleEntries - 1) % rows);
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_DOWN())
|
||||
{
|
||||
if ((mIndex % rows) < rows - 1)
|
||||
{
|
||||
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
|
||||
{
|
||||
mIndex = (mIndex / rows) * rows;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex = mIndex == rows - 1 ? 0 : rows;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_LEFT())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex % rows != mIndex)
|
||||
{
|
||||
mIndex -= rows;
|
||||
}
|
||||
else
|
||||
{
|
||||
page_back();
|
||||
mIndex += rows;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_RIGHT())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (maxEntries(count) < rows)
|
||||
{
|
||||
page_forward();
|
||||
}
|
||||
else if (mIndex + rows < mMaxVisibleEntries)
|
||||
{
|
||||
mIndex += rows;
|
||||
}
|
||||
else
|
||||
{
|
||||
page_forward();
|
||||
mIndex -= rows;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_UP())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex % rows > 0)
|
||||
{
|
||||
mIndex -= 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex = mIndex == rows ? mMaxVisibleEntries - 1 : ((mMaxVisibleEntries - 1) % rows);
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_DOWN())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if ((mIndex % rows) < rows - 1)
|
||||
{
|
||||
if (mIndex + mPage * mMaxVisibleEntries == count - 1)
|
||||
{
|
||||
mIndex = (mIndex / rows) * rows;
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex += 1;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
mIndex = mIndex == rows - 1 ? 0 : rows;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
if (kDown & _KEY_UP())
|
||||
{
|
||||
if (mIndex > 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else if (mIndex == 0)
|
||||
{
|
||||
page_back();
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kDown & _KEY_DOWN())
|
||||
{
|
||||
if (mIndex < maxEntries(count))
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
else if (mIndex == maxEntries(count))
|
||||
{
|
||||
page_forward();
|
||||
mIndex = 0;
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_UP())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex > 0)
|
||||
{
|
||||
mIndex--;
|
||||
}
|
||||
else if (mIndex == 0)
|
||||
{
|
||||
page_back();
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
}
|
||||
else if (kHeld & _KEY_DOWN())
|
||||
{
|
||||
if (mCurrentTime <= mLastTime + mDelayTicks)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (mIndex < maxEntries(count))
|
||||
{
|
||||
mIndex++;
|
||||
}
|
||||
else if (mIndex == maxEntries(count))
|
||||
{
|
||||
page_forward();
|
||||
mIndex = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (mIndex > maxEntries(count))
|
||||
{
|
||||
mIndex = maxEntries(count);
|
||||
}
|
||||
mLastTime = mCurrentTime;
|
||||
}
|
|
@ -30,15 +30,13 @@
|
|||
#include <switch.h>
|
||||
#include "ihid.hpp"
|
||||
|
||||
#define DELAY_TICKS 2500000
|
||||
|
||||
class Hid : public IHid
|
||||
class HidVertical : public IHidVertical
|
||||
{
|
||||
public:
|
||||
Hid(size_t entries, size_t columns)
|
||||
: IHid(entries, columns) { }
|
||||
HidVertical(size_t entries, size_t columns)
|
||||
: IHidVertical(entries, columns) { mDelayTicks = 2500000; }
|
||||
|
||||
virtual ~Hid(void) { }
|
||||
virtual ~HidVertical(void) { }
|
||||
|
||||
u64 down(void) override
|
||||
{
|
||||
|
@ -50,14 +48,40 @@ public:
|
|||
return hidKeysHeld(CONTROLLER_P1_AUTO);
|
||||
}
|
||||
|
||||
void update(size_t count)
|
||||
u64 tick(void) override
|
||||
{
|
||||
mCurrentTime = armGetSystemTick();
|
||||
if ((mCurrentTime > mLastTime + DELAY_TICKS))
|
||||
{
|
||||
IHid::update(count);
|
||||
mLastTime = mCurrentTime;
|
||||
}
|
||||
return armGetSystemTick();
|
||||
}
|
||||
|
||||
u64 _KEY_ZL(void) override { return 0; }
|
||||
u64 _KEY_ZR(void) override { return 0; }
|
||||
u64 _KEY_LEFT(void) override { return KEY_LEFT; }
|
||||
u64 _KEY_RIGHT(void) override { return KEY_RIGHT; }
|
||||
u64 _KEY_UP(void) override { return KEY_UP; }
|
||||
u64 _KEY_DOWN(void) override { return KEY_DOWN; }
|
||||
};
|
||||
|
||||
class HidHorizontal : public IHidHorizontal
|
||||
{
|
||||
public:
|
||||
HidHorizontal(size_t entries, size_t columns)
|
||||
: IHidHorizontal(entries, columns) { mDelayTicks = 2500000; }
|
||||
|
||||
virtual ~HidHorizontal(void) { }
|
||||
|
||||
u64 down(void) override
|
||||
{
|
||||
return hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
}
|
||||
|
||||
u64 held(void) override
|
||||
{
|
||||
return hidKeysHeld(CONTROLLER_P1_AUTO);
|
||||
}
|
||||
|
||||
u64 tick(void) override
|
||||
{
|
||||
return armGetSystemTick();
|
||||
}
|
||||
|
||||
u64 _KEY_ZL(void) override { return 0; }
|
||||
|
|
|
@ -41,7 +41,7 @@ public:
|
|||
Scrollable(u32 x, u32 y, u32 w, u32 h, size_t visibleEntries)
|
||||
: IScrollable(x, y, w, h, visibleEntries)
|
||||
{
|
||||
mHid = new Hid(visibleEntries, 1);
|
||||
mHid = new HidVertical(visibleEntries, 1);
|
||||
}
|
||||
|
||||
virtual ~Scrollable(void)
|
||||
|
@ -56,7 +56,7 @@ public:
|
|||
void updateSelection(void) override;
|
||||
|
||||
protected:
|
||||
Hid* mHid;
|
||||
HidVertical* mHid;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -37,7 +37,7 @@ static const size_t rowlen = 5;
|
|||
static const size_t collen = 4;
|
||||
static const size_t cols = 6;
|
||||
static bool backupScrollEnabled;
|
||||
static Hid* hid;
|
||||
static HidHorizontal* hid;
|
||||
static entryType_t type;
|
||||
|
||||
static float currentTime = 0;
|
||||
|
@ -245,7 +245,7 @@ bool Gui::init(void)
|
|||
backupScrollEnabled = false;
|
||||
info = new Info();
|
||||
info->init("", "", 0, TYPE_INFO);
|
||||
hid = new Hid(rowlen * collen, collen);
|
||||
hid = new HidHorizontal(rowlen * collen, collen);
|
||||
backupList = new Scrollable(540, 462, 506, 222, cols);
|
||||
buttonBackup = new Clickable(1050, 462, 220, 109, COLOR_WHITE, COLOR_GREY_LIGHT, "Backup \ue004", true);
|
||||
buttonRestore = new Clickable(1050, 575, 220, 109, COLOR_WHITE, COLOR_GREY_LIGHT, "Restore \ue005", true);
|
||||
|
|
Loading…
Reference in a new issue