From cefb6882dc4f67c85dc3a54e6e7ba8ad5898463d Mon Sep 17 00:00:00 2001 From: Ian C Date: Wed, 21 Feb 2007 01:13:20 +0000 Subject: File selector not so annoying with the touchscreen. --- source/gui.c | 243 ++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 172 insertions(+), 71 deletions(-) (limited to 'source/gui.c') diff --git a/source/gui.c b/source/gui.c index 7e55b97..92f6836 100644 --- a/source/gui.c +++ b/source/gui.c @@ -34,10 +34,10 @@ /* ---------------------------------------- PRIVATE INTERFACES - PATH HANDLING */ #define FSEL_FILENAME_LEN 20 -#define FSEL_LINES 15 +#define FSEL_LINES 16 #define FSEL_MAX_FILES 512 -#define FSEL_LIST_Y 12 +#define FSEL_LIST_Y 10 #define FSEL_LIST_H FSEL_LINES*8 typedef struct @@ -75,13 +75,18 @@ static void AddPath(char *path, const char *dir) { if (strcmp(dir,"..") == 0) { - char *p; + size_t l; - p = strrchr(path,'/'); + l = strlen(path); - if (p && p!=path) + if (l > 1) { - *p = 0; + path[--l] = 0; + + while(l && path[l] != '/') + { + path[l--] = 0; + } } } else @@ -102,7 +107,7 @@ static int SortFiles(const void *a, const void *b) f1 = (const FSEL_File *)a; f2 = (const FSEL_File *)b; - if (f1->is_dir == f1->is_dir) + if (f1->is_dir == f2->is_dir) { return strcmp(f1->name, f2->name); } @@ -360,7 +365,7 @@ void GUI_Config(void) FB_Centre("START to finish",170,FB_RGB(31,31,0),-1); #ifndef DS81_DISABLE_FAT - FB_Centre("SELECT to save to \\DS81.CFG",180,FB_RGB(31,31,0),-1); + FB_Centre("SELECT to finish and save",180,FB_RGB(31,31,0),-1); #endif for(f=0;f (no - FSEL_LINES)) { - top--; + new_top = no - FSEL_LINES; } - } - } - else if (key & KEY_DOWN) - { - if (sel < (no-1)) - { - sel++; - if (sel >= (top+FSEL_LINES)) + if (new_top < 0) { - top++; + new_top = 0; } + + if (new_top != top) + { + top = new_top; + sel = top; + drag_start = tp.py; + } + } + else + { + drag = false; } } - else if (key & KEY_L) + + if (!drag) { - if (sel) + bool activate = false; + + do { - sel-=FSEL_LINES; + swiWaitForVBlank(); + } while(!(key=keysDownRepeat())); - if (sel < 0) + if (key & KEY_TOUCH) + { + touchPosition tp; + + tp = touchReadXY(); + + if (tp.py >= FSEL_LIST_Y && tp.py <= (FSEL_LIST_Y+FSEL_LIST_H)) { - sel = 0; + if (tp.px > 239) + { + drag = true; + drag_start = tp.py; + } + else + { + int new_sel; + + new_sel = top + (tp.py - FSEL_LIST_Y)/8; + + if (new_sel < no) + { + if (new_sel == sel) + { + activate = true; + } + else + { + sel = new_sel; + } + } + } } - - top = sel; } - } - else if (key & KEY_R) - { - if (sel < (no-1)) + else if (key & KEY_UP) { - sel+=FSEL_LINES; + if (sel) + { + sel--; - if (sel > (no-1)) + if (sel= (top+FSEL_LINES)) + { + top++; + } } + } + else if (key & KEY_L) + { + if (sel) + { + sel-=FSEL_LINES; - top = sel - FSEL_LINES + 1; + if (sel < 0) + { + sel = 0; + } - if (top < 0) - { - top = 0; + top = sel; } } - } - else if (key & KEY_A) - { - if (fsel[sel].is_dir) + else if (key & KEY_R) { - AddPath(pwd,fsel[sel].name); + if (sel < (no-1)) + { + sel+=FSEL_LINES; + + if (sel > (no-1)) + { + sel = no-1; + } - no = LoadDir(pwd,filter); + top = sel - FSEL_LINES + 1; - sel = 0; - top = 0; + if (top < 0) + { + top = 0; + } + } + } + else if (key & KEY_A) + { + activate = true; + } + else if (key & KEY_B) + { + done = true; + } - if (no<=FSEL_LINES) + if (activate) + { + if (fsel[sel].is_dir) { - bar_step = 0; - bar_size = FSEL_LIST_H; + AddPath(pwd,fsel[sel].name); + + FB_printf(0,0,FB_RGB(0,0,0),FB_RGB(22,22,22), + "%-32.32s",pwd); + + no = LoadDir(pwd,filter); + + sel = 0; + top = 0; + + if (no<=FSEL_LINES) + { + bar_step = 0; + bar_size = FSEL_LIST_H; + } + else + { + bar_step = FSEL_LIST_H/(double)no; + bar_size = bar_step*FSEL_LINES; + } } else { - bar_step = FSEL_LIST_H/(double)no; - bar_size = bar_step*FSEL_LINES; - } - } - else - { - done = true; - ret = true; + done = true; + ret = true; - strcpy(selected_file,pwd); - strcat(selected_file,fsel[sel].name); + strcpy(selected_file,pwd); + strcat(selected_file,fsel[sel].name); + } } } - else if (key & KEY_START) - { - done=true; - } } while (keysHeld()); -- cgit v1.2.3