#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-static int in_sdl_menu_translate(void *drv_data, int keycode)
+static int in_sdl_menu_translate(void *drv_data, int keycode, char *charcode)
{
+ int ret = 0;
int i;
if (keycode < 0)
}
else
{
- for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
- if (key_pbtn_map[i].key == keycode)
- return key_pbtn_map[i].pbtn;
+ for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) {
+ if (key_pbtn_map[i].key == keycode) {
+ ret = key_pbtn_map[i].pbtn;
+ break;
+ }
+ }
+
+ if (charcode != NULL && (unsigned int)keycode < SDLK_LAST &&
+ in_sdl_keys[keycode] != NULL && in_sdl_keys[keycode][1] == 0)
+ {
+ ret |= PBTN_CHAR;
+ *charcode = in_sdl_keys[keycode][0];
+ }
}
- return 0;
+ return ret;
}
static const in_drv_t in_sdl_drv = {
/*
* 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];
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;
}
/* 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;
{
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;
}
/* 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;
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;
}
/* flush events */
do {
- ret = in_update_keycode(NULL, NULL, 0);
+ ret = in_update_keycode(NULL, NULL, NULL, 0);
} while (ret >= 0);
return 0;
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];
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; }
#define PBTN_MENU (1 << 10)
+#define PBTN_CHAR (1 << 11) /* character (text input) */
+
// TODO: move to pico
#if 0
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);
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);
return -1;\r
}\r
\r
+static char tolower_simple(char c)\r
+{\r
+ if ('A' <= c && c <= 'Z')\r
+ c = c - 'A' + 'a';\r
+ return c;\r
+}\r
+\r
void menu_init(void)\r
{\r
int i, c, l;\r
\r
/* make sure action buttons are not pressed on entering menu */\r
me_draw(menu, sel, NULL);\r
- while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
+ while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU));\r
\r
for (;;)\r
{\r
\r
me_draw(menu, sel, draw_more);\r
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
- PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, 70);\r
+ PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_L|PBTN_R, NULL, 70);\r
if (inp & (PBTN_MENU|PBTN_MBACK))\r
break;\r
\r
text_out16(mid - me_mfont_w * len / 2, 12 * me_mfont_h, tmp);\r
menu_draw_end();\r
\r
- while (in_menu_wait_any(50) & (PBTN_MENU|PBTN_MA2));\r
- inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, 100);\r
+ while (in_menu_wait_any(NULL, 50) & (PBTN_MENU|PBTN_MA2));\r
+ inp = in_menu_wait(PBTN_MA3|PBTN_MBACK, NULL, 100);\r
if (inp & PBTN_MA3)\r
remove(fpath);\r
}\r
return 1;\r
}\r
\r
+static int dirent_seek_char(struct dirent **namelist, int len, int sel, char c)\r
+{\r
+ int i;\r
+\r
+ sel++;\r
+ for (i = sel + 1; i != sel; i++) {\r
+ if (i >= len)\r
+ i = 1;\r
+\r
+ if (tolower_simple(namelist[i]->d_name[0]) == c)\r
+ break;\r
+ }\r
+\r
+ return i - 1;\r
+}\r
+\r
static char *menu_loop_romsel(char *curr_path, int len)\r
{\r
struct dirent **namelist;\r
int n, inp, sel = 0;\r
char *ret = NULL, *fname = NULL;\r
+ char cinp;\r
\r
rescan:\r
// is this a dir or a full path?\r
}\r
\r
// try to find sel\r
+ // note: we don't show '.' so sel is namelist index - 1\r
if (fname != NULL) {\r
int i;\r
for (i = 1; i < n; i++) {\r
- if (strcmp(namelist[i]->d_name, fname) == 0) {\r
+ char *dname = namelist[i]->d_name;\r
+ if (dname[0] == fname[0] && strcmp(dname, fname) == 0) {\r
sel = i - 1;\r
break;\r
}\r
\r
/* make sure action buttons are not pressed on entering menu */\r
draw_dirlist(curr_path, namelist, n, sel);\r
- while (in_menu_wait_any(50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU))\r
+ while (in_menu_wait_any(NULL, 50) & (PBTN_MOK|PBTN_MBACK|PBTN_MENU))\r
;\r
\r
for (;;)\r
{\r
draw_dirlist(curr_path, namelist, n, sel);\r
inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|\r
- PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU, 33);\r
+ PBTN_L|PBTN_R|PBTN_MA2|PBTN_MOK|PBTN_MBACK|PBTN_MENU|PBTN_CHAR, &cinp, 33);\r
if (inp & PBTN_UP ) { sel--; if (sel < 0) sel = n-2; }\r
if (inp & PBTN_DOWN) { sel++; if (sel > n-2) sel = 0; }\r
if (inp & PBTN_LEFT) { sel-=10; if (sel < 0) sel = 0; }\r
if (inp & PBTN_L) { sel-=24; if (sel < 0) sel = 0; }\r
if (inp & PBTN_RIGHT) { sel+=10; if (sel > n-2) sel = n-2; }\r
if (inp & PBTN_R) { sel+=24; if (sel > n-2) sel = n-2; }\r
+ if (inp & PBTN_CHAR) sel = dirent_seek_char(namelist, n, sel, cinp);\r
if ((inp & PBTN_MOK) || (inp & (PBTN_MENU|PBTN_MA2)) == (PBTN_MENU|PBTN_MA2))\r
{\r
again:\r
for (;;)\r
{\r
draw_savestate_menu(menu_sel, is_loading);\r
- inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, 100);\r
+ inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_MOK|PBTN_MBACK, NULL, 100);\r
if (inp & PBTN_UP) {\r
do {\r
menu_sel--;\r
for (;;)\r
{\r
draw_key_config(opts, opt_cnt, player_idx, sel, dev_id, dev_count, 0);\r
- mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_MBACK|PBTN_MOK|PBTN_MA2, 100);\r
+ mkey = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT\r
+ |PBTN_MBACK|PBTN_MOK|PBTN_MA2, NULL, 100);\r
switch (mkey) {\r
case PBTN_UP: sel--; if (sel < 0) sel = menu_sel_max; continue;\r
case PBTN_DOWN: sel++; if (sel > menu_sel_max) sel = 0; continue;\r
case PBTN_MOK:\r
if (sel >= opt_cnt)\r
return;\r
- while (in_menu_wait_any(30) & PBTN_MOK)\r
+ while (in_menu_wait_any(NULL, 30) & PBTN_MOK)\r
;\r
break;\r
case PBTN_MA2:\r
\r
/* wait for some up event */\r
for (is_down = 1; is_down; )\r
- kc = in_update_keycode(&bind_dev_id, &is_down, -1);\r
+ kc = in_update_keycode(&bind_dev_id, &is_down, NULL, -1);\r
\r
i = count_bound_keys(bind_dev_id, opts[sel].mask << mask_shift, bindtype);\r
unbind = (i > 0);\r
#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-static int in_gp2x_menu_translate(void *drv_data, int keycode)
+static int in_gp2x_menu_translate(void *drv_data, int keycode, char *charcode)
{
int i;
if (keycode < 0)
#define KEY_PBTN_MAP_SIZE (sizeof(key_pbtn_map) / sizeof(key_pbtn_map[0]))
-static int in_evdev_menu_translate(void *drv_data, int keycode)
+static int in_evdev_menu_translate(void *drv_data, int keycode, char *charcode)
{
in_evdev_t *dev = drv_data;
+ int ret = 0;
int i;
if (keycode < 0)
}
else
{
- for (i = 0; i < KEY_PBTN_MAP_SIZE; i++)
- if (key_pbtn_map[i].key == keycode)
- return key_pbtn_map[i].pbtn;
+ for (i = 0; i < KEY_PBTN_MAP_SIZE; i++) {
+ if (key_pbtn_map[i].key == keycode) {
+ ret = key_pbtn_map[i].pbtn;
+ break;
+ }
+ }
+
+ if (charcode != NULL && (unsigned int)keycode < KEY_CNT &&
+ in_evdev_keys[keycode] != NULL && in_evdev_keys[keycode][1] == 0)
+ {
+ char c = in_evdev_keys[keycode][0];
+ if ('A' <= c && c <= 'Z')
+ c = 'a' + c - 'A';
+ ret |= PBTN_CHAR;
+ *charcode = c;
+ }
}
- return 0;
+ return ret;
}
/* remove binds of missing keys, count remaining ones */
text_out16(2, 480 - 18, "%dx%d | d-pad: resize, R+d-pad: move", g_layer_w, g_layer_h);
menu_draw_end();
- inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT|PBTN_R|PBTN_MOK|PBTN_MBACK, 40);
+ inp = in_menu_wait(PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT
+ |PBTN_R|PBTN_MOK|PBTN_MBACK, NULL, 40);
if (inp & PBTN_UP) g_layer_y--;
if (inp & PBTN_DOWN) g_layer_y++;
if (inp & PBTN_LEFT) g_layer_x--;
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, 10);
+ PBTN_UP|PBTN_DOWN|PBTN_LEFT|PBTN_RIGHT, NULL, 10);
if (inp & PBTN_MBACK) break;
else if (inp & PBTN_UP) { if (df_y > 0) df_y--; }
else if (inp & PBTN_DOWN) { if (df_y < 512 - g_menuscreen_h) df_y++; }
{
draw_menu_message(tmp_msg, NULL);
- inp = in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
+ inp = in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
if (inp & (PBTN_MBACK|PBTN_MOK))
return;
}
break;
case MA_MAIN_CREDITS:
draw_menu_message(credits_text, draw_frame_credits);
- in_menu_wait(PBTN_MOK|PBTN_MBACK, 70);
+ in_menu_wait(PBTN_MOK|PBTN_MBACK, NULL, 70);
break;
case MA_MAIN_EXIT:
OnFile_Exit();
} while (!ready_to_go);
/* 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))
;
in_set_config_int(0, IN_CFG_BLOCKING, 0);
#include <linux/omapfb.h>
#include "common/menu.h"
+#include "common/input.h"
#include "linux/fbdev.h"
#include "linux/xenv.h"
#include "plugin_lib.h"
{
omap_enable_layer(0);
xenv_minimize();
+ in_set_config_int(0, IN_CFG_BLOCKING, 0); /* flush event queue */
omap_enable_layer(1);
}