Enabled clipboard handling

This commit is contained in:
d0k3 2016-02-29 22:27:04 +01:00
parent 264c354c11
commit 759da56e67
3 changed files with 42 additions and 12 deletions

View File

@ -220,6 +220,11 @@ void CreateScreenshot() {
FileCreate(filename, main_buffer, 54 + (400 * 240 * 3 * 2)); FileCreate(filename, main_buffer, 54 + (400 * 240 * 3 * 2));
} }
void DirEntryCpy(DirEntry* dest, const DirEntry* orig) {
memcpy(dest, orig, sizeof(DirEntry));
dest->name = dest->path + (orig->name - orig->path);
}
void SortDirStruct(DirStruct* contents) { void SortDirStruct(DirStruct* contents) {
for (u32 s = 0; s < contents->n_entries; s++) { for (u32 s = 0; s < contents->n_entries; s++) {
DirEntry* cmp0 = &(contents->entry[s]); DirEntry* cmp0 = &(contents->entry[s]);
@ -236,13 +241,9 @@ void SortDirStruct(DirStruct* contents) {
} }
if (min0 != cmp0) { if (min0 != cmp0) {
DirEntry swap; // swap entries and fix names DirEntry swap; // swap entries and fix names
u32 offset_name_cmp0 = cmp0->name - cmp0->path; DirEntryCpy(&swap, cmp0);
u32 offset_name_min0 = min0->name - min0->path; DirEntryCpy(cmp0, min0);
memcpy(&swap, cmp0, sizeof(DirEntry)); DirEntryCpy(min0, &swap);
memcpy(cmp0, min0, sizeof(DirEntry));
memcpy(min0, &swap, sizeof(DirEntry));
cmp0->name = cmp0->path + offset_name_min0;
min0->name = min0->path + offset_name_cmp0;
} }
} }
} }

View File

@ -46,3 +46,6 @@ uint64_t GetFreeSpace(const char* path);
/** Gets total spacein filesystem in bytes */ /** Gets total spacein filesystem in bytes */
uint64_t GetTotalSpace(const char* path); uint64_t GetTotalSpace(const char* path);
/** Helper function for copying DirEntry structs */
void DirEntryCpy(DirEntry* dest, const DirEntry* orig);

View File

@ -10,7 +10,7 @@
#define COLOR_DIR COLOR_TINTEDBLUE #define COLOR_DIR COLOR_TINTEDBLUE
#define COLOR_ROOT COLOR_GREY #define COLOR_ROOT COLOR_GREY
void DrawUserInterface(const char* curr_path, DirEntry* curr_entry) { void DrawUserInterface(const char* curr_path, DirEntry* curr_entry, DirStruct* clipboard) {
const u32 info_start = 16; const u32 info_start = 16;
char bytestr0[32]; char bytestr0[32];
char bytestr1[32]; char bytestr1[32];
@ -34,15 +34,26 @@ void DrawUserInterface(const char* curr_path, DirEntry* curr_entry) {
// left top - current file info // left top - current file info
DrawStringF(true, 2, info_start, COLOR_STD_FONT, COLOR_STD_BG, "[CURRENT]"); DrawStringF(true, 2, info_start, COLOR_STD_FONT, COLOR_STD_BG, "[CURRENT]");
ResizeString(tempstr, curr_entry->name, 20, 8, false); ResizeString(tempstr, curr_entry->name, 20, 8, false);
DrawStringF(true, 2, info_start + 12, (curr_entry->marked) ? COLOR_MARKED : COLOR_STD_FONT, COLOR_STD_BG, "%s", tempstr); u32 color_current = (curr_entry->marked) ? COLOR_MARKED : (curr_entry->type == T_FAT_ROOT) ? COLOR_ROOT : (curr_entry->type == T_FAT_DIR) ? COLOR_DIR : COLOR_FILE;
DrawStringF(true, 4, info_start + 12, color_current, COLOR_STD_BG, "%s", tempstr);
if (curr_entry->type == T_FAT_DIR) { if (curr_entry->type == T_FAT_DIR) {
ResizeString(tempstr, "(dir)", 20, 8, false); ResizeString(tempstr, "(dir)", 20, 8, false);
DrawStringF(true, 4, info_start + 12 + 10, COLOR_DIR, COLOR_STD_BG, tempstr);
} else { } else {
FormatBytes(bytestr0, curr_entry->size); FormatBytes(bytestr0, curr_entry->size);
ResizeString(tempstr, bytestr0, 20, 8, false); ResizeString(tempstr, bytestr0, 20, 8, false);
DrawStringF(true, 4, info_start + 12 + 10, (curr_entry->type == T_FAT_FILE) ? COLOR_FILE : COLOR_ROOT, COLOR_STD_BG, tempstr);
} }
DrawStringF(true, 4, info_start + 12 + 10, color_current, COLOR_STD_BG, tempstr);
// right top - clipboard
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8), info_start, COLOR_STD_FONT, COLOR_STD_BG, "%20s", (clipboard->n_entries) ? "[CLIPBOARD]" : "");
for (u32 c = 0; c < 10; c++) {
ResizeString(tempstr, (clipboard->n_entries > c) ? clipboard->entry[c].name : "", 20, 8, true);
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8) - 4, info_start + 12 + (c*10), (clipboard->entry[c].type == T_FAT_FILE) ? COLOR_FILE : COLOR_DIR, COLOR_STD_BG, tempstr);
}
*tempstr = '\0';
if (clipboard->n_entries > 10) snprintf(tempstr, 60, "+ %lu more", clipboard->n_entries - 10);
DrawStringF(true, SCREEN_WIDTH_TOP - (20*8) - 4, info_start + 12 + (10*10), COLOR_GREY, COLOR_STD_BG, "%20s", tempstr);
// bottom: inctruction block // bottom: inctruction block
char* instr = "GodMode 9 v0.0.1\n<A>/<B>/<\x18\x19\x1A\x1B> - Navigation\n<L> - Mark (multiple) file(s)\n<X> - Make a Screenshot\n<START/+\x1B> - Reboot / Power off"; char* instr = "GodMode 9 v0.0.1\n<A>/<B>/<\x18\x19\x1A\x1B> - Navigation\n<L> - Mark (multiple) file(s)\n<X> - Make a Screenshot\n<START/+\x1B> - Reboot / Power off";
@ -112,7 +123,7 @@ u32 GodMode() {
GetDirContents(current_dir, ""); GetDirContents(current_dir, "");
clipboard->n_entries = 0; clipboard->n_entries = 0;
while (true) { // this is the main loop while (true) { // this is the main loop
DrawUserInterface(current_path, &current_dir->entry[cursor]); // no need to fully do this everytime! DrawUserInterface(current_path, &(current_dir->entry[cursor]), clipboard); // no need to fully do this everytime!
DrawDirContents(current_dir, cursor); DrawDirContents(current_dir, cursor);
u32 pad_state = InputWait(); u32 pad_state = InputWait();
if (pad_state & BUTTON_DOWN) { // cursor up if (pad_state & BUTTON_DOWN) { // cursor up
@ -152,7 +163,22 @@ u32 GodMode() {
ClearScreenF(true, true, COLOR_STD_BG); // not really required ClearScreenF(true, true, COLOR_STD_BG); // not really required
} else if (pad_state & BUTTON_X) { // create a screenshot } else if (pad_state & BUTTON_X) { // create a screenshot
CreateScreenshot(); CreateScreenshot();
} else if ((pad_state & BUTTON_Y) && (clipboard->n_entries == 0)) { // fill clipboard
for (u32 c = 0; c < current_dir->n_entries; c++) {
if (current_dir->entry[c].marked) {
DirEntryCpy(&(clipboard->entry[clipboard->n_entries]), &(current_dir->entry[c]));
current_dir->entry[c].marked = 0;
clipboard->n_entries++;
} }
}
if (clipboard->n_entries == 0) {
DirEntryCpy(&(clipboard->entry[0]), &(current_dir->entry[cursor]));
clipboard->n_entries = 1;
}
} else if ((pad_state & BUTTON_SELECT) && (clipboard->n_entries > 0)) { // clear clipboard
clipboard->n_entries = 0;
}
if (!(pad_state & BUTTON_L1)) { if (!(pad_state & BUTTON_L1)) {
mark_setting = -1; mark_setting = -1;
} }