mirror of
https://github.com/RaySollium99/picodrive.git
synced 2025-09-05 15:27:46 -04:00
menu: support seeking the filelist with letter keys
git-svn-id: file:///home/notaz/opt/svn/PicoDrive@955 be3aeb3a-fb24-0410-a615-afba39da0efa
This commit is contained in:
parent
03435ed2c6
commit
134503079f
5 changed files with 68 additions and 37 deletions
|
@ -1258,13 +1258,13 @@ static void run_events_ui(unsigned int which)
|
|||
plat_status_msg_busy_first(tmp);
|
||||
|
||||
in_set_config_int(0, IN_CFG_BLOCKING, 1);
|
||||
while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK))
|
||||
while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))
|
||||
;
|
||||
while ( !((keys = in_menu_wait_any(50)) & (PBTN_MA3|PBTN_MBACK)) )
|
||||
while ( !((keys = in_menu_wait_any(NULL, 50)) & (PBTN_MA3|PBTN_MBACK)) )
|
||||
;
|
||||
if (keys & PBTN_MBACK)
|
||||
do_it = 0;
|
||||
while (in_menu_wait_any(50) & (PBTN_MA3|PBTN_MBACK))
|
||||
while (in_menu_wait_any(NULL, 50) & (PBTN_MA3|PBTN_MBACK))
|
||||
;
|
||||
in_set_config_int(0, IN_CFG_BLOCKING, 0);
|
||||
}
|
||||
|
|
|
@ -344,7 +344,7 @@ static int in_update_kc_async(int *dev_id_out, int *is_down_out, int timeout_ms)
|
|||
/*
|
||||
* wait for a press, always return some keycode or -1 on timeout or error
|
||||
*/
|
||||
int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
|
||||
int in_update_keycode(int *dev_id_out, int *is_down_out, char *charcode, int timeout_ms)
|
||||
{
|
||||
int result = -1, dev_id = 0, is_down, result_menu;
|
||||
int fds_hnds[IN_MAX_DEVS];
|
||||
|
@ -411,7 +411,7 @@ int in_update_keycode(int *dev_id_out, int *is_down_out, int timeout_ms)
|
|||
finish:
|
||||
/* keep track of menu key state, to allow mixing
|
||||
* in_update_keycode() and in_menu_wait_any() calls */
|
||||
result_menu = drv->menu_translate(in_devices[dev_id].drv_data, result);
|
||||
result_menu = drv->menu_translate(in_devices[dev_id].drv_data, result, charcode);
|
||||
if (result_menu != 0) {
|
||||
if (is_down)
|
||||
menu_key_state |= result_menu;
|
||||
|
@ -427,7 +427,7 @@ finish:
|
|||
}
|
||||
|
||||
/* same as above, only return bitfield of PBTN_* */
|
||||
int in_menu_wait_any(int timeout_ms)
|
||||
int in_menu_wait_any(char *charcode, int timeout_ms)
|
||||
{
|
||||
int keys_old = menu_key_state;
|
||||
|
||||
|
@ -435,7 +435,7 @@ int in_menu_wait_any(int timeout_ms)
|
|||
{
|
||||
int code, is_down = 0, dev_id = 0;
|
||||
|
||||
code = in_update_keycode(&dev_id, &is_down, timeout_ms);
|
||||
code = in_update_keycode(&dev_id, &is_down, charcode, timeout_ms);
|
||||
if (code < 0)
|
||||
break;
|
||||
|
||||
|
@ -449,7 +449,7 @@ int in_menu_wait_any(int timeout_ms)
|
|||
}
|
||||
|
||||
/* wait for menu input, do autorepeat */
|
||||
int in_menu_wait(int interesting, int autorep_delay_ms)
|
||||
int in_menu_wait(int interesting, char *charcode, int autorep_delay_ms)
|
||||
{
|
||||
static int inp_prev = 0;
|
||||
static int repeats = 0;
|
||||
|
@ -458,12 +458,12 @@ int in_menu_wait(int interesting, int autorep_delay_ms)
|
|||
if (repeats)
|
||||
wait = autorep_delay_ms;
|
||||
|
||||
ret = in_menu_wait_any(wait);
|
||||
ret = in_menu_wait_any(charcode, wait);
|
||||
if (ret == inp_prev)
|
||||
repeats++;
|
||||
|
||||
while (!(ret & interesting)) {
|
||||
ret = in_menu_wait_any(-1);
|
||||
ret = in_menu_wait_any(charcode, -1);
|
||||
release = 1;
|
||||
}
|
||||
|
||||
|
@ -540,7 +540,7 @@ static int in_set_blocking(int is_blocking)
|
|||
|
||||
/* flush events */
|
||||
do {
|
||||
ret = in_update_keycode(NULL, NULL, 0);
|
||||
ret = in_update_keycode(NULL, NULL, NULL, 0);
|
||||
} while (ret >= 0);
|
||||
|
||||
return 0;
|
||||
|
@ -643,7 +643,7 @@ const char *in_get_key_name(int dev_id, int keycode)
|
|||
|
||||
drv = &DRV(dev->drv_id);
|
||||
if (keycode < 0) /* want name for menu key? */
|
||||
keycode = drv->menu_translate(dev->drv_data, keycode);
|
||||
keycode = drv->menu_translate(dev->drv_data, keycode, NULL);
|
||||
|
||||
if (dev->key_names != NULL && 0 <= keycode && keycode < dev->key_count)
|
||||
name = dev->key_names[keycode];
|
||||
|
@ -917,7 +917,7 @@ static int in_def_get_config(void *drv_data, int what, int *val) { return -1; }
|
|||
static int in_def_set_config(void *drv_data, int what, int val) { return -1; }
|
||||
static int in_def_update_analog(void *drv_data, int axis_id, int *result) { return -1; }
|
||||
static int in_def_update_keycode(void *drv_data, int *is_down) { return 0; }
|
||||
static int in_def_menu_translate(void *drv_data, int keycode) { return 0; }
|
||||
static int in_def_menu_translate(void *drv_data, int keycode, char *ccode) { return 0; }
|
||||
static int in_def_get_key_code(const char *key_name) { return -1; }
|
||||
static const char *in_def_get_key_name(int keycode) { return NULL; }
|
||||
|
||||
|
|
|
@ -20,6 +20,8 @@
|
|||
|
||||
#define PBTN_MENU (1 << 10)
|
||||
|
||||
#define PBTN_CHAR (1 << 11) /* character (text input) */
|
||||
|
||||
// TODO: move to pico
|
||||
#if 0
|
||||
|
||||
|
@ -87,7 +89,7 @@ typedef struct {
|
|||
int (*update_analog)(void *drv_data, int axis_id, int *result);
|
||||
/* return -1 on no event, -2 on error */
|
||||
int (*update_keycode)(void *drv_data, int *is_down);
|
||||
int (*menu_translate)(void *drv_data, int keycode);
|
||||
int (*menu_translate)(void *drv_data, int keycode, char *charcode);
|
||||
int (*get_key_code)(const char *key_name);
|
||||
const char * (*get_key_name)(int keycode);
|
||||
|
||||
|
@ -111,9 +113,9 @@ void in_init(void);
|
|||
void in_probe(void);
|
||||
int in_update(int *result);
|
||||
int in_update_analog(int dev_id, int axis_id, int *value);
|
||||
int in_update_keycode(int *dev_id, int *is_down, int timeout_ms);
|
||||
int in_menu_wait_any(int timeout_ms);
|
||||
int in_menu_wait(int interesting, int autorep_delay_ms);
|
||||
int in_update_keycode(int *dev_id, int *is_down, char *charcode, int timeout_ms);
|
||||
int in_menu_wait_any(char *charcode, int timeout_ms);
|
||||
int in_menu_wait(int interesting, char *charcode, int autorep_delay_ms);
|
||||
int in_config_parse_dev(const char *dev_name);
|
||||
int in_config_bind_key(int dev_id, const char *key, int binds, int bind_type);
|
||||
int in_get_config(int dev_id, int what, void *val);
|
||||
|
|
|
@ -216,6 +216,13 @@ static int parse_hex_color(char *buff)
|
|||
return -1;
|
||||
}
|
||||
|
||||
static char tolower_simple(char c)
|
||||
{
|
||||
if ('A' <= c && c <= 'Z')
|
||||
c = c - 'A' + 'a';
|
||||
return c;
|
||||
}
|
||||
|
||||
void menu_init(void)
|
||||
{
|
||||
int i, c, l;
|
||||
|
@ -619,7 +626,7 @@ static int me_loop_d(menu_entry *menu, int *menu_sel, void (*draw_prep)(void), v
|
|||
|
||||
/* make sure action buttons are not pressed on entering menu */
|
||||
me_draw(menu, sel, NULL);
|
||||
while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));
|
||||
while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));
|
||||
|
||||
for (;;)
|
||||
{
|
||||
|
@ -628,7 +635,7 @@ static int me_loop_d(menu_entry *menu, int *menu_sel, void (*draw_prep)(void), v
|
|||
|
||||
me_draw(menu, sel, draw_more);
|
||||
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|
|
||||
PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70);
|
||||
PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, NULL, 70);
|
||||
if (inp & (PBTN_MENU|PBTN_MBACK))
|
||||
break;
|
||||
|
||||
|
@ -749,8 +756,8 @@ static void do_delete(const char *fpath, const char *fname)
|
|||
text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, tmp);
|
||||
menu_draw_end();
|
||||
|
||||
while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MA2));
|
||||
inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, 100);
|
||||
while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MA2));
|
||||
inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, NULL, 100);
|
||||
if (inp & PBTN_MA3)
|
||||
remove(fpath);
|
||||
}
|
||||
|
@ -824,11 +831,28 @@ static int scandir_filter(const struct dirent *ent)
|
|||
return 1;
|
||||
}
|
||||
|
||||
static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c)
|
||||
{
|
||||
int i;
|
||||
|
||||
sel++;
|
||||
for (i = sel + 1; i != sel; i++) {
|
||||
if (i >= len)
|
||||
i = 1;
|
||||
|
||||
if (tolower_simple(namelist[i]->d_name[0]) == c)
|
||||
break;
|
||||
}
|
||||
|
||||
return i - 1;
|
||||
}
|
||||
|
||||
static char *menu_loop_romsel(char *curr_path, int len)
|
||||
{
|
||||
struct dirent **namelist;
|
||||
int n, inp, sel = 0;
|
||||
char *ret = NULL, *fname = NULL;
|
||||
char cinp;
|
||||
|
||||
rescan:
|
||||
// is this a dir or a full path?
|
||||
|
@ -858,10 +882,12 @@ rescan:
|
|||
}
|
||||
|
||||
// try to find sel
|
||||
// note: we don't show '.' so sel is namelist index - 1
|
||||
if (fname != NULL) {
|
||||
int i;
|
||||
for (i = 1; i < n; i++) {
|
||||
if (strcmp(namelist[i]->d_name, fname) == 0) {
|
||||
char *dname = namelist[i]->d_name;
|
||||
if (dname[0] == fname[0] && strcmp(dname, fname) == 0) {
|
||||
sel = i - 1;
|
||||
break;
|
||||
}
|
||||
|
@ -870,20 +896,21 @@ rescan:
|
|||
|
||||
/* make sure action buttons are not pressed on entering menu */
|
||||
draw_dirlist(curr_path, namelist, n, sel);
|
||||
while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU))
|
||||
while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU))
|
||||
;
|
||||
|
||||
for (;;)
|
||||
{
|
||||
draw_dirlist(curr_path, namelist, n, sel);
|
||||
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|
|
||||
PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33);
|
||||
PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_CHAR, &cinp, 33);
|
||||
if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; }
|
||||
if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; }
|
||||
if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }
|
||||
if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }
|
||||
if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }
|
||||
if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; }
|
||||
if (inp & PBTN_CHAR) sel = dirent_seek_char(namelist, n, sel, cinp);
|
||||
if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2))
|
||||
{
|
||||
again:
|
||||
|
@ -1052,7 +1079,7 @@ static int menu_loop_savestate(int is_loading)
|
|||
for (;;)
|
||||
{
|
||||
draw_savestate_menu(menu_sel, is_loading);
|
||||
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, 100);
|
||||
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, NULL, 100);
|
||||
if (inp & PBTN_UP) {
|
||||
do {
|
||||
menu_sel--;
|
||||
|
@ -1242,7 +1269,8 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
|
|||
for (;;)
|
||||
{
|
||||
draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);
|
||||
mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK|PBTN_MA2, 100);
|
||||
mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT
|
||||
|PBTN_MBACK|PBTN_MOK|PBTN_MA2, NULL, 100);
|
||||
switch (mkey) {
|
||||
case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue;
|
||||
case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;
|
||||
|
@ -1267,7 +1295,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
|
|||
case PBTN_MOK:
|
||||
if (sel >= opt_cnt)
|
||||
return;
|
||||
while (in_menu_wait_any(30) & PBTN_MOK)
|
||||
while (in_menu_wait_any(NULL, 30) & PBTN_MOK)
|
||||
;
|
||||
break;
|
||||
case PBTN_MA2:
|
||||
|
@ -1280,7 +1308,7 @@ static void key_config_loop(const me_bind_action *opts, int opt_cnt, int player_
|
|||
|
||||
/* wait for some up event */
|
||||
for (is_down = 1; is_down; )
|
||||
kc = in_update_keycode(&bind_dev_id, &is_down, -1);
|
||||
kc = in_update_keycode(&bind_dev_id, &is_down, NULL, -1);
|
||||
|
||||
i = count_bound_keys(bind_dev_id, opts[sel].mask << mask_shift, bindtype);
|
||||
unbind = (i > 0);
|
||||
|
|
|
@ -193,7 +193,8 @@ static void menu_loop_patches(void)
|
|||
for (;;)
|
||||
{
|
||||
draw_patchlist(menu_sel);
|
||||
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R|PBTN_MOK|PBTN_MBACK, 33);
|
||||
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_L|PBTN_R
|
||||
|PBTN_MOK|PBTN_MBACK, NULL, 33);
|
||||
if (inp & PBTN_UP ) { menu_sel--; if (menu_sel < 0) menu_sel = PicoPatchCount; }
|
||||
if (inp & PBTN_DOWN) { menu_sel++; if (menu_sel > PicoPatchCount) menu_sel = 0; }
|
||||
if (inp &(PBTN_LEFT|PBTN_L)) { menu_sel-=10; if (menu_sel < 0) menu_sel = 0; }
|
||||
|
@ -694,7 +695,7 @@ static void mplayer_loop(void)
|
|||
while (1)
|
||||
{
|
||||
PDebugZ80Frame();
|
||||
if (in_menu_wait_any(0) & PBTN_MA3)
|
||||
if (in_menu_wait_any(NULL, 0) & PBTN_MA3)
|
||||
break;
|
||||
pemu_sound_wait();
|
||||
}
|
||||
|
@ -790,7 +791,7 @@ static void debug_menu_loop(void)
|
|||
menu_draw_end();
|
||||
|
||||
inp = in_menu_wait(PBTN_MOK|PBTN_MBACK|PBTN_MA2|PBTN_MA3|PBTN_L|PBTN_R |
|
||||
PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, 70);
|
||||
PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 70);
|
||||
if (inp & PBTN_MBACK) return;
|
||||
if (inp & PBTN_L) { mode--; if (mode < 0) mode = 4; }
|
||||
if (inp & PBTN_R) { mode++; if (mode > 4) mode = 0; }
|
||||
|
@ -801,13 +802,13 @@ static void debug_menu_loop(void)
|
|||
PDebugCPUStep();
|
||||
if (inp & PBTN_MA3) {
|
||||
while (inp & PBTN_MA3)
|
||||
inp = in_menu_wait_any(-1);
|
||||
inp = in_menu_wait_any(NULL, -1);
|
||||
mplayer_loop();
|
||||
}
|
||||
if ((inp & (PBTN_MA2|PBTN_LEFT)) == (PBTN_MA2|PBTN_LEFT)) {
|
||||
mkdir("dumps", 0777);
|
||||
PDebugDumpMem();
|
||||
while (inp & PBTN_MA2) inp = in_menu_wait_any(-1);
|
||||
while (inp & PBTN_MA2) inp = in_menu_wait_any(NULL, -1);
|
||||
dumped = 1;
|
||||
}
|
||||
break;
|
||||
|
@ -822,7 +823,7 @@ static void debug_menu_loop(void)
|
|||
PicoSkipFrame = 1;
|
||||
PicoFrame();
|
||||
PicoSkipFrame = 0;
|
||||
while (inp & PBTN_MOK) inp = in_menu_wait_any(-1);
|
||||
while (inp & PBTN_MOK) inp = in_menu_wait_any(NULL, -1);
|
||||
}
|
||||
break;
|
||||
case 3:
|
||||
|
@ -904,7 +905,7 @@ static int main_menu_handler(int id, int keys)
|
|||
break;
|
||||
case MA_MAIN_CREDITS:
|
||||
draw_menu_message(credits, NULL);
|
||||
in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
|
||||
in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
|
||||
break;
|
||||
case MA_MAIN_EXIT:
|
||||
engineState = PGS_Quit;
|
||||
|
@ -961,7 +962,7 @@ void menu_loop(void)
|
|||
if (engineState == PGS_Menu)
|
||||
engineState = PGS_Running;
|
||||
/* wait until menu, ok, back is released */
|
||||
while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
|
||||
while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK))
|
||||
;
|
||||
}
|
||||
|
||||
|
@ -1011,7 +1012,7 @@ int menu_loop_tray(void)
|
|||
ret = 0; /* no CD inserted */
|
||||
}
|
||||
|
||||
while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
|
||||
while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MOK|PBTN_MBACK));
|
||||
in_set_config_int(0, IN_CFG_BLOCKING, 0);
|
||||
|
||||
return ret;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue