From b369f37c6244b5d56742b56f745219fb2544efe2 Mon Sep 17 00:00:00 2001 From: Ian C Date: Fri, 16 Feb 2007 01:10:41 +0000 Subject: Some hi-res support. Added new config page and averaging touchscreen reads. In process of writing file selector. --- source/gui.c | 428 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 427 insertions(+), 1 deletion(-) (limited to 'source/gui.c') diff --git a/source/gui.c b/source/gui.c index 713ad02..7e55b97 100644 --- a/source/gui.c +++ b/source/gui.c @@ -20,10 +20,160 @@ $Id$ */ -#include +#include +#include #include +#include + +#include #include "framebuffer.h" +#include "config.h" + + +/* ---------------------------------------- PRIVATE INTERFACES - PATH HANDLING +*/ +#define FSEL_FILENAME_LEN 20 +#define FSEL_LINES 15 +#define FSEL_MAX_FILES 512 + +#define FSEL_LIST_Y 12 +#define FSEL_LIST_H FSEL_LINES*8 + +typedef struct +{ + char name[FSEL_FILENAME_LEN+1]; + int is_dir; + int size; +} FSEL_File; + +static FSEL_File fsel[FSEL_MAX_FILES]; + + +static void CheckPath(char *path) +{ + size_t l; + + l = strlen(path); + + if (l == 1) + { + path[0] = '/'; + } + else + { + if (path[l-1] != '/') + { + path[l] = '/'; + path[l+1] = 0; + } + } +} + + +static void AddPath(char *path, const char *dir) +{ + if (strcmp(dir,"..") == 0) + { + char *p; + + p = strrchr(path,'/'); + + if (p && p!=path) + { + *p = 0; + } + } + else + { + strcat(path,dir); + strcat(path,"/"); + } +} + + + + +static int SortFiles(const void *a, const void *b) +{ + const FSEL_File *f1; + const FSEL_File *f2; + + f1 = (const FSEL_File *)a; + f2 = (const FSEL_File *)b; + + if (f1->is_dir == f1->is_dir) + { + return strcmp(f1->name, f2->name); + } + else if (f1->is_dir) + { + return -1; + } + else + { + return 1; + } +} + + +static int ValidFilename(const char *name, int is_dir, const char *filter) +{ + size_t l; + size_t f; + + l = strlen(name); + + if (l > FSEL_FILENAME_LEN) + return 0; + + if (strcmp(name,".") == 0) + return 0; + + if (is_dir || !filter) + return 1; + + f = strlen(filter); + + if (l > f) + { + if (strcmp(name+l-f,filter) == 0) + { + return 1; + } + } + + return 0; +} + + +static int LoadDir(const char *path, const char *filter) +{ + DIR_ITER *dir; + struct stat st; + char name[FILENAME_MAX]; + int no = 0; + + if ((dir = diropen(path))) + { + while(no < FSEL_MAX_FILES && dirnext(dir,name,&st) == 0) + { + if (ValidFilename(name, (st.st_mode & S_IFDIR), filter)) + { + strcpy(fsel[no].name,name); + fsel[no].is_dir = (st.st_mode & S_IFDIR); + fsel[no].size = (int)st.st_size; + no++; + } + } + + dirclose(dir); + + qsort(fsel,no,sizeof fsel[0],SortFiles); + } + + return no; +} /* ---------------------------------------- PUBLIC INTERFACES @@ -189,3 +339,279 @@ void GUI_Alert(int fatal, const char *text) } } } + + +void GUI_Config(void) +{ + int sel; + DS81_ConfigItem f; + bool done; + bool save; + + sel = 0; + done = false; + save = false; + + FB_Clear(); + + FB_Centre("Up/Down to select",140,FB_RGB(31,31,0),-1); + FB_Centre("A to toggle",150,FB_RGB(31,31,0),-1); + FB_Centre("Or use touchscreen",160,FB_RGB(31,31,0),-1); + 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); +#endif + + for(f=0;f=0 && nsel= (top+FSEL_LINES)) + { + top++; + } + } + } + else if (key & KEY_L) + { + if (sel) + { + sel-=FSEL_LINES; + + if (sel < 0) + { + sel = 0; + } + + top = sel; + } + } + else if (key & KEY_R) + { + if (sel < (no-1)) + { + sel+=FSEL_LINES; + + if (sel > (no-1)) + { + sel = no-1; + } + + top = sel - FSEL_LINES + 1; + + if (top < 0) + { + top = 0; + } + } + } + else if (key & KEY_A) + { + if (fsel[sel].is_dir) + { + AddPath(pwd,fsel[sel].name); + + 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 + { + done = true; + ret = true; + + strcpy(selected_file,pwd); + strcat(selected_file,fsel[sel].name); + } + } + else if (key & KEY_START) + { + done=true; + } + } + + while (keysHeld()); + + return ret; +} -- cgit v1.2.3