summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--source/gui.c243
1 files changed, 172 insertions, 71 deletions
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<DS81_NUM_CONFIG_ITEMS;f++)
@@ -447,12 +452,19 @@ bool GUI_FileSelect(char pwd[], char selected_file[], const char *filter)
int paper;
int off;
int f;
+ bool drag;
+ int drag_start;
CheckPath(pwd);
FB_Clear();
- FB_printf(0,0,FB_RGB(0,0,0),FB_RGB(22,22,22),"%-31.31s",pwd);
+ FB_printf(0,0,FB_RGB(0,0,0),FB_RGB(22,22,22),"%-32.32s",pwd);
+
+ FB_Centre("Use pad and A to select",140,FB_RGB(31,31,0),-1);
+ FB_Centre("L and R to page up/down",150,FB_RGB(31,31,0),-1);
+ FB_Centre("Or use touchscreen",160,FB_RGB(31,31,0),-1);
+ FB_Centre("B to cancel",170,FB_RGB(31,31,0),-1);
no = LoadDir(pwd,filter);
@@ -460,6 +472,8 @@ bool GUI_FileSelect(char pwd[], char selected_file[], const char *filter)
top = 0;
done = false;
ret = false;
+ drag = false;
+ drag_start = 0;
if (no<=FSEL_LINES)
{
@@ -505,110 +519,197 @@ bool GUI_FileSelect(char pwd[], char selected_file[], const char *filter)
"%-*s %s",
FSEL_FILENAME_LEN,
off==0 ? "No Files!" : "",
- "");
+ " ");
}
}
FB_FillBox(240,FSEL_LIST_Y,16,FSEL_LIST_H,FB_RGB(10,10,10));
FB_FillBox(240,FSEL_LIST_Y+top*bar_step,16,bar_size,FB_RGB(31,31,31));
- do
+ if (drag)
{
- swiWaitForVBlank();
- } while(!(key=keysDownRepeat()));
+ touchPosition tp = {0};
+ int diff = 0;
- if (key & KEY_UP)
- {
- if (sel)
+ while (((key=keysHeld()) & KEY_TOUCH) && diff == 0)
{
- sel--;
+ tp = touchReadXY();
+ diff = tp.py - drag_start;
+ swiWaitForVBlank();
+ }
+
+ if (key & KEY_TOUCH)
+ {
+ int new_top;
- if (sel<top)
+ new_top = top + diff / bar_step;
+
+ if (new_top > (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)
+ {
+ top--;
+ }
+ }
+ }
+ else if (key & KEY_DOWN)
+ {
+ if (sel < (no-1))
{
- sel = no-1;
+ sel++;
+
+ 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());