finish touch hid rewrite for switch + bonuses

make empty destructors default, same effect. do we even need to define them?
Fix uses platform dependent header files defining what gets passed to the different update functions
All "fix me"s eradicated
needs testing to ensure nothing broke
This commit is contained in:
LiquidFenrir 2021-04-18 16:18:03 +02:00
parent 85fa31e842
commit 98f020f7fe
38 changed files with 238 additions and 194 deletions

View file

@ -45,7 +45,7 @@ public:
~CheatManagerOverlay(void);
void drawTop(void) const override;
void drawBottom(void) const override;
void update(touchPosition* touch) override;
void update(TouchScreen* touch) override;
protected:
void save(const std::string& key, Scrollable* s);

View file

@ -43,7 +43,7 @@ public:
~ErrorOverlay(void);
void drawTop(void) const override;
void drawBottom(void) const override;
void update(touchPosition* touch) override;
void update(TouchScreen* touch) override;
private:
u32 posx, posy;

View file

@ -43,7 +43,7 @@ public:
~InfoOverlay(void);
void drawTop(void) const override;
void drawBottom(void) const override;
void update(touchPosition* touch) override;
void update(TouchScreen* touch) override;
private:
u32 posx, posy;

View file

@ -46,7 +46,7 @@ public:
~MainScreen(void);
void drawTop(void) const override;
void drawBottom(void) const override;
void update(touchPosition* touch) override;
void update(TouchScreen* touch) override;
protected:
int selectorX(size_t i) const;

View file

@ -0,0 +1,34 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* 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.
*/
#ifndef TOUCHSCREEN_HPP
#define TOUCHSCREEN_HPP
#include <3ds.h>
using TouchScreen = touchPosition;
#endif

View file

@ -44,7 +44,7 @@ public:
~YesNoOverlay(void);
void drawTop(void) const override;
void drawBottom(void) const override;
void update(touchPosition* touch) override;
void update(TouchScreen* touch) override;
private:
u32 posx, posy;

View file

@ -52,7 +52,7 @@ public:
private:
CheatManager(void);
~CheatManager(void){};
~CheatManager() = default;
CheatManager(CheatManager const&) = delete;
void operator=(CheatManager const&) = delete;

View file

@ -53,7 +53,7 @@ public:
private:
Configuration(void);
~Configuration(void){};
~Configuration() = default;
void store(void);
nlohmann::json loadJson(const std::string& path);

View file

@ -35,7 +35,7 @@
class Directory {
public:
Directory(FS_Archive archive, const std::u16string& root);
~Directory(void){};
~Directory() = default;
Result error(void);
std::u16string entry(size_t index);

View file

@ -34,7 +34,7 @@ class FSStream {
public:
FSStream(FS_Archive archive, const std::u16string& path, u32 flags);
FSStream(FS_Archive archive, const std::u16string& path, u32 flags, u32 size);
~FSStream(void){};
~FSStream() = default;
Result close(void);
bool eof(void);

View file

@ -90,7 +90,7 @@ void CheatManagerOverlay::drawBottom(void) const
C2D_DrawRectSolid(0, 0, 0.5f, 320, 240, COLOR_OVERLAY);
}
void CheatManagerOverlay::update(touchPosition* touch)
void CheatManagerOverlay::update(TouchScreen* touch)
{
if (hidKeysDown() & KEY_A) {
std::string cellName = scrollable->cellName(scrollable->index());

View file

@ -61,7 +61,7 @@ void ErrorOverlay::drawBottom(void) const
Gui::drawPulsingOutline(42, 162, 236, 36, 2, COLOR_RED);
}
void ErrorOverlay::update(touchPosition* touch)
void ErrorOverlay::update(TouchScreen* touch)
{
if (button->released() || (hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_B)) {
screen.removeOverlay();

View file

@ -57,7 +57,7 @@ void InfoOverlay::drawBottom(void) const
Gui::drawPulsingOutline(42, 162, 236, 36, 2, COLOR_BLUE);
}
void InfoOverlay::update(touchPosition* touch)
void InfoOverlay::update(TouchScreen* touch)
{
if (button->released() || (hidKeysDown() & KEY_A) || (hidKeysDown() & KEY_B)) {
screen.removeOverlay();

View file

@ -264,7 +264,7 @@ void MainScreen::drawBottom(void) const
}
}
void MainScreen::update(touchPosition* touch)
void MainScreen::update(TouchScreen* touch)
{
updateSelector();
handleEvents(touch);

View file

@ -72,7 +72,7 @@ void YesNoOverlay::drawBottom(void) const
}
}
void YesNoOverlay::update(touchPosition* touch)
void YesNoOverlay::update(TouchScreen* touch)
{
hid.update(2);

View file

@ -29,18 +29,12 @@
#include "Screen.hpp"
#include <memory>
#include <string>
#if defined(_3DS)
#include <3ds.h>
#elif defined(__SWITCH__)
#include <switch.h>
#endif
class Overlay {
public:
Overlay(Screen& screen) : screen(screen), me(screen.currentOverlay) {}
virtual ~Overlay() {}
virtual void update(PadState*) = 0;
virtual ~Overlay() = default;
virtual void update(TouchScreen*) = 0;
#if defined(_3DS)
virtual void drawTop() const = 0;
virtual void drawBottom() const = 0;

View file

@ -44,17 +44,6 @@ void Screen::doDrawBottom() const
currentOverlay->drawBottom();
}
}
void Screen::doUpdate(touchPosition* touch)
{
if (currentOverlay) {
currentOverlay->update(touch);
}
else {
update(touch);
}
}
#elif defined(__SWITCH__)
void Screen::doDraw() const
@ -65,14 +54,14 @@ void Screen::doDraw() const
}
}
void Screen::doUpdate(PadState* pad)
#endif
void Screen::doUpdate(TouchScreen* touch)
{
if (currentOverlay) {
currentOverlay->update(pad);
currentOverlay->update(touch);
}
else {
update(pad);
update(touch);
}
}
#endif

View file

@ -27,11 +27,7 @@
#ifndef SCREEN_HPP
#define SCREEN_HPP
#if defined(_3DS)
#include <3ds.h>
#elif defined(__SWITCH__)
#include <switch.h>
#endif
#include "TouchScreen.hpp"
#include <memory>
class Overlay;
@ -40,31 +36,27 @@ class Screen {
friend class Overlay;
public:
Screen(void) {}
virtual ~Screen(void) {}
virtual ~Screen() = default;
// Call draw, then currentOverlay->draw if it exists
#if defined(_3DS)
virtual void doDrawTop(void) const final;
virtual void doDrawBottom(void) const final;
void doDrawTop(void) const;
void doDrawBottom(void) const;
virtual void drawTop(void) const = 0;
virtual void drawBottom(void) const = 0;
// Call currentOverlay->update if it exists, and update if it doesn't
virtual void doUpdate(touchPosition*) final;
virtual void update(touchPosition*) = 0;
#elif defined(__SWITCH__)
virtual void doDraw() const final;
void doDraw() const;
virtual void draw() const = 0;
// Call currentOverlay->update if it exists, and update if it doesn't
virtual void doUpdate(PadState*) final;
virtual void update(PadState*) = 0;
#endif
void removeOverlay() { currentOverlay = nullptr; }
// Call currentOverlay->update if it exists, and update if it doesn't
void doUpdate(TouchScreen*);
virtual void update(TouchScreen*) = 0;
void removeOverlay() { currentOverlay.reset(); }
void setOverlay(std::shared_ptr<Overlay>& overlay) { currentOverlay = overlay; }
protected:
// No point in restricting this to only being editable during update, especially since it's drawn afterwards. Allows setting it before the first
// draw loop is done
mutable std::shared_ptr<Overlay> currentOverlay = nullptr;
mutable std::shared_ptr<Overlay> currentOverlay;
};
#endif

View file

@ -46,7 +46,7 @@ public:
CheatManagerOverlay(Screen& screen, const std::string& mtext);
~CheatManagerOverlay(void) {}
void draw(void) const override;
void update(PadState*) override;
void update(TouchScreen*) override;
protected:
void save(const std::string& key, Scrollable* s);

View file

@ -41,7 +41,7 @@ public:
ErrorOverlay(Screen& screen, Result res, const std::string& mtext);
~ErrorOverlay(void) {}
void draw(void) const override;
void update(PadState*) override;
void update(TouchScreen*) override;
private:
u32 textw, texth;

