Index: apps/recorder/keyboard.c =================================================================== --- apps/recorder/keyboard.c (revision 24311) +++ apps/recorder/keyboard.c (working copy) @@ -49,6 +49,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) \ @@ -270,6 +277,77 @@ return (k < pm->nchars)? pm->kbd_buf[k]: ' '; } +#ifdef HAVE_TOUCHSCREEN +#ifdef HAVE_MORSE_INPUT +#define keyboard_touchscreen(a, b, c) _keyboard_touchscreen(a, b, c) +#else +#define keyboard_touchscreen(a, b, c) _keyboard_touchscreen(a, b) +#endif +static int keyboard_touchscreen(struct keyboard_parameters *pm, + struct screen *sc, bool morse_mode) +{ + 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 (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; + } +#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; @@ -336,6 +414,9 @@ } char outline[256]; +#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; @@ -377,7 +458,7 @@ int i, w; pm->font = font_get(pm->curfont); - pm->font_h = pm->font->height; + pm->font_h = GRID_SIZE(pm->font->height); /* check if FONT_UI fits the screen */ if (2*pm->font_h + 3 + BUTTONBAR_HEIGHT > sc->getheight()) @@ -400,6 +481,12 @@ pm->font_w = w; } } + + pm->text_w = pm->font_w; + +#ifdef HAVE_TOUCHSCREEN + pm->font_w = GRID_SIZE(pm->font_w); +#endif } FOR_NB_SCREENS(l) @@ -461,9 +548,11 @@ struct keyboard_parameters *pm = ¶m[l]; struct screen *sc = &screens[l]; int icon_w, sc_w, sc_h; +#ifdef HAVE_TOUCHSCREEN + int button_h = 0; + bool flippage_button = false; +#endif - pm->text_w = pm->font_w; - utf8 = text; while (*utf8) { @@ -481,6 +570,16 @@ if(pm->max_chars_text < 3 && icon_w > pm->text_w) pm->max_chars_text = sc_w / pm->text_w - 2; +#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 (!kbd_loaded && pm->lines > pm->DEFAULT_LINES) @@ -503,9 +602,22 @@ if (pm->pages == 1) pm->lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; +#ifdef HAVE_TOUCHSCREEN + else if (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 + if (button_h && flippage_button) + pm->main_y += button_h; +#endif #ifdef HAVE_MORSE_INPUT pm->old_main_y = pm->main_y; @@ -602,13 +714,13 @@ for (i = j = 0; j < pm->lines && k < pm->nchars; k++) { - int w; + int w, h; 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) { @@ -651,12 +763,12 @@ if ((*utf8 & MASK) != COMP) { - int w; + int w, h; outline[j] = 0; j = 0; - sc->getstringsize(outline, &w, NULL); + sc->getstringsize(outline, &w, &h); sc->putsxy(text_margin + i*text_w + (text_w-w)/2, - pm->main_y, outline); + pm->main_y + (pm->font_h-h) / 2, outline); i++; } } @@ -711,6 +823,48 @@ gui_buttonbar_set(&buttonbar, "Shift", "OK", "Del"); gui_buttonbar_draw(&buttonbar); #endif +#ifdef HAVE_TOUCHSCREEN + if (touchscreen_point) + { + struct keyboard_parameters *pm = ¶m[0]; + struct viewport vp; + viewport_set_defaults(&vp, SCREEN_MAIN); + int height = font_get(vp.font)->height, text_y = 1; + vp.flags |= VP_FLAG_ALIGN_CENTER; + lcd_set_viewport(&vp); + if (height < MIN_GRID_SIZE) + { + text_y = (MIN_GRID_SIZE - height) / 2 + 1; + height = MIN_GRID_SIZE; + } + /* draw buttons */ + if (pm->pages > 1) + { + /* button to flip page. */ + vp.x = 0; + vp.y = pm->lines*pm->font_h; + vp.width = LCD_WIDTH; + vp.height = pm->font_h; + lcd_hline(0, LCD_WIDTH - 1, 0); + lcd_putsxy(0, text_y, ">"); + } + /* OK/Del/Cancel buttons */ + vp.x = 0; + vp.y = LCD_HEIGHT - height - 1; + vp.width = LCD_WIDTH; + vp.height = height + 1; + lcd_hline(0, LCD_WIDTH - 1, 0); + lcd_vline((LCD_WIDTH/3), 0, height); + lcd_vline((LCD_WIDTH/3)*2, 0, height); + vp.width = LCD_WIDTH/3; + lcd_putsxy(0, text_y, "OK"); + vp.x = (LCD_WIDTH/3); + lcd_putsxy(0, text_y, "Del"); + vp.x = (LCD_WIDTH/3)*2; + lcd_putsxy(0, text_y, "Cancel"); + lcd_set_viewport(NULL); + } +#endif FOR_NB_SCREENS(l) { @@ -745,6 +899,10 @@ #endif pm = ¶m[button_screen]; sc = &screens[button_screen]; +#ifdef HAVE_TOUCHSCREEN + if (button == ACTION_TOUCHSCREEN) + button = keyboard_touchscreen(pm, sc, morse_mode); +#endif #if defined(KBD_MODES) || defined(HAVE_MORSE_INPUT) /* Remap some buttons to allow to move