diff options
Diffstat (limited to 'apps/recorder/keyboard.c')
-rw-r--r-- | apps/recorder/keyboard.c | 206 |
1 files changed, 206 insertions, 0 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c new file mode 100644 index 0000000000..431bfb6b19 --- /dev/null +++ b/apps/recorder/keyboard.c | |||
@@ -0,0 +1,206 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2002 by Björn Stenberg | ||
11 | * | ||
12 | * All files in this archive are subject to the GNU General Public License. | ||
13 | * See the file COPYING in the source tree root for full license agreement. | ||
14 | * | ||
15 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
16 | * KIND, either express or implied. | ||
17 | * | ||
18 | ****************************************************************************/ | ||
19 | #include "lcd.h" | ||
20 | #include "button.h" | ||
21 | #include "kernel.h" | ||
22 | #include "version.h" | ||
23 | #include "debug_menu.h" | ||
24 | #include "sprintf.h" | ||
25 | #include <string.h> | ||
26 | |||
27 | #include "bmp.h" | ||
28 | #include "icons.h" | ||
29 | #include "font.h" | ||
30 | |||
31 | #define KEYBOARD_LINES 4 | ||
32 | #define KEYBOARD_PAGES 3 | ||
33 | |||
34 | static void kbd_setupkeys(char* line[KEYBOARD_LINES], int page) | ||
35 | { | ||
36 | switch (page) { | ||
37 | case 0: | ||
38 | line[0] = "ABCDEFG !?\" @#$%+'"; | ||
39 | line[1] = "HIJKLMN 789 &_()-`"; | ||
40 | line[2] = "OPQRSTU 456 §|{}/<"; | ||
41 | line[3] = "VWXYZ.,0123 ~=[]*>"; | ||
42 | break; | ||
43 | |||
44 | case 1: | ||
45 | line[0] = "abcdefg ¢£¤¥¦§©®¬"; | ||
46 | line[1] = "hijklmn «»°ºª¹²³¶"; | ||
47 | line[2] = "opqrsty ¯±×÷¡¿µ·¨"; | ||
48 | line[3] = "vwxyz ¼½¾ "; | ||
49 | break; | ||
50 | |||
51 | case 2: | ||
52 | line[0] = "ÀÁÂÃÄÅÆ ÌÍÎÏ ÈÉÊË"; | ||
53 | line[1] = "àáâãäåæ ìíîï èéêë"; | ||
54 | line[2] = "ÓÒÔÕÖØ ÇÐÞÝß ÙÚÛÜ"; | ||
55 | line[3] = "òóôõöø çðþýÿ ùúûü"; | ||
56 | break; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | static void kbd_draw_statusbar_button(int num, char* caption, int y, int fw) | ||
61 | { | ||
62 | int x, x2, tw, cx; | ||
63 | x = num*(LCD_WIDTH/3); | ||
64 | x2 = (num+1)*(LCD_WIDTH/3); | ||
65 | tw = fw * strlen(caption); | ||
66 | cx = x2 - x; | ||
67 | /* center the text */ | ||
68 | lcd_putsxy((x + (cx/2)) - (tw/2), y, caption); | ||
69 | lcd_invertrect(x, y - 1, (x2-x)-1, LCD_HEIGHT-y+1); | ||
70 | } | ||
71 | |||
72 | int kbd_input(char* text, int buflen) | ||
73 | { | ||
74 | bool done = false; | ||
75 | int page = 0; | ||
76 | |||
77 | int font_w = 0, font_h = 0, i; | ||
78 | int x = 0, y = 0; | ||
79 | int main_x, main_y, max_chars, margin; | ||
80 | int status_y1, status_y2, curpos; | ||
81 | int len; | ||
82 | char* line[KEYBOARD_LINES]; | ||
83 | |||
84 | char c = 0; | ||
85 | struct font* font = font_get(FONT_SYSFIXED); | ||
86 | |||
87 | font_w = font->maxwidth; | ||
88 | font_h = font->height; | ||
89 | |||
90 | margin = 3; | ||
91 | main_y = (KEYBOARD_LINES + 1) * font_h + margin; | ||
92 | main_x = 0; | ||
93 | status_y1 = LCD_HEIGHT - font_h; | ||
94 | status_y2 = LCD_HEIGHT; | ||
95 | |||
96 | max_chars = LCD_WIDTH / font_w; | ||
97 | kbd_setupkeys(line, page); | ||
98 | |||
99 | while(!done) | ||
100 | { | ||
101 | lcd_clear_display(); | ||
102 | |||
103 | /* draw page */ | ||
104 | for (i=0; i < KEYBOARD_LINES; i++) | ||
105 | lcd_putsxy(0, i * font_h, line[i]); | ||
106 | |||
107 | len = strlen(text); | ||
108 | |||
109 | /* separator */ | ||
110 | lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin); | ||
111 | |||
112 | /* write out the text */ | ||
113 | if (len <= max_chars) | ||
114 | { | ||
115 | /* if we have enough room */ | ||
116 | lcd_putsxy(main_x, main_y, text); | ||
117 | curpos = main_x + len * font_w; | ||
118 | } | ||
119 | else | ||
120 | { | ||
121 | /* if we don't have enough room, write out the last bit only */ | ||
122 | lcd_putsxy(0, main_y, "<"); | ||
123 | lcd_invertrect(0, main_y, font_w, font_h); | ||
124 | |||
125 | lcd_putsxy(font_w, main_y, text + len - (max_chars-1)); | ||
126 | curpos = main_x + max_chars * font_w; | ||
127 | } | ||
128 | |||
129 | /* cursor */ | ||
130 | lcd_drawline(curpos, main_y, curpos, main_y + font_h); | ||
131 | |||
132 | /* draw the status bar */ | ||
133 | kbd_draw_statusbar_button(0, "Shift", status_y1, font_w); | ||
134 | kbd_draw_statusbar_button(1, "Done", status_y1, font_w); | ||
135 | kbd_draw_statusbar_button(2, "Del", status_y1, font_w); | ||
136 | |||
137 | /* highlight the key that has focus */ | ||
138 | lcd_invertrect(font_w * x, font_h * y, font_w, font_h); | ||
139 | lcd_update(); | ||
140 | |||
141 | switch ( button_get(true) ) { | ||
142 | |||
143 | case BUTTON_OFF: | ||
144 | /* abort */ | ||
145 | return -1; | ||
146 | break; | ||
147 | |||
148 | case BUTTON_F1: | ||
149 | /* Page */ | ||
150 | if (++page == KEYBOARD_PAGES) | ||
151 | page = 0; | ||
152 | kbd_setupkeys(line, page); | ||
153 | break; | ||
154 | |||
155 | case BUTTON_RIGHT: | ||
156 | if (x < (int)strlen(line[y]) - 1) | ||
157 | x++; | ||
158 | else | ||
159 | x = 0; | ||
160 | break; | ||
161 | |||
162 | case BUTTON_LEFT: | ||
163 | if (x) | ||
164 | x--; | ||
165 | else | ||
166 | x = strlen(line[y]) - 1; | ||
167 | break; | ||
168 | |||
169 | case BUTTON_DOWN: | ||
170 | if (y < KEYBOARD_LINES - 1) | ||
171 | y++; | ||
172 | else | ||
173 | y=0; | ||
174 | break; | ||
175 | |||
176 | case BUTTON_UP: | ||
177 | if (y) | ||
178 | y--; | ||
179 | else | ||
180 | y = KEYBOARD_LINES - 1; | ||
181 | break; | ||
182 | |||
183 | case BUTTON_F3: | ||
184 | /* backspace */ | ||
185 | if (len) | ||
186 | text[len-1] = 0; | ||
187 | break; | ||
188 | |||
189 | case BUTTON_F2: | ||
190 | /* F2 accepts what was entered and continues */ | ||
191 | done = true; | ||
192 | break; | ||
193 | |||
194 | case BUTTON_PLAY: | ||
195 | /* PLAY inserts the selected char */ | ||
196 | if (len<buflen) | ||
197 | { | ||
198 | c = line[y][x]; | ||
199 | text[len] = c; | ||
200 | text[len+1] = 0; | ||
201 | } | ||
202 | break; | ||
203 | } | ||
204 | } | ||
205 | return 0; | ||
206 | } | ||