From 0d9ddc0241f37027dd701ac7ab7b90b819a9de68 Mon Sep 17 00:00:00 2001 From: bernardogiordano Date: Tue, 3 Oct 2017 14:16:10 +0200 Subject: [PATCH] Implement multiselection, fix #6. Add cosmetic changes --- assets/romfs/checkbox.png | Bin 0 -> 517 bytes assets/romfs/checkpoint.png | Bin 0 -> 583 bytes include/gui.h | 9 ++++++ include/swkbd.h | 2 +- source/fsstream.cpp | 3 +- source/gui.cpp | 62 +++++++++++++++++++++++++++++++++--- source/main.cpp | 21 +++++++++++- source/swkbd.cpp | 4 +-- source/title.cpp | 2 +- source/util.cpp | 5 ++- 10 files changed, 97 insertions(+), 11 deletions(-) create mode 100644 assets/romfs/checkbox.png create mode 100644 assets/romfs/checkpoint.png diff --git a/assets/romfs/checkbox.png b/assets/romfs/checkbox.png new file mode 100644 index 0000000000000000000000000000000000000000..c08a75c0d86281c40f24d05a883136a7b7cc7b42 GIT binary patch literal 517 zcmeAS@N?(olHy`uVBq!ia0vp^5+KaM1|%Pp+x`GjEa{HEjtmSN`?>!lvI6;x#X;^) z4C~IxyaaL-l0AZa85pY67#JE_7#My5g&JNkFq9fFFuY1&V6d9Oz#v{QXIG#NP=YPV z+ua371Hn({-St3l3KMe^SkgJTmbfRop5$z|PU2d!=hXiD>GO4%gKZRdD&G9?+hx*gz2GSd zOc6ac=^_(T{SF9C6__~9T07)!b>5E;S7DZy>Qx$knW zeqhG1|H*@}gN;w-Jh@q1)c;`0uc%Lg?=&Y)oAE%7(X-7YF7jcVW3{k$47b+d==+mv zmVCRoVc+!qKf5NS%G}U;vjb? zhIQv;UIIA^$sR$z3=CCj3=9n|3=F@3LJcn%7)lKo7+xhXFj&oCU=S~uvn$XBD8ZKG z?d}4kf#9d}?s_1_S>O>_45U54*zIJt9ng3VPZ!4!i_=#p+UqwLinPwZZ6Y+QWa0#a zO)K>i^g55|>}x!!vX5nc!_f<#N#cSpbCwEk^axjcblyq6`8#jr&#hNImZaM}zf)ZN zzHwpWuBF%5X7)N=kodr2(omehIOE)oyB!u9Kc*``(hv<}l-nP${eYRnOI}vR2>T|7pY9mbg&ytFvzDv`zi3kz%40$Ds6x z(cUO_QmvAUQh^kMk%6JPuAzahfpLhTp_QqHm4TVIfq|8QfzUC2P#7aL z^ literal 0 HcmV?d00001 diff --git a/include/gui.h b/include/gui.h index 8db2b6d..8a3b4d0 100644 --- a/include/gui.h +++ b/include/gui.h @@ -21,6 +21,9 @@ #include "common.h" +#define TEXTURE_CHECKPOINT 1 +#define TEXTURE_CHECKBOX 2 + #define COLOR_BACKGROUND ABGR8(255, 51, 51, 51) #define COLOR_BARS RGBA8(150, 150, 150, 255) #define WHITE RGBA8(255, 255, 255, 255) @@ -32,6 +35,12 @@ size_t getScrollableIndex(void); +std::vector getSelectedEntries(void); +bool multipleSelectionEnabled(void); +void clearSelectedEntries(void); +void addSelectedEntry(size_t index); +void resetDirectoryListIndex(void); + class Gui { public: diff --git a/include/swkbd.h b/include/swkbd.h index 60d56bc..a86c864 100644 --- a/include/swkbd.h +++ b/include/swkbd.h @@ -23,6 +23,6 @@ #define CUSTOM_PATH_LEN 40 -std::u16string getPath(void); +std::u16string getPath(std::string suggestion); #endif \ No newline at end of file diff --git a/source/fsstream.cpp b/source/fsstream.cpp index 1483f04..2c175fa 100644 --- a/source/fsstream.cpp +++ b/source/fsstream.cpp @@ -200,7 +200,8 @@ void backup(size_t index) if (R_SUCCEEDED(res)) { - std::u16string customPath = isNewFolder ? getPath() : u8tou16(getPathFromCell(cellIndex).c_str()); + std::string suggestion = multipleSelectionEnabled() ? title.getShortDescription() + " - Autobackup" : getPathDateTime(); + std::u16string customPath = isNewFolder ? getPath(suggestion) : u8tou16(getPathFromCell(cellIndex).c_str()); if (!customPath.compare(u8tou16(" "))) { FSUSER_CloseArchive(archive); diff --git a/source/gui.cpp b/source/gui.cpp index 4fac10f..0e2dbd8 100644 --- a/source/gui.cpp +++ b/source/gui.cpp @@ -25,6 +25,53 @@ static Clickable* buttonBackup; static Clickable* buttonRestore; static Scrollable* directoryList; +/// Multi selection + +static std::vector selectedEntries; + +std::vector getSelectedEntries(void) +{ + return selectedEntries; +} + +bool multipleSelectionEnabled(void) +{ + return !selectedEntries.empty(); +} + +void clearSelectedEntries(void) +{ + selectedEntries.clear(); +} + +void addSelectedEntry(size_t index) +{ + int existing = -1; + for (size_t i = 0, sz = selectedEntries.size(); i < sz && existing == -1; i++) + { + if (selectedEntries.at(i) == index) + { + existing = (int)i; + } + } + + if (existing == -1) + { + selectedEntries.push_back(index); + } + else + { + selectedEntries.erase(selectedEntries.begin() + existing); + } +} + +/// Gui implementation + +void resetDirectoryListIndex(void) +{ + directoryList->resetIndex(); +} + size_t getScrollableIndex(void) { return directoryList->getIndex(); @@ -141,11 +188,17 @@ void Gui::draw(void) pp2d_draw_text(4, 3, 0.45f, 0.45f, GREYISH, getTime().c_str()); pp2d_draw_text(TOP_WIDTH - 4 - versionLen, 3, 0.45f, 0.45f, GREYISH, version); - pp2d_draw_text(TOP_WIDTH - 6 - versionLen - smLen, 2, 0.50f, 0.50f, WHITE, "checkpoint"); + pp2d_draw_texture(TEXTURE_CHECKPOINT, TOP_WIDTH - 5 - versionLen - 19, 0); + pp2d_draw_text(TOP_WIDTH - 6 - versionLen - smLen - 19, 2, 0.50f, 0.50f, WHITE, "checkpoint"); for (size_t k = page*entries; k < page*entries + max; k++) { - pp2d_draw_texture(getTextureId(k), getSelectorX(k) + 1, getSelectorY(k) + 1); + pp2d_draw_texture(getTextureId(k), getSelectorX(k) + 1, getSelectorY(k) + 1); + if (!selectedEntries.empty() && std::find(selectedEntries.begin(), selectedEntries.end(), k) != selectedEntries.end()) + { + pp2d_draw_rectangle(getSelectorX(k) + 28, getSelectorY(k) + 28, 16, 16, WHITE); + pp2d_draw_texture_blend(TEXTURE_CHECKBOX, getSelectorX(k) + 24, getSelectorY(k) + 24, RGBA8(51, 51, 51, 255)); + } } if (getTitlesCount() > 0) @@ -200,12 +253,13 @@ void Gui::draw(void) pp2d_draw_rectangle(4, 100, 312, 114, GREYISH); pp2d_draw_rectangle(6, 102, 308, 110, COLOR_BARS); - pp2d_draw_rectangle(202, 102, 2, 110, GREYISH); - pp2d_draw_rectangle(204, 156, 110, 2, GREYISH); directoryList->draw(); buttonBackup->draw(); buttonRestore->draw(); + + pp2d_draw_rectangle(202, 102, 2, 110, GREYISH); + pp2d_draw_rectangle(204, 156, 110, 2, GREYISH); } pp2d_draw_text_center(GFX_BOTTOM, 224, 0.46f, 0.46f, WHITE, "Press \uE073 to exit."); diff --git a/source/main.cpp b/source/main.cpp index c45ddbf..c624b49 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -52,6 +52,7 @@ int main() { menu->setBottomScroll(false); menu->updateButtonsColor(); setEntryType(TITLES); + clearSelectedEntries(); } if (hidKeysDown() & KEY_X) @@ -60,9 +61,27 @@ int main() { setMode(getMode() == MODE_SAVE ? MODE_EXTDATA : MODE_SAVE); } + if (hidKeysDown() & KEY_Y) + { + addSelectedEntry(menu->getNormalizedIndex()); + } + if (menu->isBackupReleased()) { - backup(menu->getNormalizedIndex()); + if (multipleSelectionEnabled()) + { + resetDirectoryListIndex(); + std::vector list = getSelectedEntries(); + for (size_t i = 0, sz = list.size(); i < sz; i++) + { + backup(list.at(i)); + } + clearSelectedEntries(); + } + else + { + backup(menu->getNormalizedIndex()); + } } if (menu->isRestoreReleased()) diff --git a/source/swkbd.cpp b/source/swkbd.cpp index acb9219..d0501bb 100644 --- a/source/swkbd.cpp +++ b/source/swkbd.cpp @@ -18,7 +18,7 @@ #include "swkbd.h" -std::u16string getPath(void) +std::u16string getPath(std::string suggestion) { static SwkbdState swkbd; SwkbdButton button = SWKBD_BUTTON_NONE; @@ -26,7 +26,7 @@ std::u16string getPath(void) swkbdInit(&swkbd, SWKBD_TYPE_NORMAL, 2, CUSTOM_PATH_LEN - 1); swkbdSetHintText(&swkbd, "Choose a name for your backup."); - swkbdSetInitialText(&swkbd, getPathDateTime().c_str()); + swkbdSetInitialText(&swkbd, suggestion.c_str()); button = swkbdInputText(&swkbd, buf, CUSTOM_PATH_LEN); buf[CUSTOM_PATH_LEN - 1] = '\0'; diff --git a/source/title.cpp b/source/title.cpp index 411cbb2..892564e 100644 --- a/source/title.cpp +++ b/source/title.cpp @@ -27,7 +27,7 @@ static std::vector titleExtdatas; bool Title::load(u64 _id, FS_MediaType _media) { bool loadTitle = false; - static size_t index = 1; + static size_t index = 3; id = _id; media = _media; diff --git a/source/util.cpp b/source/util.cpp index e8e1591..fe186b3 100644 --- a/source/util.cpp +++ b/source/util.cpp @@ -26,12 +26,13 @@ void servicesExit(void) hidExit(); pp2d_exit(); sdmcExit(); + romfsExit(); } void servicesInit(void) { Result res = 0; - + romfsInit(); sdmcInit(); pp2d_init(); hidInit(); @@ -51,4 +52,6 @@ void servicesInit(void) pp2d_set_screen_color(GFX_TOP, COLOR_BACKGROUND); pp2d_set_screen_color(GFX_BOTTOM, COLOR_BACKGROUND); + pp2d_load_texture_png(TEXTURE_CHECKBOX, "romfs:/checkbox.png"); + pp2d_load_texture_png(TEXTURE_CHECKPOINT, "romfs:/checkpoint.png"); } \ No newline at end of file