diff options
author | Daniel Stenberg <daniel@haxx.se> | 2003-12-12 13:31:16 +0000 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2003-12-12 13:31:16 +0000 |
commit | c78b30dac867d956a48df96ac4eb73e2372f0fbc (patch) | |
tree | d5ee0656798824e83ea767db425589c1ab99164f /apps/neo/keyboard.c | |
parent | 4009334d332ed7174be0c1556546c3bf8a1d1312 (diff) | |
download | rockbox-c78b30dac867d956a48df96ac4eb73e2372f0fbc.tar.gz rockbox-c78b30dac867d956a48df96ac4eb73e2372f0fbc.zip |
New Neo-specific code from the Open Neo project. Unfortunately, the sources
don't say who've written this stuff so I can give credit to any specific
person (yet). The sources have been modified by me to conform to Rockbox
standards.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4135 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/neo/keyboard.c')
-rw-r--r-- | apps/neo/keyboard.c | 299 |
1 files changed, 299 insertions, 0 deletions
diff --git a/apps/neo/keyboard.c b/apps/neo/keyboard.c new file mode 100644 index 0000000000..9f02f2a9c8 --- /dev/null +++ b/apps/neo/keyboard.c | |||
@@ -0,0 +1,299 @@ | |||
1 | |||
2 | /*************************************************************************** | ||
3 | * __________ __ ___. | ||
4 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
5 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
6 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
7 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
8 | * \/ \/ \/ \/ \/ | ||
9 | * $Id$ | ||
10 | * | ||
11 | * Copyright (C) 2003 by an Open Neo author (FILL IN) | ||
12 | * | ||
13 | * All files in this archive are subject to the GNU General Public License. | ||
14 | * See the file COPYING in the source tree root for full license agreement. | ||
15 | * | ||
16 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
17 | * KIND, either express or implied. | ||
18 | * | ||
19 | ****************************************************************************/ | ||
20 | #include <string.h> | ||
21 | |||
22 | #include "lcd.h" | ||
23 | #include "button.h" | ||
24 | #include "kernel.h" | ||
25 | #include "version.h" | ||
26 | #include "sprintf.h" | ||
27 | #include "lcd-charset.h" | ||
28 | #include "lang.h" | ||
29 | #include "debug.h" | ||
30 | |||
31 | #define KEYBOARD_MAX_LENGTH 255 | ||
32 | |||
33 | static unsigned char* kbd_screens[3] = { | ||
34 | "ABCDEFGHIJKLMNOPQRSTUVWXYZ", | ||
35 | "abcdefghijklmnopqrstuvwxyz", | ||
36 | " !\"#$%&'()*+,-./0123456789;<=>?@[]^_`{|}" | ||
37 | }; | ||
38 | |||
39 | static unsigned char* kbd_screens_names[3] = { | ||
40 | "Capitals", | ||
41 | "Small", | ||
42 | "Others" | ||
43 | }; | ||
44 | |||
45 | static void kbd_show_legend( int nb ) | ||
46 | { | ||
47 | char buf[24]; | ||
48 | snprintf(buf, sizeof(buf), "[%s]", kbd_screens_names[nb] ); | ||
49 | lcd_puts( 0, 1, buf ); | ||
50 | lcd_puts( 0, 2, kbd_screens[nb] ); | ||
51 | lcd_puts( 0, 3, &kbd_screens[nb][20] ); | ||
52 | } | ||
53 | |||
54 | /* returns text len | ||
55 | Max = KEYBOARD_MAX_LENGTH characters | ||
56 | */ | ||
57 | int kbd_input( char* text, int buflen ) | ||
58 | { | ||
59 | char* pstart; | ||
60 | char* pcursor; | ||
61 | char* pold; | ||
62 | int bufferlen; | ||
63 | char cursorpos = 0; | ||
64 | int ret = 0; | ||
65 | char buffer[KEYBOARD_MAX_LENGTH+1]; | ||
66 | bool done = false; | ||
67 | int key; | ||
68 | int screen = 0; | ||
69 | int screenidx = -1; | ||
70 | unsigned char * pcurscreen = kbd_screens[0]; | ||
71 | bool ctl; | ||
72 | |||
73 | bufferlen = strlen(text); | ||
74 | |||
75 | if( bufferlen > KEYBOARD_MAX_LENGTH ) | ||
76 | bufferlen = KEYBOARD_MAX_LENGTH; | ||
77 | |||
78 | strncpy( buffer, text, bufferlen ); | ||
79 | buffer[bufferlen] = 0; | ||
80 | |||
81 | lcd_clear_display(); | ||
82 | |||
83 | /* Initial setup */ | ||
84 | lcd_puts( 0, 0, buffer ); | ||
85 | kbd_show_legend( screen ); | ||
86 | lcd_cursor( cursorpos, 0 ); | ||
87 | lcd_write(true,LCD_BLINKCUR); | ||
88 | |||
89 | pstart = pcursor = buffer; | ||
90 | |||
91 | while(!done) { | ||
92 | /* We want all the keys except the releases and the repeats */ | ||
93 | key = button_get(true); | ||
94 | |||
95 | if( key & BUTTON_IR) | ||
96 | ctl = key & (NEO_IR_BUTTON_PLAY|NEO_IR_BUTTON_STOP|NEO_IR_BUTTON_BROWSE); | ||
97 | else | ||
98 | ctl = key & (BUTTON_PLAY|BUTTON_STOP|BUTTON_MENU); | ||
99 | |||
100 | if( ctl ) { | ||
101 | /* These key do not change the first line */ | ||
102 | switch( key ) { | ||
103 | case BUTTON_MENU: | ||
104 | case BUTTON_IR|NEO_IR_BUTTON_BROWSE: | ||
105 | |||
106 | /* Toggle legend screen */ | ||
107 | screen++; | ||
108 | if( screen == 3 ) | ||
109 | screen = 0; | ||
110 | |||
111 | pcurscreen = kbd_screens[screen]; | ||
112 | |||
113 | screenidx = -1; | ||
114 | kbd_show_legend( screen ); | ||
115 | |||
116 | /* Restore cursor */ | ||
117 | lcd_cursor( cursorpos, 0 ); | ||
118 | break; | ||
119 | |||
120 | case BUTTON_PLAY: | ||
121 | case BUTTON_IR|NEO_IR_BUTTON_PLAY: | ||
122 | |||
123 | if( bufferlen ) { | ||
124 | strncpy(text, buffer, bufferlen); | ||
125 | text[bufferlen] = 0; | ||
126 | ret = bufferlen; | ||
127 | } | ||
128 | /* fallthrough */ | ||
129 | |||
130 | case BUTTON_STOP: | ||
131 | case BUTTON_IR|NEO_IR_BUTTON_STOP: | ||
132 | |||
133 | /* Remove blinking cursor */ | ||
134 | lcd_write(true,LCD_OFFCUR); | ||
135 | done = true; | ||
136 | } | ||
137 | } | ||
138 | else { | ||
139 | |||
140 | switch( key ) { | ||
141 | |||
142 | case BUTTON_PROGRAM: | ||
143 | case BUTTON_PROGRAM|BUTTON_REPEAT: | ||
144 | case BUTTON_IR|NEO_IR_BUTTON_PROGRAM: | ||
145 | |||
146 | /* Delete char at pcursor */ | ||
147 | /* Check if we are at the last char */ | ||
148 | |||
149 | if( *(pcursor+1) != 0 ) { | ||
150 | /* move rest of the string to the left in buffer */ | ||
151 | pold = pcursor; | ||
152 | while( *pcursor ){ | ||
153 | *pcursor = *(pcursor+1); | ||
154 | pcursor++; | ||
155 | } | ||
156 | |||
157 | /* Restore position */ | ||
158 | pcursor = pold; | ||
159 | } | ||
160 | else { | ||
161 | *pcursor = 0; | ||
162 | pcursor--; | ||
163 | cursorpos--; | ||
164 | } | ||
165 | |||
166 | bufferlen--; | ||
167 | break; | ||
168 | |||
169 | case BUTTON_IR|NEO_IR_BUTTON_EQ: | ||
170 | case BUTTON_SELECT|BUTTON_LEFT: | ||
171 | |||
172 | /* Insert left */ | ||
173 | |||
174 | if(bufferlen >= KEYBOARD_MAX_LENGTH ) | ||
175 | break; | ||
176 | |||
177 | pold = pcursor; | ||
178 | |||
179 | /* Goto end */ | ||
180 | while( *pcursor ) | ||
181 | pcursor++; | ||
182 | |||
183 | /* Move string content to the right */ | ||
184 | while( pcursor >= pold ){ | ||
185 | *(pcursor+1) = *pcursor; | ||
186 | pcursor--; | ||
187 | } | ||
188 | |||
189 | pcursor = pold; | ||
190 | *pcursor = ' '; | ||
191 | |||
192 | bufferlen++; | ||
193 | break; | ||
194 | |||
195 | case BUTTON_IR|NEO_IR_BUTTON_MUTE: | ||
196 | case BUTTON_SELECT|BUTTON_RIGHT: | ||
197 | |||
198 | /* Insert Right */ | ||
199 | |||
200 | if(bufferlen >= KEYBOARD_MAX_LENGTH ) | ||
201 | break; | ||
202 | |||
203 | pold = pcursor; | ||
204 | |||
205 | /* Goto end */ | ||
206 | while( *pcursor ) | ||
207 | pcursor++; | ||
208 | |||
209 | /* Move string content to the right */ | ||
210 | while( pcursor > pold ){ | ||
211 | *(pcursor+1) = *pcursor; | ||
212 | pcursor--; | ||
213 | } | ||
214 | |||
215 | pcursor = pold; | ||
216 | *(pcursor+1) = ' '; | ||
217 | |||
218 | bufferlen++; | ||
219 | |||
220 | button_add( BUTTON_RIGHT ); | ||
221 | break; | ||
222 | |||
223 | case BUTTON_LEFT: | ||
224 | case BUTTON_REPEAT|BUTTON_LEFT: | ||
225 | case BUTTON_IR|NEO_IR_BUTTON_REWIND: | ||
226 | case BUTTON_IR|NEO_IR_BUTTON_REWIND|BUTTON_REPEAT: | ||
227 | |||
228 | /* Move cursor left. Shift text right if all the way to the | ||
229 | left */ | ||
230 | |||
231 | /* Check for start of string */ | ||
232 | if( pcursor > buffer ) { | ||
233 | |||
234 | screenidx = -1; | ||
235 | cursorpos--; | ||
236 | pcursor--; | ||
237 | |||
238 | /* Check if were going off the screen */ | ||
239 | if( cursorpos == -1 ) { | ||
240 | cursorpos = 0; | ||
241 | |||
242 | /* Shift text right if we are */ | ||
243 | pstart--; | ||
244 | } | ||
245 | } | ||
246 | break; | ||
247 | |||
248 | case BUTTON_RIGHT: | ||
249 | case BUTTON_REPEAT|BUTTON_RIGHT: | ||
250 | case BUTTON_IR|NEO_IR_BUTTON_FFORWARD: | ||
251 | case BUTTON_IR|NEO_IR_BUTTON_FFORWARD|BUTTON_REPEAT: | ||
252 | |||
253 | /* Move cursor right. Shift text left if all the way to | ||
254 | the right */ | ||
255 | |||
256 | /* Check for end of string */ | ||
257 | if( *(pcursor+1) != 0 ) { | ||
258 | screenidx = -1; | ||
259 | cursorpos++; | ||
260 | pcursor++; | ||
261 | |||
262 | /* Check if were going of the screen */ | ||
263 | if( cursorpos == 20 ) { | ||
264 | cursorpos = 19; | ||
265 | |||
266 | /* Shift text left if we are */ | ||
267 | pstart++; | ||
268 | } | ||
269 | } | ||
270 | break; | ||
271 | |||
272 | case BUTTON_UP: | ||
273 | case BUTTON_UP|BUTTON_REPEAT: | ||
274 | case BUTTON_IR|NEO_IR_BUTTON_VOLUP: | ||
275 | case BUTTON_IR|NEO_IR_BUTTON_VOLUP|BUTTON_REPEAT: | ||
276 | screenidx += 2; | ||
277 | /* fallthrough */ | ||
278 | case BUTTON_DOWN: | ||
279 | case BUTTON_DOWN|BUTTON_REPEAT: | ||
280 | case BUTTON_IR|NEO_IR_BUTTON_VOLDN: | ||
281 | case BUTTON_IR|NEO_IR_BUTTON_VOLDN|BUTTON_REPEAT: | ||
282 | screenidx--; | ||
283 | |||
284 | if( screenidx < 0 ) | ||
285 | screenidx = strlen(pcurscreen)-1; | ||
286 | |||
287 | if( pcurscreen[screenidx] == 0 ) | ||
288 | screenidx = 0; | ||
289 | |||
290 | /* Changes the character over the cursor */ | ||
291 | *pcursor = pcurscreen[screenidx]; | ||
292 | } | ||
293 | |||
294 | lcd_puts( 0, 0, pstart); | ||
295 | lcd_cursor( cursorpos, 0 ); | ||
296 | } | ||
297 | } | ||
298 | return ret; | ||
299 | } | ||