summaryrefslogtreecommitdiff
path: root/apps/recorder
diff options
context:
space:
mode:
Diffstat (limited to 'apps/recorder')
-rw-r--r--apps/recorder/keyboard.c183
1 files changed, 156 insertions, 27 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
index fd6099c8c6..f06bd9bf7f 100644
--- a/apps/recorder/keyboard.c
+++ b/apps/recorder/keyboard.c
@@ -37,6 +37,7 @@
37#include "viewport.h" 37#include "viewport.h"
38#include "file.h" 38#include "file.h"
39#include "splash.h" 39#include "splash.h"
40#include "core_alloc.h"
40 41
41#ifndef O_BINARY 42#ifndef O_BINARY
42#define O_BINARY 0 43#define O_BINARY 0
@@ -78,8 +79,19 @@
78#define CHANGED_CURSOR 2 79#define CHANGED_CURSOR 2
79#define CHANGED_TEXT 3 80#define CHANGED_TEXT 3
80 81
82static int kbd_vpbuf_handle[NB_SCREENS] = {0};
83
84enum ekbd_viewports
85{
86 eKBD_VP_TEXT = 0,
87 eKBD_VP_PICKER,
88 eKBD_VP_MENU,
89 eKBD_COUNT_VP_COUNT
90};
91
81struct keyboard_parameters 92struct keyboard_parameters
82{ 93{
94 struct viewport *kbd_viewports;
83 unsigned short kbd_buf[KBD_BUF_SIZE]; 95 unsigned short kbd_buf[KBD_BUF_SIZE];
84 unsigned short *kbd_buf_ptr; 96 unsigned short *kbd_buf_ptr;
85 unsigned short max_line_len; 97 unsigned short max_line_len;
@@ -142,6 +154,78 @@ static const unsigned char morse_codes[] = {
142 0x73,0x55,0x4c,0x61,0x5a,0x80 }; 154 0x73,0x55,0x4c,0x61,0x5a,0x80 };
143#endif 155#endif
144 156
157static void keyboard_layout(struct viewport *kbd_vp,
158 struct keyboard_parameters *pm,
159 struct screen *sc)
160{
161 /*Note: viewports are initialized to vp_default by kbd_create_viewports */
162
163 int sc_w = sc->getwidth();
164 int sc_h = sc->getheight();
165
166 /* TEXT */
167 struct viewport *vp = &kbd_vp[eKBD_VP_TEXT];
168 /* make sure height is even for the text box */
169 int text_height = (MAX(pm->font_h, get_icon_height(sc->screen_type)) & ~1) + 2;
170 vp->x = 0; /* LEFT */
171 vp->y = 0; /* TOP */
172 vp->width = sc_w;
173 vp->height = text_height;
174 vp->font = pm->curfont;
175 text_height += vp->x + 3;
176
177 /* MENU */
178 vp = &kbd_vp[eKBD_VP_MENU];
179 int menu_w = 0;//pm->font_w * MENU_CHARS; /* NOT IMPLEMENTED */
180 vp->x = 0; /* LEFT */
181 vp->y = text_height; /* TOP */
182 vp->width = menu_w;
183 vp->height = 0;
184 vp->font = pm->curfont;
185 menu_w += vp->x;
186
187 /* PICKER */
188 vp = &kbd_vp[eKBD_VP_PICKER];
189 vp->x = menu_w; /* LEFT */
190 vp->y = text_height - 2; /* TOP */
191 vp->width = sc_w - menu_w;
192 vp->height = sc_h - vp->y; /* (MAX SIZE) - OVERWRITTEN */
193 vp->font = pm->curfont;
194}
195
196static int kbd_create_viewports(struct keyboard_parameters * kbd_param)
197{
198 struct viewport *vp;
199 size_t bufsz = (sizeof(struct viewport) * 3); /* different for remote??*/
200 int i, h;
201 FOR_NB_SCREENS(l)
202 {
203 h = core_alloc_ex("kbd vp", bufsz, &buflib_ops_locked);
204 if (h <= 0)
205 return h;
206 kbd_vpbuf_handle[l] = h;
207 kbd_param[l].kbd_viewports = ((struct viewport *) core_get_data(h));
208 for (i = 0; i < eKBD_COUNT_VP_COUNT; i++)
209 {
210 vp = &kbd_param[l].kbd_viewports[i];
211 viewport_set_defaults(vp, l);
212 vp->font = FONT_UI;
213 }
214 }
215 return bufsz;
216}
217
218static void kbd_destroy_viewports(void)
219{
220 FOR_NB_SCREENS(l)
221 {
222 if (kbd_vpbuf_handle[l] > 0) /* free old buffer */
223 {
224 kbd_vpbuf_handle[l] = core_free(kbd_vpbuf_handle[l]);
225 }
226 }
227}
228
145/* Loads a custom keyboard into memory 229/* Loads a custom keyboard into memory
146 call with NULL to reset keyboard */ 230 call with NULL to reset keyboard */
147int load_kbd(unsigned char* filename) 231int load_kbd(unsigned char* filename)
@@ -309,8 +393,9 @@ static unsigned short get_kbd_ch(struct keyboard_parameters *pm, int x, int y)
309 k = k * pm->max_chars + x; 393 k = k * pm->max_chars + x;
310 return (*pbuf != 0xFEFF && k < *pbuf)? pbuf[k+1]: ' '; 394 return (*pbuf != 0xFEFF && k < *pbuf)? pbuf[k+1]: ' ';
311} 395}
312 396static void kbd_calc_pm_params(struct keyboard_parameters *pm,
313static void kbd_calc_params(struct keyboard_parameters *pm, 397 struct screen *sc, struct edit_state *state);
398static void kbd_calc_vp_params(struct keyboard_parameters *pm,
314 struct screen *sc, struct edit_state *state); 399 struct screen *sc, struct edit_state *state);
315static void kbd_draw_picker(struct keyboard_parameters *pm, 400static void kbd_draw_picker(struct keyboard_parameters *pm,
316 struct screen *sc, struct edit_state *state); 401 struct screen *sc, struct edit_state *state);
@@ -342,13 +427,18 @@ int kbd_input(char* text, int buflen, unsigned short *kbd)
342 viewportmanager_theme_enable(l, false, NULL); 427 viewportmanager_theme_enable(l, false, NULL);
343 } 428 }
344 429
430 if (kbd_create_viewports(param) <= 0)
431 {
432 splash(HZ * 2,"Error: No Viewport Allocated, OOM?");
433 goto cleanup;
434 }
435
345#ifdef HAVE_TOUCHSCREEN 436#ifdef HAVE_TOUCHSCREEN
346 /* keyboard is unusuable in pointing mode so force 3x3 for now. 437 /* keyboard is unusuable in pointing mode so force 3x3 for now.
347 * TODO - fix properly by using a bigger font and changing the layout */ 438 * TODO - fix properly by using a bigger font and changing the layout */
348 enum touchscreen_mode old_mode = touchscreen_get_mode(); 439 enum touchscreen_mode old_mode = touchscreen_get_mode();
349 touchscreen_set_mode(TOUCHSCREEN_BUTTON); 440 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
350#endif 441#endif
351
352 /* initialize state */ 442 /* initialize state */
353 state.text = text; 443 state.text = text;
354 state.buflen = buflen; 444 state.buflen = buflen;
@@ -443,7 +533,15 @@ int kbd_input(char* text, int buflen, unsigned short *kbd)
443 pm->kbd_buf_ptr = pm->kbd_buf; /* internal layout buffer */ 533 pm->kbd_buf_ptr = pm->kbd_buf; /* internal layout buffer */
444 534
445 struct screen *sc = &screens[l]; 535 struct screen *sc = &screens[l];
446 kbd_calc_params(pm, sc, &state); 536
537 kbd_calc_pm_params(pm, sc, &state);
538
539 keyboard_layout(pm->kbd_viewports, pm, sc);
540 /* have all the params we need lets set up our viewports */
541 kbd_calc_vp_params(pm, sc, &state);
542 /* We want these the same height */
543 pm->kbd_viewports[eKBD_VP_MENU].height = pm->main_y;
544 pm->kbd_viewports[eKBD_VP_PICKER].height = pm->main_y;
447 } 545 }
448 546
449 if (global_settings.talk_menu) /* voice UI? */ 547 if (global_settings.talk_menu) /* voice UI? */
@@ -698,26 +796,23 @@ int kbd_input(char* text, int buflen, unsigned short *kbd)
698 settings_save(); 796 settings_save();
699 } 797 }
700#endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */ 798#endif /* HAVE_MORSE_INPUT && KBD_TOGGLE_INPUT */
701 799cleanup:
702 FOR_NB_SCREENS(l) 800 FOR_NB_SCREENS(l)
703 { 801 {
704 screens[l].setfont(FONT_UI); 802 screens[l].setfont(FONT_UI);
705 viewportmanager_theme_undo(l, false); 803 viewportmanager_theme_undo(l, false);
706 } 804 }
805 kbd_destroy_viewports();
707 return ret; 806 return ret;
708} 807}
709 808static void kbd_calc_pm_params(struct keyboard_parameters *pm,
710static void kbd_calc_params(struct keyboard_parameters *pm,
711 struct screen *sc, struct edit_state *state) 809 struct screen *sc, struct edit_state *state)
712{ 810{
713 struct font* font; 811 struct font* font;
714 const unsigned char *p; 812 const unsigned char *p;
715 unsigned short ch, *pbuf; 813 unsigned short ch, *pbuf;
716 int icon_w, sc_w, sc_h, w; 814 int i, w;
717 int i, total_lines;
718#ifdef HAVE_TOUCHSCREEN 815#ifdef HAVE_TOUCHSCREEN
719 int button_h = 0;
720 bool flippage_button = false;
721 pm->show_buttons = (sc->screen_type == SCREEN_MAIN && 816 pm->show_buttons = (sc->screen_type == SCREEN_MAIN &&
722 (touchscreen_get_mode() == TOUCHSCREEN_POINT)); 817 (touchscreen_get_mode() == TOUCHSCREEN_POINT));
723#endif 818#endif
@@ -765,9 +860,21 @@ static void kbd_calc_params(struct keyboard_parameters *pm,
765#ifdef HAVE_TOUCHSCREEN 860#ifdef HAVE_TOUCHSCREEN
766 pm->font_w = GRID_SIZE(sc->screen_type, pm->font_w); 861 pm->font_w = GRID_SIZE(sc->screen_type, pm->font_w);
767#endif 862#endif
863
864}
865
866static void kbd_calc_vp_params(struct keyboard_parameters *pm,
867 struct screen *sc, struct edit_state *state)
868{
869 (void) state;
870 struct viewport *vp = &pm->kbd_viewports[eKBD_VP_PICKER];
871 int icon_w, sc_w, sc_h;
872 int i, total_lines;
873 unsigned short *pbuf;
768 /* calculate how many characters to put in a row. */ 874 /* calculate how many characters to put in a row. */
769 icon_w = get_icon_width(sc->screen_type); 875 icon_w = get_icon_width(sc->screen_type);
770 sc_w = sc->getwidth(); 876
877 sc_w = vp->width; /**sc->getwidth();**/
771 if (pm->font_w < sc_w / pm->max_line_len) 878 if (pm->font_w < sc_w / pm->max_line_len)
772 pm->font_w = sc_w / pm->max_line_len; 879 pm->font_w = sc_w / pm->max_line_len;
773 pm->max_chars = sc_w / pm->font_w; 880 pm->max_chars = sc_w / pm->font_w;
@@ -776,8 +883,10 @@ static void kbd_calc_params(struct keyboard_parameters *pm,
776 pm->max_chars_text = sc_w / pm->text_w - 2; 883 pm->max_chars_text = sc_w / pm->text_w - 2;
777 884
778 /* calculate pm->pages and pm->lines */ 885 /* calculate pm->pages and pm->lines */
779 sc_h = sc->getheight(); 886 sc_h = vp->height;/**sc->getheight()**/;
780#ifdef HAVE_TOUCHSCREEN 887#ifdef HAVE_TOUCHSCREEN
888 int button_h = 0;
889 bool flippage_button = false;
781 /* add space for buttons */ 890 /* add space for buttons */
782 if (pm->show_buttons) 891 if (pm->show_buttons)
783 { 892 {
@@ -824,7 +933,7 @@ recalc_param:
824 pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin; 933 pm->main_y = pm->font_h*pm->lines + pm->keyboard_margin;
825 pm->keyboard_margin -= pm->keyboard_margin/2; 934 pm->keyboard_margin -= pm->keyboard_margin/2;
826#ifdef HAVE_TOUCHSCREEN 935#ifdef HAVE_TOUCHSCREEN
827 /* flip page button is put between piker and edit line */ 936 /* flip page button is put between picker and edit line */
828 if (flippage_button) 937 if (flippage_button)
829 pm->main_y += button_h; 938 pm->main_y += button_h;
830#endif 939#endif
@@ -843,13 +952,18 @@ recalc_param:
843static void kbd_draw_picker(struct keyboard_parameters *pm, 952static void kbd_draw_picker(struct keyboard_parameters *pm,
844 struct screen *sc, struct edit_state *state) 953 struct screen *sc, struct edit_state *state)
845{ 954{
955 struct viewport *last;
956 struct viewport *vp = &pm->kbd_viewports[eKBD_VP_PICKER];
957 last = sc->set_viewport(vp);
958 sc->clear_viewport();
959
846 char outline[8]; 960 char outline[8];
847#ifdef HAVE_MORSE_INPUT 961#ifdef HAVE_MORSE_INPUT
848 if (state->morse_mode) 962 if (state->morse_mode)
849 { 963 {
850 const int w = 6, h = 8; /* sysfixed font width, height */ 964 const int w = 6, h = 8; /* sysfixed font width, height */
851 int i, j, x, y; 965 int i, j, x, y;
852 int sc_w = sc->getwidth(), sc_h = pm->main_y - pm->keyboard_margin - 1; 966 int sc_w = vp->width, sc_h = vp->height;//pm->main_y - pm->keyboard_margin - 1;
853 967
854 /* Draw morse code screen with sysfont */ 968 /* Draw morse code screen with sysfont */
855 sc->setfont(FONT_SYSFIXED); 969 sc->setfont(FONT_SYSFIXED);
@@ -926,6 +1040,7 @@ static void kbd_draw_picker(struct keyboard_parameters *pm,
926 sc->set_drawmode(DRMODE_SOLID); 1040 sc->set_drawmode(DRMODE_SOLID);
927 } 1041 }
928 } 1042 }
1043 sc->set_viewport(last);
929} 1044}
930 1045
931static void kbd_draw_edit_line(struct keyboard_parameters *pm, 1046static void kbd_draw_edit_line(struct keyboard_parameters *pm,
@@ -933,22 +1048,33 @@ static void kbd_draw_edit_line(struct keyboard_parameters *pm,
933{ 1048{
934 char outline[8]; 1049 char outline[8];
935 unsigned char *utf8; 1050 unsigned char *utf8;
936 int i = 0, j = 0, icon_w, w; 1051 int i = 0, j = 0, w;
937 int sc_w = sc->getwidth(); 1052 int icon_w, icon_y;
938 int y = pm->main_y - pm->keyboard_margin; 1053 struct viewport *last;
1054 struct viewport *vp = &pm->kbd_viewports[eKBD_VP_TEXT];
1055 last = sc->set_viewport(vp);
1056 sc->clear_viewport();
1057 sc->hline(1, vp->width - 1, vp->height - 1);
1058
1059 int sc_w = vp->width;
1060 int y = (vp->height - pm->font_h) / 2;
1061
1062
939 int text_margin = (sc_w - pm->text_w * pm->max_chars_text) / 2; 1063 int text_margin = (sc_w - pm->text_w * pm->max_chars_text) / 2;
940 1064
1065#if 0
941 /* Clear text area one pixel above separator line so any overdraw 1066 /* Clear text area one pixel above separator line so any overdraw
942 doesn't collide */ 1067 doesn't collide */
943 screen_clear_area(sc, 0, y - 1, sc_w, pm->font_h + 6); 1068 screen_clear_area(sc, 0, y - 1, sc_w, pm->font_h + 6);
944 1069
945 sc->hline(0, sc_w - 1, y); 1070 sc->hline(0, sc_w - 1, y);
946 1071#endif
947 /* write out the text */ 1072 /* write out the text */
948 sc->setfont(pm->curfont); 1073 sc->setfont(pm->curfont);
949 1074
950 pm->leftpos = MAX(0, MIN(state->len_utf8, state->editpos + 2) 1075 pm->leftpos = MAX(0, MIN(state->len_utf8, state->editpos + 2)
951 - pm->max_chars_text); 1076 - pm->max_chars_text);
1077
952 pm->curpos = state->editpos - pm->leftpos; 1078 pm->curpos = state->editpos - pm->leftpos;
953 utf8 = state->text + utf8seek(state->text, pm->leftpos); 1079 utf8 = state->text + utf8seek(state->text, pm->leftpos);
954 1080
@@ -958,12 +1084,13 @@ static void kbd_draw_edit_line(struct keyboard_parameters *pm,
958 strlcpy(outline, utf8, j+1); 1084 strlcpy(outline, utf8, j+1);
959 sc->getstringsize(outline, &w, NULL); 1085 sc->getstringsize(outline, &w, NULL);
960 sc->putsxy(text_margin + i*pm->text_w + (pm->text_w-w)/2, 1086 sc->putsxy(text_margin + i*pm->text_w + (pm->text_w-w)/2,
961 pm->main_y, outline); 1087 y, outline);
962 utf8 += j; 1088 utf8 += j;
963 i++; 1089 i++;
964 } 1090 }
965 1091
966 icon_w = get_icon_width(sc->screen_type); 1092 icon_w = get_icon_width(sc->screen_type);
1093 icon_y = (vp->height - get_icon_height(sc->screen_type)) / 2;
967 if (pm->leftpos > 0) 1094 if (pm->leftpos > 0)
968 { 1095 {
969 /* Draw nicer bitmap arrow if room, else settle for "<". */ 1096 /* Draw nicer bitmap arrow if room, else settle for "<". */
@@ -971,12 +1098,12 @@ static void kbd_draw_edit_line(struct keyboard_parameters *pm,
971 { 1098 {
972 screen_put_icon_with_offset(sc, 0, 0, 1099 screen_put_icon_with_offset(sc, 0, 0,
973 (text_margin - icon_w) / 2, 1100 (text_margin - icon_w) / 2,
974 pm->main_y, Icon_Reverse_Cursor); 1101 icon_y, Icon_Reverse_Cursor);
975 } 1102 }
976 else 1103 else
977 { 1104 {
978 sc->getstringsize("<", &w, NULL); 1105 sc->getstringsize("<", &w, NULL);
979 sc->putsxy(text_margin - w, pm->main_y, "<"); 1106 sc->putsxy(text_margin - w, y, "<");
980 } 1107 }
981 } 1108 }
982 1109
@@ -987,11 +1114,11 @@ static void kbd_draw_edit_line(struct keyboard_parameters *pm,
987 { 1114 {
988 screen_put_icon_with_offset(sc, 0, 0, 1115 screen_put_icon_with_offset(sc, 0, 0,
989 sc_w - (text_margin + icon_w) / 2, 1116 sc_w - (text_margin + icon_w) / 2,
990 pm->main_y, Icon_Cursor); 1117 icon_y, Icon_Cursor);
991 } 1118 }
992 else 1119 else
993 { 1120 {
994 sc->putsxy(sc_w - text_margin, pm->main_y, ">"); 1121 sc->putsxy(sc_w - text_margin, y, ">");
995 } 1122 }
996 } 1123 }
997 1124
@@ -999,17 +1126,19 @@ static void kbd_draw_edit_line(struct keyboard_parameters *pm,
999 i = text_margin + pm->curpos * pm->text_w; 1126 i = text_margin + pm->curpos * pm->text_w;
1000 1127
1001 if (state->cur_blink) 1128 if (state->cur_blink)
1002 sc->vline(i, pm->main_y, pm->main_y + pm->font_h - 1); 1129 sc->vline(i, y, y + pm->font_h - 1);
1003 1130
1004 if (state->hangul) /* draw underbar */ 1131 if (state->hangul) /* draw underbar */
1005 sc->hline(i - pm->text_w, i, pm->main_y + pm->font_h - 1); 1132 sc->hline(i - pm->text_w, i, y + pm->font_h - 1);
1006 1133
1007 if (pm->line_edit) 1134 if (pm->line_edit)
1008 { 1135 {
1009 sc->set_drawmode(DRMODE_COMPLEMENT); 1136 sc->set_drawmode(DRMODE_COMPLEMENT);
1010 sc->fillrect(0, y + 2, sc_w, pm->font_h + 2); 1137 sc->fillrect(0, y - 1, sc_w, pm->font_h + 2);
1011 sc->set_drawmode(DRMODE_SOLID); 1138 sc->set_drawmode(DRMODE_SOLID);
1012 } 1139 }
1140
1141 sc->set_viewport(last);
1013} 1142}
1014 1143
1015#ifdef HAVE_TOUCHSCREEN 1144#ifdef HAVE_TOUCHSCREEN