diff options
-rw-r--r-- | apps/lang/english.lang | 51 | ||||
-rw-r--r-- | apps/recorder/keyboard.c | 171 |
2 files changed, 219 insertions, 3 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 49ce9b25a1..2c09b594b2 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -12554,3 +12554,54 @@ | |||
12554 | *: "open picture flow" | 12554 | *: "open picture flow" |
12555 | </voice> | 12555 | </voice> |
12556 | </phrase> | 12556 | </phrase> |
12557 | <phrase> | ||
12558 | id: LANG_KBD_OK | ||
12559 | desc: in keyboad | ||
12560 | user: core | ||
12561 | <source> | ||
12562 | *: none | ||
12563 | touchscreen: "OK" | ||
12564 | </source> | ||
12565 | <dest> | ||
12566 | *: none | ||
12567 | touchscreen: "OK" | ||
12568 | </dest> | ||
12569 | <voice> | ||
12570 | *: none | ||
12571 | touchscreen: "OK" | ||
12572 | </voice> | ||
12573 | </phrase> | ||
12574 | <phrase> | ||
12575 | id: LANG_KBD_DELETE | ||
12576 | desc: in keyboad | ||
12577 | user: core | ||
12578 | <source> | ||
12579 | *: none | ||
12580 | touchscreen: "Del" | ||
12581 | </source> | ||
12582 | <dest> | ||
12583 | *: none | ||
12584 | touchscreen: "Del" | ||
12585 | </dest> | ||
12586 | <voice> | ||
12587 | *: none | ||
12588 | touchscreen: "Del" | ||
12589 | </voice> | ||
12590 | </phrase> | ||
12591 | <phrase> | ||
12592 | id: LANG_KBD_CANCEL | ||
12593 | desc: in keyboad | ||
12594 | user: core | ||
12595 | <source> | ||
12596 | *: none | ||
12597 | touchscreen: "Cancel" | ||
12598 | </source> | ||
12599 | <dest> | ||
12600 | *: none | ||
12601 | touchscreen: "Cancel" | ||
12602 | </dest> | ||
12603 | <voice> | ||
12604 | *: none | ||
12605 | touchscreen: "Cancel" | ||
12606 | </voice> | ||
12607 | </phrase> | ||
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c index e8894d179b..2ec14a8d09 100644 --- a/apps/recorder/keyboard.c +++ b/apps/recorder/keyboard.c | |||
@@ -47,6 +47,12 @@ | |||
47 | #define DEFAULT_MARGIN 6 | 47 | #define DEFAULT_MARGIN 6 |
48 | #define KBD_BUF_SIZE 500 | 48 | #define KBD_BUF_SIZE 500 |
49 | 49 | ||
50 | #ifdef HAVE_TOUCHSCREEN | ||
51 | #define MIN_GRID_SIZE 16 | ||
52 | #define GRID_SIZE(s, x) \ | ||
53 | ((s) == SCREEN_MAIN && MIN_GRID_SIZE > (x) ? MIN_GRID_SIZE: (x)) | ||
54 | #endif | ||
55 | |||
50 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) \ | 56 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) \ |
51 | || (CONFIG_KEYPAD == IRIVER_H300_PAD) \ | 57 | || (CONFIG_KEYPAD == IRIVER_H300_PAD) \ |
52 | || (CONFIG_KEYPAD == IPOD_1G2G_PAD) \ | 58 | || (CONFIG_KEYPAD == IPOD_1G2G_PAD) \ |
@@ -93,6 +99,9 @@ struct keyboard_parameters | |||
93 | int x; | 99 | int x; |
94 | int y; | 100 | int y; |
95 | bool line_edit; | 101 | bool line_edit; |
102 | #ifdef HAVE_TOUCHSCREEN | ||
103 | bool show_buttons; | ||
104 | #endif | ||
96 | }; | 105 | }; |
97 | 106 | ||
98 | struct edit_state | 107 | struct edit_state |
@@ -272,6 +281,11 @@ static void kbd_draw_picker(struct keyboard_parameters *pm, | |||
272 | struct screen *sc, struct edit_state *state); | 281 | struct screen *sc, struct edit_state *state); |
273 | static void kbd_draw_edit_line(struct keyboard_parameters *pm, | 282 | static void kbd_draw_edit_line(struct keyboard_parameters *pm, |
274 | struct screen *sc, struct edit_state *state); | 283 | struct screen *sc, struct edit_state *state); |
284 | #ifdef HAVE_TOUCHSCREEN | ||
285 | static void kbd_draw_buttons(struct keyboard_parameters *pm, struct screen *sc); | ||
286 | static int keyboard_touchscreen(struct keyboard_parameters *pm, | ||
287 | struct screen *sc, struct edit_state *state); | ||
288 | #endif | ||
275 | static void kbd_insert_selected(struct keyboard_parameters *pm, | 289 | static void kbd_insert_selected(struct keyboard_parameters *pm, |
276 | struct edit_state *state); | 290 | struct edit_state *state); |
277 | static void kbd_backspace(struct edit_state *state); | 291 | static void kbd_backspace(struct edit_state *state); |
@@ -414,6 +428,10 @@ int kbd_input(char* text, int buflen) | |||
414 | sc->clear_display(); | 428 | sc->clear_display(); |
415 | kbd_draw_picker(pm, sc, &state); | 429 | kbd_draw_picker(pm, sc, &state); |
416 | kbd_draw_edit_line(pm, sc, &state); | 430 | kbd_draw_edit_line(pm, sc, &state); |
431 | #ifdef HAVE_TOUCHSCREEN | ||
432 | if (pm->show_buttons) | ||
433 | kbd_draw_buttons(pm, sc); | ||
434 | #endif | ||
417 | } | 435 | } |
418 | 436 | ||
419 | #ifdef HAVE_BUTTONBAR | 437 | #ifdef HAVE_BUTTONBAR |
@@ -437,6 +455,10 @@ int kbd_input(char* text, int buflen) | |||
437 | #endif | 455 | #endif |
438 | pm = ¶m[button_screen]; | 456 | pm = ¶m[button_screen]; |
439 | sc = &screens[button_screen]; | 457 | sc = &screens[button_screen]; |
458 | #ifdef HAVE_TOUCHSCREEN | ||
459 | if (button == ACTION_TOUCHSCREEN) | ||
460 | button = keyboard_touchscreen(pm, sc, &state); | ||
461 | #endif | ||
440 | 462 | ||
441 | /* Remap some buttons to allow to move | 463 | /* Remap some buttons to allow to move |
442 | * cursor in line edit mode and morse mode. */ | 464 | * cursor in line edit mode and morse mode. */ |
@@ -652,6 +674,12 @@ static void kbd_calc_params(struct keyboard_parameters *pm, | |||
652 | unsigned short ch; | 674 | unsigned short ch; |
653 | int icon_w, sc_w, sc_h, w; | 675 | int icon_w, sc_w, sc_h, w; |
654 | int i, total_lines; | 676 | int i, total_lines; |
677 | #ifdef HAVE_TOUCHSCREEN | ||
678 | int button_h = 0; | ||
679 | bool flippage_button = false; | ||
680 | pm->show_buttons = (sc->screen_type == SCREEN_MAIN && | ||
681 | (touchscreen_get_mode() == TOUCHSCREEN_POINT)); | ||
682 | #endif | ||
655 | 683 | ||
656 | pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI; | 684 | pm->curfont = pm->default_lines ? FONT_SYSFIXED : FONT_UI; |
657 | font = font_get(pm->curfont); | 685 | font = font_get(pm->curfont); |
@@ -664,6 +692,9 @@ static void kbd_calc_params(struct keyboard_parameters *pm, | |||
664 | font = font_get(FONT_SYSFIXED); | 692 | font = font_get(FONT_SYSFIXED); |
665 | pm->font_h = font->height; | 693 | pm->font_h = font->height; |
666 | } | 694 | } |
695 | #ifdef HAVE_TOUCHSCREEN | ||
696 | pm->font_h = GRID_SIZE(sc->screen_type, pm->font_h); | ||
697 | #endif | ||
667 | 698 | ||
668 | /* find max width of keyboard glyphs. | 699 | /* find max width of keyboard glyphs. |
669 | * since we're going to be adding spaces, | 700 | * since we're going to be adding spaces, |
@@ -690,6 +721,9 @@ static void kbd_calc_params(struct keyboard_parameters *pm, | |||
690 | pm->text_w = w; | 721 | pm->text_w = w; |
691 | } | 722 | } |
692 | 723 | ||
724 | #ifdef HAVE_TOUCHSCREEN | ||
725 | pm->font_w = GRID_SIZE(sc->screen_type, pm->font_w); | ||
726 | #endif | ||
693 | /* calculate how many characters to put in a row. */ | 727 | /* calculate how many characters to put in a row. */ |
694 | icon_w = get_icon_width(sc->screen_type); | 728 | icon_w = get_icon_width(sc->screen_type); |
695 | sc_w = sc->getwidth(); | 729 | sc_w = sc->getwidth(); |
@@ -750,6 +784,16 @@ static void kbd_calc_params(struct keyboard_parameters *pm, | |||
750 | 784 | ||
751 | /* calculate pm->pages and pm->lines */ | 785 | /* calculate pm->pages and pm->lines */ |
752 | sc_h = sc->getheight(); | 786 | sc_h = sc->getheight(); |
787 | #ifdef HAVE_TOUCHSCREEN | ||
788 | /* add space for buttons */ | ||
789 | if (pm->show_buttons) | ||
790 | { | ||
791 | /* reserve place for OK/Del/Cancel buttons, use ui font for them */ | ||
792 | button_h = GRID_SIZE(sc->screen_type, sc->getcharheight()); | ||
793 | sc_h -= MAX(MIN_GRID_SIZE*2, button_h); | ||
794 | } | ||
795 | recalc_param: | ||
796 | #endif | ||
753 | pm->lines = (sc_h - BUTTONBAR_HEIGHT) / pm->font_h - 1; | 797 | pm->lines = (sc_h - BUTTONBAR_HEIGHT) / pm->font_h - 1; |
754 | 798 | ||
755 | if (pm->default_lines && pm->lines > pm->default_lines) | 799 | if (pm->default_lines && pm->lines > pm->default_lines) |
@@ -770,9 +814,23 @@ static void kbd_calc_params(struct keyboard_parameters *pm, | |||
770 | total_lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; | 814 | total_lines = (pm->nchars + pm->max_chars - 1) / pm->max_chars; |
771 | pm->pages = (total_lines + pm->lines - 1) / pm->lines; | 815 | pm->pages = (total_lines + pm->lines - 1) / pm->lines; |
772 | pm->lines = (total_lines + pm->pages - 1) / pm->pages; | 816 | pm->lines = (total_lines + pm->pages - 1) / pm->pages; |
817 | #ifdef HAVE_TOUCHSCREEN | ||
818 | if (pm->pages > 1 && pm->show_buttons && !flippage_button) | ||
819 | { | ||
820 | /* add space for flip page button */ | ||
821 | sc_h -= button_h; | ||
822 | flippage_button = true; | ||
823 | goto recalc_param; | ||
824 | } | ||
825 | #endif | ||
773 | 826 | ||
774 | pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin; | 827 | pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin; |
775 | pm->keyboard_margin -= pm->keyboard_margin/2; | 828 | pm->keyboard_margin -= pm->keyboard_margin/2; |
829 | #ifdef HAVE_TOUCHSCREEN | ||
830 | /* flip page button is put between piker and edit line */ | ||
831 | if (flippage_button) | ||
832 | pm->main_y += button_h; | ||
833 | #endif | ||
776 | 834 | ||
777 | #ifdef HAVE_MORSE_INPUT | 835 | #ifdef HAVE_MORSE_INPUT |
778 | pm->old_main_y = sc_h - pm->font_h - BUTTONBAR_HEIGHT; | 836 | pm->old_main_y = sc_h - pm->font_h - BUTTONBAR_HEIGHT; |
@@ -849,14 +907,14 @@ static void kbd_draw_picker(struct keyboard_parameters *pm, | |||
849 | 907 | ||
850 | for (i = j = 0; k < pm->nchars; k++) | 908 | for (i = j = 0; k < pm->nchars; k++) |
851 | { | 909 | { |
852 | int w; | 910 | int w, h; |
853 | unsigned char *utf8; | 911 | unsigned char *utf8; |
854 | utf8 = utf8encode(pm->kbd_buf[k], outline); | 912 | utf8 = utf8encode(pm->kbd_buf[k], outline); |
855 | *utf8 = 0; | 913 | *utf8 = 0; |
856 | 914 | ||
857 | sc->getstringsize(outline, &w, NULL); | 915 | sc->getstringsize(outline, &w, &h); |
858 | sc->putsxy(i*pm->font_w + (pm->font_w-w) / 2, | 916 | sc->putsxy(i*pm->font_w + (pm->font_w-w) / 2, |
859 | j*pm->font_h, outline); | 917 | j*pm->font_h + (pm->font_h-h) / 2, outline); |
860 | 918 | ||
861 | if (++i >= pm->max_chars) | 919 | if (++i >= pm->max_chars) |
862 | { | 920 | { |
@@ -961,6 +1019,113 @@ static void kbd_draw_edit_line(struct keyboard_parameters *pm, | |||
961 | } | 1019 | } |
962 | } | 1020 | } |
963 | 1021 | ||
1022 | #ifdef HAVE_TOUCHSCREEN | ||
1023 | static void kbd_draw_buttons(struct keyboard_parameters *pm, struct screen *sc) | ||
1024 | { | ||
1025 | struct viewport vp; | ||
1026 | int button_h, text_h, text_y; | ||
1027 | int sc_w = sc->getwidth(), sc_h = sc->getheight(); | ||
1028 | viewport_set_defaults(&vp, sc->screen_type); | ||
1029 | vp.flags |= VP_FLAG_ALIGN_CENTER; | ||
1030 | sc->set_viewport(&vp); | ||
1031 | text_h = sc->getcharheight(); | ||
1032 | button_h = GRID_SIZE(sc->screen_type, text_h); | ||
1033 | text_y = (button_h - text_h) / 2 + 1; | ||
1034 | vp.x = 0; | ||
1035 | vp.y = 0; | ||
1036 | vp.width = sc_w; | ||
1037 | vp.height = button_h; | ||
1038 | /* draw buttons */ | ||
1039 | if (pm->pages > 1) | ||
1040 | { | ||
1041 | /* button to flip page. */ | ||
1042 | vp.y = pm->lines*pm->font_h; | ||
1043 | sc->hline(0, sc_w - 1, 0); | ||
1044 | sc->putsxy(0, text_y, ">"); | ||
1045 | } | ||
1046 | /* OK/Del/Cancel buttons */ | ||
1047 | button_h = MAX(MIN_GRID_SIZE*2, button_h); | ||
1048 | text_y = (button_h - text_h) / 2 + 1; | ||
1049 | vp.y = sc_h - button_h - 1; | ||
1050 | vp.height = button_h; | ||
1051 | sc->hline(0, sc_w - 1, 0); | ||
1052 | vp.width = sc_w/3; | ||
1053 | sc->putsxy(0, text_y, str(LANG_KBD_OK)); | ||
1054 | vp.x += vp.width; | ||
1055 | sc->vline(0, 0, button_h); | ||
1056 | sc->putsxy(0, text_y, str(LANG_KBD_DELETE)); | ||
1057 | vp.x += vp.width; | ||
1058 | sc->vline(0, 0, button_h); | ||
1059 | sc->putsxy(0, text_y, str(LANG_KBD_CANCEL)); | ||
1060 | sc->set_viewport(NULL); | ||
1061 | } | ||
1062 | |||
1063 | static int keyboard_touchscreen(struct keyboard_parameters *pm, | ||
1064 | struct screen *sc, struct edit_state *state) | ||
1065 | { | ||
1066 | short x, y; | ||
1067 | const int button = action_get_touchscreen_press(&x, &y); | ||
1068 | const int sc_w = sc->getwidth(), sc_h = sc->getheight(); | ||
1069 | int button_h = MAX(MIN_GRID_SIZE*2, sc->getcharheight()); | ||
1070 | #ifdef HAVE_MORSE_INPUT | ||
1071 | if (state->morse_mode && y < pm->main_y - pm->keyboard_margin) | ||
1072 | { | ||
1073 | /* don't return ACTION_NONE since it has effect in morse mode. */ | ||
1074 | return button == BUTTON_TOUCHSCREEN? ACTION_KBD_SELECT: | ||
1075 | button & BUTTON_REL? ACTION_KBD_MORSE_SELECT: ACTION_STD_OK; | ||
1076 | } | ||
1077 | #else | ||
1078 | (void) state; | ||
1079 | #endif | ||
1080 | if (x < 0 || y < 0) | ||
1081 | return ACTION_NONE; | ||
1082 | if (y < pm->lines*pm->font_h) | ||
1083 | { | ||
1084 | if (x/pm->font_w < pm->max_chars) | ||
1085 | { | ||
1086 | /* picker area */ | ||
1087 | state->changed = CHANGED_PICKER; | ||
1088 | pm->x = x/pm->font_w; | ||
1089 | pm->y = y/pm->font_h; | ||
1090 | pm->line_edit = false; | ||
1091 | if (button == BUTTON_REL) | ||
1092 | return ACTION_KBD_SELECT; | ||
1093 | } | ||
1094 | } | ||
1095 | else if (y < pm->main_y - pm->keyboard_margin) | ||
1096 | { | ||
1097 | /* button to flip page */ | ||
1098 | if (button == BUTTON_REL) | ||
1099 | return ACTION_KBD_PAGE_FLIP; | ||
1100 | } | ||
1101 | else if (y < sc_h - button_h) | ||
1102 | { | ||
1103 | /* edit line */ | ||
1104 | if (button & (BUTTON_REPEAT|BUTTON_REL)) | ||
1105 | { | ||
1106 | if (x < sc_w/2) | ||
1107 | return ACTION_KBD_CURSOR_LEFT; | ||
1108 | else | ||
1109 | return ACTION_KBD_CURSOR_RIGHT; | ||
1110 | } | ||
1111 | } | ||
1112 | else | ||
1113 | { | ||
1114 | /* OK/Del/Cancel button */ | ||
1115 | if (button == BUTTON_REL) | ||
1116 | { | ||
1117 | if (x < sc_w/3) | ||
1118 | return ACTION_KBD_DONE; | ||
1119 | else if (x < (sc_w/3) * 2) | ||
1120 | return ACTION_KBD_BACKSPACE; | ||
1121 | else | ||
1122 | return ACTION_KBD_ABORT; | ||
1123 | } | ||
1124 | } | ||
1125 | return ACTION_NONE; | ||
1126 | } | ||
1127 | #endif | ||
1128 | |||
964 | /* inserts the selected char */ | 1129 | /* inserts the selected char */ |
965 | static void kbd_insert_selected(struct keyboard_parameters *pm, | 1130 | static void kbd_insert_selected(struct keyboard_parameters *pm, |
966 | struct edit_state *state) | 1131 | struct edit_state *state) |