Index: apps/recorder/keyboard.c =================================================================== --- apps/recorder/keyboard.c (revision 24416) +++ apps/recorder/keyboard.c (working copy) @@ -47,6 +47,13 @@ #define DEFAULT_MARGIN 6 #define KBD_BUF_SIZE 500 +#ifdef HAVE_TOUCHSCREEN +#define MIN_GRID_SIZE 16 +#define GRID_SIZE(x) MAX(MIN_GRID_SIZE, (x)) +#else +#define GRID_SIZE(x) (x) +#endif + #if (CONFIG_KEYPAD == ONDIO_PAD) \ || (CONFIG_KEYPAD == IPOD_1G2G_PAD) \ || (CONFIG_KEYPAD == IPOD_3G_PAD) \ @@ -285,6 +292,74 @@ return (k < pm->nchars)? pm->kbd_buf[k]: ' '; } +#ifdef HAVE_TOUCHSCREEN +static int keyboard_touchscreen(struct keyboard_parameters *pm, + struct screen *sc, struct edit_state *state) +{ + short x, y; + const int button = action_get_touchscreen_press(&x, &y); + const int sc_w = sc->getwidth(), sc_h = sc->getheight(); +#ifdef HAVE_MORSE_INPUT + if (state->morse_mode && y < pm->main_y - pm->keyboard_margin) + { + /* don't return ACTION_NONE as it has effect in morse mode. */ + return button == BUTTON_TOUCHSCREEN? ACTION_KBD_SELECT: + button & BUTTON_REL? ACTION_KBD_MORSE_SELECT: ACTION_STD_OK; + } +#else + (void) state; +#endif + if (x < 0 || y < 0) + return ACTION_NONE; + if (y < pm->lines*pm->font_h) + { + if (x/pm->font_w < pm->max_chars) + { + /* picker area */ + pm->x = x/pm->font_w; + pm->y = y/pm->font_h; +#ifdef KBD_MODES + pm->line_edit = false; +#endif + if (button == BUTTON_REL) + return ACTION_KBD_SELECT; + } + } + else if (y < pm->main_y - pm->keyboard_margin) + { + /* button to flip page */ + if (button == BUTTON_REL) + return ACTION_KBD_PAGE_FLIP; + } + else if (y < sc_h - pm->font_h) + { + /* edit line */ + if (button & (BUTTON_REPEAT|BUTTON_REL)) + { + if (x < sc_w/2) + return ACTION_KBD_CURSOR_LEFT; + else + return ACTION_KBD_CURSOR_RIGHT; + } + } + else if (y >= sc_h - pm->font_h) + { + /* OK/Del/Cancel button */ + if (button == BUTTON_REL) + { + x /= (sc_w/3); + if (x == 0) + return ACTION_KBD_DONE; + else if (x == 1) + return ACTION_KBD_BACKSPACE; + else + return ACTION_KBD_ABORT; + } + } + return ACTION_NONE; +} +#endif + int kbd_input(char* text, int buflen) { bool done = false; @@ -304,6 +379,9 @@ } char outline[8]; +#ifdef HAVE_TOUCHSCREEN + bool touchscreen_point = (touchscreen_get_mode() == TOUCHSCREEN_POINT); +#endif #ifdef HAVE_BUTTONBAR struct gui_buttonbar buttonbar; bool buttonbar_config = global_settings.buttonbar; @@ -391,14 +469,14 @@ pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI; font = font_get(pm->curfont); - pm->font_h = font->height; + pm->font_h = GRID_SIZE(font->height); /* check if FONT_UI fits the screen */ if (2*pm->font_h + 3 + BUTTONBAR_HEIGHT > sc->getheight()) { pm->curfont = FONT_SYSFIXED; font = font_get(FONT_SYSFIXED); - pm->font_h = font->height; + pm->font_h = GRID_SIZE(font->height); } /* find max width of keyboard glyphs. @@ -426,6 +504,10 @@ pm->text_w = w; } +#ifdef HAVE_TOUCHSCREEN + if (pm->font_w < MIN_GRID_SIZE) + pm->font_w = MIN_GRID_SIZE; +#endif /* calculate how many characters to put in a row. */ icon_w = get_icon_width(l); sc_w = sc->getwidth(); @@ -491,8 +573,22 @@ struct keyboard_parameters *pm = ¶m[l]; struct screen *sc = &screens[l]; int sc_h, total_lines; +#ifdef HAVE_TOUCHSCREEN + int button_h = 0; + bool flippage_button = false; +#endif sc_h = sc->getheight(); +#ifdef HAVE_TOUCHSCREEN + /* add space for buttons */ + if (l == SCREEN_MAIN && touchscreen_point) + { + /* use ui font for buttons */ + button_h = GRID_SIZE(sc->getcharheight()); + sc_h -= button_h; + } +recalc_param: +#endif pm->lines = (sc_h - BUTTONBAR_HEIGHT) / pm->font_h - 1; if (pm->default_lines && pm->lines > pm->default_lines) @@ -513,9 +609,23 @@ total_lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; pm->pages = (total_lines + pm->lines - 1) / pm->lines; pm->lines = (total_lines + pm->pages - 1) / pm->pages; +#ifdef HAVE_TOUCHSCREEN + if (pm->pages > 1 && button_h && !flippage_button) + { + /* add space for flip page button */ + sc_h -= button_h; + flippage_button = true; + goto recalc_param; + } +#endif pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin; pm->keyboard_margin -= pm->keyboard_margin/2; +#ifdef HAVE_TOUCHSCREEN + /* flip page button is put between piker and edit line */ + if (flippage_button) + pm->main_y += button_h; +#endif #ifdef HAVE_MORSE_INPUT pm->old_main_y = sc_h - pm->font_h - BUTTONBAR_HEIGHT; @@ -619,14 +729,14 @@ for (i = j = 0; k < pm->nchars; k++) { - int w; + int w, h; unsigned char *utf8; utf8 = utf8encode(pm->kbd_buf[k], outline); *utf8 = 0; - sc->getstringsize(outline, &w, NULL); + sc->getstringsize(outline, &w, &h); sc->putsxy(i*pm->font_w + (pm->font_w-w) / 2, - j*pm->font_h, outline); + j*pm->font_h + (pm->font_h-h) / 2, outline); if (++i >= pm->max_chars) { @@ -738,6 +848,48 @@ state.cur_blink = !state.cur_blink; +#ifdef HAVE_TOUCHSCREEN + if (touchscreen_point) + { + struct keyboard_parameters *pm = ¶m[SCREEN_MAIN]; + struct screen *sc = &screens[SCREEN_MAIN]; + struct viewport vp; + viewport_set_defaults(&vp, SCREEN_MAIN); + int height = font_get(vp.font)->height, text_y = 1; + int sc_w = sc->getwidth(), sc_h = sc->getheight(); + vp.flags |= VP_FLAG_ALIGN_CENTER; + sc->set_viewport(&vp); + if (height < MIN_GRID_SIZE) + { + text_y = (MIN_GRID_SIZE - height) / 2 + 1; + height = MIN_GRID_SIZE; + } + vp.x = 0; + vp.y = 0; + vp.width = sc_w; + vp.height = height; + /* draw buttons */ + if (pm->pages > 1) + { + /* button to flip page. */ + vp.y = pm->lines*pm->font_h; + sc->hline(0, sc_w - 1, 0); + sc->putsxy(0, text_y, ">"); + } + /* OK/Del/Cancel buttons */ + vp.y = sc_h - height - 1; + sc->hline(0, sc_w - 1, 0); + sc->vline((sc_w/3), 0, height); + sc->vline((sc_w/3)*2, 0, height); + vp.width = sc_w/3; + sc->putsxy(0, text_y, "OK"); + vp.x = (sc_w/3); + sc->putsxy(0, text_y, "Del"); + vp.x = (sc_w/3)*2; + sc->putsxy(0, text_y, "Cancel"); + sc->set_viewport(NULL); + } +#endif #ifdef HAVE_BUTTONBAR /* draw the button bar */ gui_buttonbar_set(&buttonbar, "Shift", "OK", "Del"); @@ -757,6 +909,10 @@ #endif pm = ¶m[button_screen]; sc = &screens[button_screen]; +#ifdef HAVE_TOUCHSCREEN + if (button == ACTION_TOUCHSCREEN) + button = keyboard_touchscreen(pm, sc, &state); +#endif #if defined(KBD_MODES) || defined(HAVE_MORSE_INPUT) /* Remap some buttons to allow to move