Skip to content

Commit

Permalink
Implement multiselection, fix BernardoGiordano#6. Add cosmetic changes
Browse files Browse the repository at this point in the history
  • Loading branch information
BernardoGiordano committed Oct 3, 2017
1 parent 930911f commit 0d9ddc0
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 11 deletions.
Binary file added assets/romfs/checkbox.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/romfs/checkpoint.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions include/gui.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -32,6 +35,12 @@

size_t getScrollableIndex(void);

std::vector<size_t> getSelectedEntries(void);
bool multipleSelectionEnabled(void);
void clearSelectedEntries(void);
void addSelectedEntry(size_t index);
void resetDirectoryListIndex(void);

class Gui
{
public:
Expand Down
2 changes: 1 addition & 1 deletion include/swkbd.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@

#define CUSTOM_PATH_LEN 40

std::u16string getPath(void);
std::u16string getPath(std::string suggestion);

#endif
3 changes: 2 additions & 1 deletion source/fsstream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
62 changes: 58 additions & 4 deletions source/gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,53 @@ static Clickable* buttonBackup;
static Clickable* buttonRestore;
static Scrollable* directoryList;

/// Multi selection

static std::vector<size_t> selectedEntries;

std::vector<size_t> 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();
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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.");
Expand Down
21 changes: 20 additions & 1 deletion source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ int main() {
menu->setBottomScroll(false);
menu->updateButtonsColor();
setEntryType(TITLES);
clearSelectedEntries();
}

if (hidKeysDown() & KEY_X)
Expand All @@ -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<size_t> 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())
Expand Down
4 changes: 2 additions & 2 deletions source/swkbd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@

#include "swkbd.h"

std::u16string getPath(void)
std::u16string getPath(std::string suggestion)
{
static SwkbdState swkbd;
SwkbdButton button = SWKBD_BUTTON_NONE;
char buf[CUSTOM_PATH_LEN] = {0};

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';
Expand Down
2 changes: 1 addition & 1 deletion source/title.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static std::vector<Title> 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;

Expand Down
5 changes: 4 additions & 1 deletion source/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ void servicesExit(void)
hidExit();
pp2d_exit();
sdmcExit();
romfsExit();
}

void servicesInit(void)
{
Result res = 0;

romfsInit();
sdmcInit();
pp2d_init();
hidInit();
Expand All @@ -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");
}

0 comments on commit 0d9ddc0

Please sign in to comment.