View file

@ -41,7 +41,7 @@ public:
InfoOverlay(Screen& screen, const std::string& mtext);
~InfoOverlay(void) {}
void draw(void) const override;
void update(PadState* touch) override;
void update(TouchScreen* touch) override;
private:
u32 textw, texth;

View file

@ -50,7 +50,7 @@ public:
private:
KeyboardManager(void);
virtual ~KeyboardManager(void){};
virtual ~KeyboardManager() = default;
Result res;
bool systemKeyboardAvailable;

View file

@ -48,16 +48,15 @@ class Scrollable;
class MainScreen : public Screen {
public:
MainScreen(void);
MainScreen(PadState*);
MainScreen(TouchScreen*);
void draw(void) const override;
void update(PadState* pad) override;
void update(TouchScreen* pad) override;
protected:
int selectorX(size_t i) const;
int selectorY(size_t i) const;
void updateSelector(PadState* pad);
void handleEvents(PadState* pad);
void updateSelector(TouchScreen* pad);
void handleEvents(TouchScreen* pad);
std::string nameFromCell(size_t index) const;
void entryType(entryType_t type);
size_t index(entryType_t type) const;
@ -72,6 +71,7 @@ private:
entryType_t type;
int selectionTimer;
bool pksmBridge;
bool wantInstructions;
Hid<HidDirection::HORIZONTAL, HidDirection::HORIZONTAL> hid;
std::unique_ptr<Scrollable> backupList;
std::unique_ptr<Clickable> buttonCheats, buttonBackup, buttonRestore;

View file

@ -0,0 +1,34 @@
/*
* This file is part of Checkpoint
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
*
* 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.
*/
#ifndef TOUCHSCREEN_HPP
#define TOUCHSCREEN_HPP
#include <switch.h>
struct TouchScreen : public HidTouchScreenState, public PadState { };
#endif

View file

@ -43,7 +43,7 @@ public:
YesNoOverlay(Screen& screen, const std::string& mtext, const std::function<void()>& callbackYes, const std::function<void()>& callbackNo);
~YesNoOverlay(void) {}
void draw(void) const override;
void update(PadState*) override;
void update(TouchScreen*) override;
private:
u32 textw, texth;

View file

@ -54,7 +54,7 @@ public:
private:
CheatManager(void);
~CheatManager(void){};
~CheatManager() = default;
CheatManager(CheatManager const&) = delete;
void operator=(CheatManager const&) = delete;

View file

@ -39,11 +39,11 @@ public:
: IClickable(x, y, w, h, colorBg, colorText, message, centered)
{
}
virtual ~Clickable(void){};
virtual ~Clickable() = default;
void draw(float font, SDL_Color overlay) override;
bool held(void) override;
bool released(void) override;
bool held() override;
bool released() override;
void drawOutline(SDL_Color color) override;
};

View file

