diff options
author | Björn Stenberg <bjorn@haxx.se> | 2002-12-04 15:04:43 +0000 |
---|---|---|
committer | Björn Stenberg <bjorn@haxx.se> | 2002-12-04 15:04:43 +0000 |
commit | c8cb6ffcc000b5beb66d77f7a8b18d900b28360f (patch) | |
tree | 6146c849d2aeb8e14140537d74a3e6671c10bb0f | |
parent | b070dd55be61b19a0cf88cd8d8a5b80387c50f31 (diff) | |
download | rockbox-c8cb6ffcc000b5beb66d77f7a8b18d900b28360f.tar.gz rockbox-c8cb6ffcc000b5beb66d77f7a8b18d900b28360f.zip |
Added virtual keyboard for text input, loosely based on John Wood's code
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@2928 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r-- | apps/keyboard.h | 24 | ||||
-rw-r--r-- | apps/player/keyboard.c | 117 | ||||
-rw-r--r-- | apps/recorder/keyboard.c | 206 | ||||
-rw-r--r-- | uisimulator/x11/Makefile | 5 |
4 files changed, 351 insertions, 1 deletions
diff --git a/apps/keyboard.h b/apps/keyboard.h new file mode 100644 index 0000000000..fa1e11e0ce --- /dev/null +++ b/apps/keyboard.h | |||
@@ -0,0 +1,24 @@ | |||
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 | #ifndef _KEYBOARD_H | ||
20 | #define _KEYBOARD_H | ||
21 | |||
22 | int kbd_input(char* buffer, int buflen); | ||
23 | |||
24 | #endif | ||
diff --git a/apps/player/keyboard.c b/apps/player/keyboard.c new file mode 100644 index 0000000000..be0e43b8a9 --- /dev/null +++ b/apps/player/keyboard.c | |||
@@ -0,0 +1,117 @@ | |||
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 | #define KEYBOARD_PAGES 4 | ||
28 | |||
29 | static char* kbd_setupkeys(int page) | ||
30 | { | ||
31 | static char* lines[] = { | ||
32 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
33 | "abcdefghijklmnopqrstuvwxyz", | ||
34 | "01234567890!@#$%&/(){}[]<>", | ||
35 | "+-*_.,:;!?'" | ||
36 | }; | ||
37 | |||
38 | return lines[page]; | ||
39 | } | ||
40 | |||
41 | int kbd_input(char* text, int buflen) | ||
42 | { | ||
43 | bool done = false; | ||
44 | int page=0, x=0; | ||
45 | char* line = kbd_setupkeys(page); | ||
46 | int linelen = strlen(line); | ||
47 | |||
48 | while(!done) | ||
49 | { | ||
50 | int i; | ||
51 | int len = strlen(text); | ||
52 | |||
53 | lcd_clear_display(); | ||
54 | |||
55 | /* draw chars */ | ||
56 | for (i=0; i < 11; i++) | ||
57 | lcd_putc(i, 1, line[i+x]); | ||
58 | |||
59 | /* write out the text */ | ||
60 | if (len <= 11) { | ||
61 | /* if we have enough room */ | ||
62 | lcd_puts(0, 0, text); | ||
63 | } | ||
64 | else { | ||
65 | /* if we don't have enough room, write out the last bit only */ | ||
66 | lcd_putc(0, 0, '<'); | ||
67 | lcd_puts(1, 0, text + len - 10); | ||
68 | } | ||
69 | lcd_update(); | ||
70 | |||
71 | switch ( button_get(true) ) { | ||
72 | |||
73 | case BUTTON_MENU: | ||
74 | /* Page */ | ||
75 | if (++page == KEYBOARD_PAGES) | ||
76 | page = 0; | ||
77 | line = kbd_setupkeys(page); | ||
78 | linelen = strlen(line); | ||
79 | break; | ||
80 | |||
81 | case BUTTON_RIGHT: | ||
82 | if (x < linelen - 1) | ||
83 | x++; | ||
84 | else | ||
85 | x = 0; | ||
86 | break; | ||
87 | |||
88 | case BUTTON_LEFT: | ||
89 | if (x) | ||
90 | x--; | ||
91 | else | ||
92 | x = linelen - 1; | ||
93 | break; | ||
94 | |||
95 | case BUTTON_STOP: | ||
96 | /* backspace */ | ||
97 | if (len) | ||
98 | text[len-1] = 0; | ||
99 | break; | ||
100 | |||
101 | case BUTTON_ON: | ||
102 | /* F2 accepts what was entered and continues */ | ||
103 | done = true; | ||
104 | break; | ||
105 | |||
106 | case BUTTON_PLAY: | ||
107 | /* PLAY inserts the selected char */ | ||
108 | if (len<buflen) | ||
109 | { | ||
110 | text[len] = line[x]; | ||
111 | text[len+1] = 0; | ||
112 | } | ||
113 | break; | ||
114 | } | ||
115 | } | ||
116 | return 0; | ||
117 | } | ||
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 | } | ||
diff --git a/uisimulator/x11/Makefile b/uisimulator/x11/Makefile index ea511474a6..10fc2c532b 100644 --- a/uisimulator/x11/Makefile +++ b/uisimulator/x11/Makefile | |||
@@ -90,7 +90,7 @@ FIRMSRCS = $(LCDSRSC) sprintf.c id3.c debug.c usb.c mpeg.c power.c\ | |||
90 | 90 | ||
91 | APPS = main.c tree.c menu.c credits.c main_menu.c language.c\ | 91 | APPS = main.c tree.c menu.c credits.c main_menu.c language.c\ |
92 | playlist.c wps.c wps-display.c settings.c status.c icons.c\ | 92 | playlist.c wps.c wps-display.c settings.c status.c icons.c\ |
93 | screens.c peakmeter.c viewer.c sleeptimer.c | 93 | screens.c peakmeter.c viewer.c sleeptimer.c keyboard.c |
94 | 94 | ||
95 | MENUS = games_menu.c demo_menu.c settings_menu.c sound_menu.c | 95 | MENUS = games_menu.c demo_menu.c settings_menu.c sound_menu.c |
96 | 96 | ||
@@ -170,6 +170,9 @@ $(OBJDIR)/menu.o: $(APPDIR)/menu.c | |||
170 | $(OBJDIR)/main_menu.o: $(APPDIR)/main_menu.c | 170 | $(OBJDIR)/main_menu.o: $(APPDIR)/main_menu.c |
171 | $(CC) $(APPCFLAGS) -c $< -o $@ | 171 | $(CC) $(APPCFLAGS) -c $< -o $@ |
172 | 172 | ||
173 | $(OBJDIR)/keyboard.o: $(MACHINEDIR)/keyboard.c | ||
174 | $(CC) $(APPCFLAGS) -c $< -o $@ | ||
175 | |||
173 | $(OBJDIR)/language.o: $(APPDIR)/language.c | 176 | $(OBJDIR)/language.o: $(APPDIR)/language.c |
174 | $(CC) $(APPCFLAGS) -c $< -o $@ | 177 | $(CC) $(APPCFLAGS) -c $< -o $@ |
175 | 178 | ||