From 98f020f7fecee7ff9a0f6159bba74f23acefc56e Mon Sep 17 00:00:00 2001 From: LiquidFenrir Date: Sun, 18 Apr 2021 16:18:03 +0200 Subject: [PATCH] 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 --- 3ds/include/CheatManagerOverlay.hpp | 2 +- 3ds/include/ErrorOverlay.hpp | 2 +- 3ds/include/InfoOverlay.hpp | 2 +- 3ds/include/MainScreen.hpp | 2 +- 3ds/include/TouchScreen.hpp | 34 ++++++ 3ds/include/YesNoOverlay.hpp | 2 +- 3ds/include/cheatmanager.hpp | 2 +- 3ds/include/configuration.hpp | 2 +- 3ds/include/directory.hpp | 2 +- 3ds/include/fsstream.hpp | 2 +- 3ds/source/CheatManagerOverlay.cpp | 2 +- 3ds/source/ErrorOverlay.cpp | 2 +- 3ds/source/InfoOverlay.cpp | 2 +- 3ds/source/MainScreen.cpp | 2 +- 3ds/source/YesNoOverlay.cpp | 2 +- common/Overlay.hpp | 10 +- common/Screen.cpp | 21 +--- common/Screen.hpp | 28 ++--- switch/include/CheatManagerOverlay.hpp | 2 +- switch/include/ErrorOverlay.hpp | 2 +- switch/include/InfoOverlay.hpp | 2 +- switch/include/KeyboardManager.hpp | 2 +- switch/include/MainScreen.hpp | 10 +- switch/include/TouchScreen.hpp | 34 ++++++ switch/include/YesNoOverlay.hpp | 2 +- switch/include/cheatmanager.hpp | 2 +- switch/include/clickable.hpp | 6 +- switch/include/directory.hpp | 2 +- switch/include/hid.hpp | 18 +-- switch/include/title.hpp | 2 +- switch/source/CheatManagerOverlay.cpp | 2 +- switch/source/ErrorOverlay.cpp | 2 +- switch/source/InfoOverlay.cpp | 2 +- switch/source/MainScreen.cpp | 145 ++++++++++++------------- switch/source/YesNoOverlay.cpp | 2 +- switch/source/clickable.cpp | 45 ++++---- switch/source/main.cpp | 4 +- switch/source/scrollable.cpp | 25 ++--- 38 files changed, 238 insertions(+), 194 deletions(-) create mode 100644 3ds/include/TouchScreen.hpp create mode 100644 switch/include/TouchScreen.hpp diff --git a/3ds/include/CheatManagerOverlay.hpp b/3ds/include/CheatManagerOverlay.hpp index 93a7f36..4db17d0 100644 --- a/3ds/include/CheatManagerOverlay.hpp +++ b/3ds/include/CheatManagerOverlay.hpp @@ -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); diff --git a/3ds/include/ErrorOverlay.hpp b/3ds/include/ErrorOverlay.hpp index 3dd717f..0efe41b 100644 --- a/3ds/include/ErrorOverlay.hpp +++ b/3ds/include/ErrorOverlay.hpp @@ -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; diff --git a/3ds/include/InfoOverlay.hpp b/3ds/include/InfoOverlay.hpp index 2ad06cd..33be098 100644 --- a/3ds/include/InfoOverlay.hpp +++ b/3ds/include/InfoOverlay.hpp @@ -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; diff --git a/3ds/include/MainScreen.hpp b/3ds/include/MainScreen.hpp index f5388eb..94df07f 100644 --- a/3ds/include/MainScreen.hpp +++ b/3ds/include/MainScreen.hpp @@ -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; diff --git a/3ds/include/TouchScreen.hpp b/3ds/include/TouchScreen.hpp new file mode 100644 index 0000000..613367a --- /dev/null +++ b/3ds/include/TouchScreen.hpp @@ -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 . + * + * 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 diff --git a/3ds/include/YesNoOverlay.hpp b/3ds/include/YesNoOverlay.hpp index 02261b3..383c178 100644 --- a/3ds/include/YesNoOverlay.hpp +++ b/3ds/include/YesNoOverlay.hpp @@ -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; diff --git a/3ds/include/cheatmanager.hpp b/3ds/include/cheatmanager.hpp index 6bb28dd..deb5c2c 100644 --- a/3ds/include/cheatmanager.hpp +++ b/3ds/include/cheatmanager.hpp @@ -52,7 +52,7 @@ public: private: CheatManager(void); - ~CheatManager(void){}; + ~CheatManager() = default; CheatManager(CheatManager const&) = delete; void operator=(CheatManager const&) = delete; diff --git a/3ds/include/configuration.hpp b/3ds/include/configuration.hpp index f482586..e94c476 100644 --- a/3ds/include/configuration.hpp +++ b/3ds/include/configuration.hpp @@ -53,7 +53,7 @@ public: private: Configuration(void); - ~Configuration(void){}; + ~Configuration() = default; void store(void); nlohmann::json loadJson(const std::string& path); diff --git a/3ds/include/directory.hpp b/3ds/include/directory.hpp index fdae71e..1c4dacf 100644 --- a/3ds/include/directory.hpp +++ b/3ds/include/directory.hpp @@ -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); diff --git a/3ds/include/fsstream.hpp b/3ds/include/fsstream.hpp index 2a3f31d..20c9614 100644 --- a/3ds/include/fsstream.hpp +++ b/3ds/include/fsstream.hpp @@ -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); diff --git a/3ds/source/CheatManagerOverlay.cpp b/3ds/source/CheatManagerOverlay.cpp index cb61fb8..282dfc9 100644 --- a/3ds/source/CheatManagerOverlay.cpp +++ b/3ds/source/CheatManagerOverlay.cpp @@ -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()); diff --git a/3ds/source/ErrorOverlay.cpp b/3ds/source/ErrorOverlay.cpp index ee9c0e8..d1f7386 100644 --- a/3ds/source/ErrorOverlay.cpp +++ b/3ds/source/ErrorOverlay.cpp @@ -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(); diff --git a/3ds/source/InfoOverlay.cpp b/3ds/source/InfoOverlay.cpp index 2ec7e73..5f251c5 100644 --- a/3ds/source/InfoOverlay.cpp +++ b/3ds/source/InfoOverlay.cpp @@ -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(); diff --git a/3ds/source/MainScreen.cpp b/3ds/source/MainScreen.cpp index 34231aa..dd9c1f4 100644 --- a/3ds/source/MainScreen.cpp +++ b/3ds/source/MainScreen.cpp @@ -264,7 +264,7 @@ void MainScreen::drawBottom(void) const } } -void MainScreen::update(touchPosition* touch) +void MainScreen::update(TouchScreen* touch) { updateSelector(); handleEvents(touch); diff --git a/3ds/source/YesNoOverlay.cpp b/3ds/source/YesNoOverlay.cpp index 0fe8fdb..eb8e3fa 100644 --- a/3ds/source/YesNoOverlay.cpp +++ b/3ds/source/YesNoOverlay.cpp @@ -72,7 +72,7 @@ void YesNoOverlay::drawBottom(void) const } } -void YesNoOverlay::update(touchPosition* touch) +void YesNoOverlay::update(TouchScreen* touch) { hid.update(2); diff --git a/common/Overlay.hpp b/common/Overlay.hpp index bb3a857..20d8d2c 100644 --- a/common/Overlay.hpp +++ b/common/Overlay.hpp @@ -29,18 +29,12 @@ #include "Screen.hpp" #include -#include -#if defined(_3DS) -#include <3ds.h> -#elif defined(__SWITCH__) -#include -#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; diff --git a/common/Screen.cpp b/common/Screen.cpp index 0f175f3..662538a 100644 --- a/common/Screen.cpp +++ b/common/Screen.cpp @@ -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 \ No newline at end of file diff --git a/common/Screen.hpp b/common/Screen.hpp index 41e19e4..59f3ae6 100644 --- a/common/Screen.hpp +++ b/common/Screen.hpp @@ -27,11 +27,7 @@ #ifndef SCREEN_HPP #define SCREEN_HPP -#if defined(_3DS) -#include <3ds.h> -#elif defined(__SWITCH__) -#include -#endif +#include "TouchScreen.hpp" #include 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) { 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 currentOverlay = nullptr; + mutable std::shared_ptr currentOverlay; }; #endif \ No newline at end of file diff --git a/switch/include/CheatManagerOverlay.hpp b/switch/include/CheatManagerOverlay.hpp index f9f63f2..8af0c47 100644 --- a/switch/include/CheatManagerOverlay.hpp +++ b/switch/include/CheatManagerOverlay.hpp @@ -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); diff --git a/switch/include/ErrorOverlay.hpp b/switch/include/ErrorOverlay.hpp index 366b3d2..64e17c6 100644 --- a/switch/include/ErrorOverlay.hpp +++ b/switch/include/ErrorOverlay.hpp @@ -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; diff --git a/switch/include/InfoOverlay.hpp b/switch/include/InfoOverlay.hpp index 0879ed1..f1fa457 100644 --- a/switch/include/InfoOverlay.hpp +++ b/switch/include/InfoOverlay.hpp @@ -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; diff --git a/switch/include/KeyboardManager.hpp b/switch/include/KeyboardManager.hpp index 20f3663..ee73a3a 100644 --- a/switch/include/KeyboardManager.hpp +++ b/switch/include/KeyboardManager.hpp @@ -50,7 +50,7 @@ public: private: KeyboardManager(void); - virtual ~KeyboardManager(void){}; + virtual ~KeyboardManager() = default; Result res; bool systemKeyboardAvailable; diff --git a/switch/include/MainScreen.hpp b/switch/include/MainScreen.hpp index 934ab6d..8f44f65 100644 --- a/switch/include/MainScreen.hpp +++ b/switch/include/MainScreen.hpp @@ -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 hid; std::unique_ptr backupList; std::unique_ptr buttonCheats, buttonBackup, buttonRestore; diff --git a/switch/include/TouchScreen.hpp b/switch/include/TouchScreen.hpp new file mode 100644 index 0000000..17980b2 --- /dev/null +++ b/switch/include/TouchScreen.hpp @@ -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 . + * + * 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 + +struct TouchScreen : public HidTouchScreenState, public PadState { }; + +#endif diff --git a/switch/include/YesNoOverlay.hpp b/switch/include/YesNoOverlay.hpp index d82b89a..89a6b69 100644 --- a/switch/include/YesNoOverlay.hpp +++ b/switch/include/YesNoOverlay.hpp @@ -43,7 +43,7 @@ public: YesNoOverlay(Screen& screen, const std::string& mtext, const std::function& callbackYes, const std::function& callbackNo); ~YesNoOverlay(void) {} void draw(void) const override; - void update(PadState*) override; + void update(TouchScreen*) override; private: u32 textw, texth; diff --git a/switch/include/cheatmanager.hpp b/switch/include/cheatmanager.hpp index 12a7870..ef42d37 100644 --- a/switch/include/cheatmanager.hpp +++ b/switch/include/cheatmanager.hpp @@ -54,7 +54,7 @@ public: private: CheatManager(void); - ~CheatManager(void){}; + ~CheatManager() = default; CheatManager(CheatManager const&) = delete; void operator=(CheatManager const&) = delete; diff --git a/switch/include/clickable.hpp b/switch/include/clickable.hpp index 24dad7d..8466a2b 100644 --- a/switch/include/clickable.hpp +++ b/switch/include/clickable.hpp @@ -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; }; diff --git a/switch/include/directory.hpp b/switch/include/directory.hpp index 6636466..5ee689d 100644 --- a/switch/include/directory.hpp +++ b/switch/include/directory.hpp @@ -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); diff --git a/switch/include/hid.hpp b/switch/include/hid.hpp index 4185ac7..7629aae 100644 --- a/switch/include/hid.hpp +++ b/switch/include/hid.hpp @@ -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(); } }; diff --git a/switch/include/title.hpp b/switch/include/title.hpp index f408582..ec3b1aa 100644 --- a/switch/include/title.hpp +++ b/switch/include/title.hpp @@ -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 displayName(void); diff --git a/switch/source/CheatManagerOverlay.cpp b/switch/source/CheatManagerOverlay.cpp index 0a2a613..cc01873 100644 --- a/switch/source/CheatManagerOverlay.cpp +++ b/switch/source/CheatManagerOverlay.cpp @@ -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) { diff --git a/switch/source/ErrorOverlay.cpp b/switch/source/ErrorOverlay.cpp index 95d40dd..d9593b0 100644 --- a/switch/source/ErrorOverlay.cpp +++ b/switch/source/ErrorOverlay.cpp @@ -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)) { diff --git a/switch/source/InfoOverlay.cpp b/switch/source/InfoOverlay.cpp index 9f59aa6..c744dcc 100644 --- a/switch/source/InfoOverlay.cpp +++ b/switch/source/InfoOverlay.cpp @@ -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)) { diff --git a/switch/source/MainScreen.cpp b/switch/source/MainScreen.cpp index 2540bed..3e3fe09 100644 --- a/switch/source/MainScreen.cpp +++ b/switch/source/MainScreen.cpp @@ -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(538, 276, 414, 380, rows); buttonBackup = std::make_unique(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(); diff --git a/switch/source/YesNoOverlay.cpp b/switch/source/YesNoOverlay.cpp index 0b65674..55e8b58 100644 --- a/switch/source/YesNoOverlay.cpp +++ b/switch/source/YesNoOverlay.cpp @@ -56,7 +56,7 @@ void YesNoOverlay::draw(void) const } } -void YesNoOverlay::update(PadState* pad) +void YesNoOverlay::update(TouchScreen* pad) { hid.update(2); diff --git a/switch/source/clickable.cpp b/switch/source/clickable.cpp index 9752426..fc9ed0a 100644 --- a/switch/source/clickable.cpp +++ b/switch/source/clickable.cpp @@ -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; } diff --git a/switch/source/main.cpp b/switch/source/main.cpp index b0baaf1..75d0999 100644 --- a/switch/source/main.cpp +++ b/switch/source/main.cpp @@ -48,7 +48,7 @@ int main(void) exit(res); } - PadState pad; + TouchScreen pad; padInitializeDefault(&pad); g_screen = std::make_unique(&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); diff --git a/switch/source/scrollable.cpp b/switch/source/scrollable.cpp index 6422ce4..2400648 100644 --- a/switch/source/scrollable.cpp +++ b/switch/source/scrollable.cpp @@ -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)