@ -41,7 +41,7 @@ struct DirectoryEntry {
class Directory {
public:
Directory(const std::string& root);
~Directory(void){};
~Directory() = default;
Result error(void);
std::string entry(size_t index);

View file

@ -49,15 +49,15 @@ private:
bool upDown() const override { return padGetButtonsDown(pad) & HidNpadButton_Up; }
bool leftDown() const override { return padGetButtonsDown(pad) & HidNpadButton_Left; }
bool rightDown() const override { return padGetButtonsDown(pad) & HidNpadButton_Right; }
// TODO: fix me
bool leftTriggerDown() const override { return false; }
bool rightTriggerDown() const override { return false; }
bool downHeld() const override { return false; }
bool upHeld() const override { return false; }
bool leftHeld() const override { return false; }
bool rightHeld() const override { return false; }
bool leftTriggerHeld() const override { return false; }
bool rightTriggerHeld() const override { return false; }
bool leftTriggerDown() const override { return padGetButtonsDown(pad) & HidNpadButton_L; }
bool rightTriggerDown() const override { return padGetButtonsDown(pad) & HidNpadButton_R; }
bool downHeld() const override { return padGetButtons(pad) & HidNpadButton_Down; }
bool upHeld() const override { return padGetButtons(pad) & HidNpadButton_Up; }
bool leftHeld() const override { return padGetButtons(pad) & HidNpadButton_Left; }
bool rightHeld() const override { return padGetButtons(pad) & HidNpadButton_Right; }
bool leftTriggerHeld() const override { return padGetButtons(pad) & HidNpadButton_L; }
bool rightTriggerHeld() const override { return padGetButtons(pad) & HidNpadButton_R; }
u64 tick() const override { return armGetSystemTick(); }
};

View file

@ -43,7 +43,7 @@
class Title {
public:
void init(u8 saveDataType, u64 titleid, AccountUid userID, const std::string& name, const std::string& author);
~Title(void){};
~Title() = default;
std::string author(void);
std::pair<std::string, std::string> displayName(void);

View file

@ -83,7 +83,7 @@ void CheatManagerOverlay::draw(void) const
20, 94, ceilf(664 + (32 - height) / 2), COLOR_WHITE, multiSelected ? "\ue003 to deselect all cheats" : "\ue003 to select all cheats");
}
void CheatManagerOverlay::update(PadState* pad)
void CheatManagerOverlay::update(TouchScreen* pad)
{
u64 kDown = padGetButtonsDown(pad);
if (kDown & HidNpadButton_A) {

View file

@ -45,7 +45,7 @@ void ErrorOverlay::draw(void) const
drawPulsingOutline(322, 462, 636, 56, 4, COLOR_RED);
}
void ErrorOverlay::update(PadState* pad)
void ErrorOverlay::update(TouchScreen* pad)
{
u64 kDown = padGetButtonsDown(pad);
if (button->released() || (kDown & HidNpadButton_A) || (kDown & HidNpadButton_B)) {

View file

@ -43,7 +43,7 @@ void InfoOverlay::draw(void) const
drawPulsingOutline(322, 462, 636, 56, 4, COLOR_BLUE);
}
void InfoOverlay::update(PadState* pad)
void InfoOverlay::update(TouchScreen* pad)
{
u64 kDown = padGetButtonsDown(pad);
if (button->released() || (kDown & HidNpadButton_A) || (kDown & HidNpadButton_B)) {

View file

@ -28,10 +28,11 @@
static constexpr size_t rowlen = 5, collen = 4, rows = 10, SIDEBAR_w = 96;
MainScreen::MainScreen(PadState* pad) : hid(rowlen * collen, collen, pad)
MainScreen::MainScreen(TouchScreen* pad) : hid(rowlen * collen, collen, pad)
{
pksmBridge = false;
selectionTimer = 0;
pksmBridge = false;
wantInstructions = false;
selectionTimer = 0;
sprintf(ver, "v%d.%d.%d", VERSION_MAJOR, VERSION_MINOR, VERSION_MICRO);
backupList = std::make_unique<Scrollable>(538, 276, 414, 380, rows);
buttonBackup = std::make_unique<Clickable>(956, 276, 220, 80, theme().c2, theme().c6, "Backup \ue004", true);
@ -183,32 +184,31 @@ void MainScreen::draw() const
SDLH_GetTextDimensions(26, "checkpoint", &checkpoint_w, &checkpoint_h);
SDLH_GetTextDimensions(24, "\ue046 Instructions", &inst_w, &inst_h);
// TODO: fix me
// if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_MINUS && currentOverlay == nullptr) {
// SDLH_DrawRect(0, 0, 1280, 720, COLOR_OVERLAY);
// SDLH_DrawText(27, 1205, 646, theme().c6, "\ue085\ue086");
// SDLH_DrawText(24, 58, 69, theme().c6, "\ue058 Tap to select title");
// SDLH_DrawText(24, 58, 109, theme().c6, ("\ue026 Sort: " + sortMode()).c_str());
// SDLH_DrawText(24, 100, 270, theme().c6, "\ue006 \ue080 to scroll between titles");
// SDLH_DrawText(24, 100, 300, theme().c6, "\ue004 \ue005 to scroll between pages");
// SDLH_DrawText(24, 100, 330, theme().c6, "\ue000 to enter the selected title");
// SDLH_DrawText(24, 100, 360, theme().c6, "\ue001 to exit the selected title");
// SDLH_DrawText(24, 100, 390, theme().c6, "\ue002 to change sort mode");
// SDLH_DrawText(24, 100, 420, theme().c6, "\ue003 to multiselect title");
// SDLH_DrawText(24, 100, 450, theme().c6, "Hold \ue003 to select all titles");
// SDLH_DrawText(24, 616, 480, theme().c6, "\ue002 to delete a backup");
// if (Configuration::getInstance().isPKSMBridgeEnabled()) {
// SDLH_DrawText(24, 100, 480, theme().c6, "\ue004 + \ue005 to enable PKSM bridge");
// }
// if (gethostid() != INADDR_LOOPBACK) {
// if (g_ftpAvailable && Configuration::getInstance().isFTPEnabled()) {
// SDLH_DrawText(24, 16 * 6 + checkpoint_w + 8 + ver_w + inst_w, 642 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, COLOR_GOLD,
// StringUtils::format("FTP server running on %s:50000", getConsoleIP()).c_str());
// }
// SDLH_DrawText(24, 16 * 6 + checkpoint_w + 8 + ver_w + inst_w, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, COLOR_GOLD,
// StringUtils::format("Configuration server running on %s:8000", getConsoleIP()).c_str());
// }
// }
if (wantInstructions && currentOverlay == nullptr) {
SDLH_DrawRect(0, 0, 1280, 720, COLOR_OVERLAY);
SDLH_DrawText(27, 1205, 646, theme().c6, "\ue085\ue086");
SDLH_DrawText(24, 58, 69, theme().c6, "\ue058 Tap to select title");
SDLH_DrawText(24, 58, 109, theme().c6, ("\ue026 Sort: " + sortMode()).c_str());
SDLH_DrawText(24, 100, 270, theme().c6, "\ue006 \ue080 to scroll between titles");
SDLH_DrawText(24, 100, 300, theme().c6, "\ue004 \ue005 to scroll between pages");
SDLH_DrawText(24, 100, 330, theme().c6, "\ue000 to enter the selected title");
SDLH_DrawText(24, 100, 360, theme().c6, "\ue001 to exit the selected title");
SDLH_DrawText(24, 100, 390, theme().c6, "\ue002 to change sort mode");
SDLH_DrawText(24, 100, 420, theme().c6, "\ue003 to multiselect title");
SDLH_DrawText(24, 100, 450, theme().c6, "Hold \ue003 to select all titles");
SDLH_DrawText(24, 616, 480, theme().c6, "\ue002 to delete a backup");
if (Configuration::getInstance().isPKSMBridgeEnabled()) {
SDLH_DrawText(24, 100, 480, theme().c6, "\ue004 + \ue005 to enable PKSM bridge");
}
if (gethostid() != INADDR_LOOPBACK) {
if (g_ftpAvailable && Configuration::getInstance().isFTPEnabled()) {
SDLH_DrawText(24, 16 * 6 + checkpoint_w + 8 + ver_w + inst_w, 642 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, COLOR_GOLD,
StringUtils::format("FTP server running on %s:50000", getConsoleIP()).c_str());
}
SDLH_DrawText(24, 16 * 6 + checkpoint_w + 8 + ver_w + inst_w, 672 + (40 - checkpoint_h) / 2 + checkpoint_h - inst_h, COLOR_GOLD,
StringUtils::format("Configuration server running on %s:8000", getConsoleIP()).c_str());
}
}
SDLH_DrawRect(0, 672, checkpoint_w + ver_w + 2 * 16 + 8, 40, lightBlack);
SDLH_DrawText(26, 16, 672 + (40 - checkpoint_h) / 2 + 2, theme().c6, "checkpoint");
@ -224,13 +224,13 @@ void MainScreen::draw() const
}
}
void MainScreen::update(PadState* pad)
void MainScreen::update(TouchScreen* pad)
{
updateSelector(pad);
handleEvents(pad);
}
void MainScreen::updateSelector(PadState* pad)
void MainScreen::updateSelector(TouchScreen* pad)
{
if (!g_backupScrollEnabled) {
size_t count = getTitleCount(g_currentUId);
@ -246,10 +246,9 @@ void MainScreen::updateSelector(PadState* pad)
u32 x = selectorX(index);
u32 y = selectorY(index);
// TODO: FIX ME
// if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH && touch->px >= x && touch->px <= x + 128 && touch->py >= y && touch->py <= y + 128) {
// hid.index(index);
// }
if (pad->count > 0 && pad->touches[0].x >= x && pad->touches[0].x <= x + 128 && pad->touches[0].y >= y && pad->touches[0].y <= y + 128) {
hid.index(index);
}
}
}
@ -263,12 +262,13 @@ void MainScreen::updateSelector(PadState* pad)
}
}
void MainScreen::handleEvents(PadState* pad)
void MainScreen::handleEvents(TouchScreen* pad)
{
// TODO: fix me
// u32 kheld = padGetButtonsHeld(&pad);
const u64 kheld = padGetButtons(pad);
const u64 kdown = padGetButtonsDown(pad);
wantInstructions = (kheld & HidNpadButton_Minus);
u32 kdown = padGetButtonsDown(pad);
if (kdown & HidNpadButton_ZL || kdown & HidNpadButton_ZR) {
while ((g_currentUId = Account::selectAccount()) == 0)
;
@ -281,34 +281,33 @@ void MainScreen::handleEvents(PadState* pad)
Title title;
getTitle(title, g_currentUId, this->index(TITLES));
if (!getPKSMBridgeFlag()) {
// TODO: fix me
// if ((kheld & HidNpadButton_L) && (kheld & HidNpadButton_R) && isPKSMBridgeTitle(title.id())) {
// setPKSMBridgeFlag(true);
// updateButtons();
// }
if ((kheld & HidNpadButton_L) && (kheld & HidNpadButton_R) && isPKSMBridgeTitle(title.id())) {
setPKSMBridgeFlag(true);
updateButtons();
}
}
}
// // handle touchscreen
// if (!g_backupScrollEnabled && hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH && touch->px >= 1200 && touch->px <= 1200 + USER_ICON_SIZE &&
// touch->py >= 626 && touch->py <= 626 + USER_ICON_SIZE) {
// while ((g_currentUId = Account::selectAccount()) == 0)
// ;
// this->index(TITLES, 0);
// this->index(CELLS, 0);
// setPKSMBridgeFlag(false);
// }
// handle touchscreen
if (!g_backupScrollEnabled && pad->count > 0 && pad->touches[0].x >= 1200 && pad->touches[0].x <= 1200 + USER_ICON_SIZE &&
pad->touches[0].y >= 626 && pad->touches[0].y <= 626 + USER_ICON_SIZE) {
while ((g_currentUId = Account::selectAccount()) == 0)
;
this->index(TITLES, 0);
this->index(CELLS, 0);
setPKSMBridgeFlag(false);
}
// // Handle touching the backup list
// if ((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH && (int)touch->px > 538 && (int)touch->px < 952 && (int)touch->py > 276 &&
// (int)touch->py < 656)) {
// // Activate backup list only if multiple selections are enabled
// if (!MS::multipleSelectionEnabled()) {
// g_backupScrollEnabled = true;
// updateButtons();
// entryType(CELLS);
// }
// }
// Handle touching the backup list
if (pad->count > 0 && pad->touches[0].x > 538 && pad->touches[0].x < 952 && pad->touches[0].y > 276 &&
pad->touches[0].y < 656) {
// Activate backup list only if multiple selections are enabled
if (!MS::multipleSelectionEnabled()) {
g_backupScrollEnabled = true;
updateButtons();
entryType(CELLS);
}
}
// Handle pressing A
// Backup list active: Backup/Restore
@ -366,10 +365,8 @@ void MainScreen::handleEvents(PadState* pad)
}
// Handle pressing B
if (kdown & HidNpadButton_B
// || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH && (int)touch->px >= 0 && (int)touch->px <= 532 && (int)touch->py >= 0 &&
// (int)touch->py <= 664)
){
if ((kdown & HidNpadButton_B) || (pad->count > 0 && pad->touches[0].x <= 532 && pad->touches[0].y <= 664))
{
this->index(CELLS, 0);
g_backupScrollEnabled = false;
entryType(TITLES);
@ -417,13 +414,13 @@ void MainScreen::handleEvents(PadState* pad)
updateButtons(); // Do this last
}
// // Handle holding Y
// if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_Y && !(g_backupScrollEnabled)) {
// selectionTimer++;
// }
// else {
// selectionTimer = 0;
// }
// Handle holding Y
if (kheld & KEY_Y && !(g_backupScrollEnabled)) {
selectionTimer++;
}
else {
selectionTimer = 0;
}
if (selectionTimer > 45) {
MS::clearSelectedEntries();

View file

@ -56,7 +56,7 @@ void YesNoOverlay::draw(void) const
}
}
void YesNoOverlay::update(PadState* pad)
void YesNoOverlay::update(TouchScreen* pad)
{
hid.update(2);

View file

@ -28,31 +28,36 @@
bool Clickable::held()
{
// TODO: fix me
// touchPosition touch;
// hidTouchRead(&touch, 0);
// return ((hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH) && (int)touch.px > mx && (int)touch.px < mx + mw && (int)touch.py > my &&
// (int)touch.py < my + mh);
HidTouchScreenState state={0};
if (hidGetTouchScreenStates(&state, 1)) {
return state.count > 0 && state.touches[0].y > (unsigned)my && state.touches[0].y < (unsigned)(my + mh) &&
state.touches[0].x > (unsigned)mx && state.touches[0].x < (unsigned)(mx + mw);
}
return false;
}
bool Clickable::released(void)
bool Clickable::released()
{
// TODO: fix me
// touchPosition touch;
// hidTouchRead(&touch, 0);
// const bool on = (int)touch.px > mx && (int)touch.px < mx + mw && (int)touch.py > my && (int)touch.py < my + mh;
const auto [on, currentlyTouching] = [this]() {
HidTouchScreenState state={0};
if (hidGetTouchScreenStates(&state, 1)) {
return std::make_pair(state.count > 0 && state.touches[0].y > (unsigned)my &&
state.touches[0].y < (unsigned)(my + mh) && state.touches[0].x > (unsigned)mx &&
state.touches[0].x < (unsigned)(mx + mw), true);
}
return std::make_pair(false, false);
}();
// if (on) {
// mOldPressed = true;
// }
// else {
// if (mOldPressed && !(touch.px > 0 || touch.py > 0)) {
// mOldPressed = false;
// return true;
// }
// mOldPressed = false;
// }
if (on) {
mOldPressed = true;
}
else {
if (mOldPressed && !currentlyTouching) {
mOldPressed = false;
return true;
}
mOldPressed = false;
}
return false;
}

View file

@ -48,7 +48,7 @@ int main(void)
exit(res);
}
PadState pad;
TouchScreen pad;
padInitializeDefault(&pad);
g_screen = std::make_unique<MainScreen>(&pad);
@ -72,7 +72,7 @@ int main(void)
if (kDown & HidNpadButton_Plus)
break;
// hidTouchRead(&touch, 0);
hidGetTouchScreenStates(&pad, 1);
g_screen->doDraw();
g_screen->doUpdate(&pad);

View file

@ -54,21 +54,20 @@ void Scrollable::push_back(SDL_Color color, SDL_Color colorMessage, const std::s
void Scrollable::updateSelection(void)
{
// TODO: fix me
// touchPosition touch;
// hidTouchRead(&touch, 0);
const int hu = (mHid.maxEntries(size()) + 1) * mh / mVisibleEntries;
// const int hu = (mHid.maxEntries(size()) + 1) * mh / mVisibleEntries;
// if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH && touch.py > (float)my && touch.py < (float)(my + hu) && touch.px > (float)mx &&
// touch.px < (float)(mx + mw)) {
// mHid.index(ceilf((touch.py - my) * mVisibleEntries / mh));
// }
HidTouchScreenState state={0};
if (hidGetTouchScreenStates(&state, 1)) {
if (state.count > 0 && state.touches[0].y > (float)my && state.touches[0].y < (float)(my + hu) && state.touches[0].x > (float)mx &&
state.touches[0].x < (float)(mx + mw)) {
mHid.index(ceilf((state.touches[0].y - my) * mVisibleEntries / mh));
}
}
// mHid.update(size());
// mIndex = mHid.index();
// mPage = mHid.page();
mHid.update(size());
mIndex = mHid.index();
mPage = mHid.page();
}
void Scrollable::draw(bool condition)