summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2003-03-10 15:09:27 +0000
committerBjörn Stenberg <bjorn@haxx.se>2003-03-10 15:09:27 +0000
commitaa2972d41b6a8e98a05cfe391fef47ba6319c175 (patch)
tree818d38b4052206fdcf6222aad26823d22e155624
parenta039091187f40d018b6353b8c13de7a01d3a6fe0 (diff)
downloadrockbox-aa2972d41b6a8e98a05cfe391fef47ba6319c175.tar.gz
rockbox-aa2972d41b6a8e98a05cfe391fef47ba6319c175.zip
Added cursor movement (Alexander Eickhoff's patch, minus some cosmetics.)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3411 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/recorder/keyboard.c134
1 files changed, 103 insertions, 31 deletions
diff --git a/apps/recorder/keyboard.c b/apps/recorder/keyboard.c
index a4958f00af..a76f2342d2 100644
--- a/apps/recorder/keyboard.c
+++ b/apps/recorder/keyboard.c
@@ -23,10 +23,8 @@
23#include "debug_menu.h" 23#include "debug_menu.h"
24#include "sprintf.h" 24#include "sprintf.h"
25#include <string.h> 25#include <string.h>
26
27#include "bmp.h"
28#include "icons.h"
29#include "font.h" 26#include "font.h"
27#include "screens.h"
30 28
31#define KEYBOARD_LINES 4 29#define KEYBOARD_LINES 4
32#define KEYBOARD_PAGES 3 30#define KEYBOARD_PAGES 3
@@ -45,7 +43,7 @@ static void kbd_setupkeys(char* line[KEYBOARD_LINES], int page)
45 line[0] = "abcdefg ¢£¤¥¦§©®¬"; 43 line[0] = "abcdefg ¢£¤¥¦§©®¬";
46 line[1] = "hijklmn «»°ºª¹²³¶"; 44 line[1] = "hijklmn «»°ºª¹²³¶";
47 line[2] = "opqrstu ¯±×÷¡¿µ·¨"; 45 line[2] = "opqrstu ¯±×÷¡¿µ·¨";
48 line[3] = "vwxyz ¼½¾ "; 46 line[3] = "vwxyz., ¼½¾ ";
49 break; 47 break;
50 48
51 case 2: 49 case 2:
@@ -79,8 +77,10 @@ int kbd_input(char* text, int buflen)
79 int main_x, main_y, max_chars, margin; 77 int main_x, main_y, max_chars, margin;
80 int status_y1, status_y2, curpos; 78 int status_y1, status_y2, curpos;
81 int len; 79 int len;
82 char* line[KEYBOARD_LINES]; 80 int editpos;
81 char* line[KEYBOARD_LINES];
83 82
83 char outline[256];
84 char c = 0; 84 char c = 0;
85 struct font* font = font_get(FONT_SYSFIXED); 85 struct font* font = font_get(FONT_SYSFIXED);
86 86
@@ -94,6 +94,8 @@ int kbd_input(char* text, int buflen)
94 status_y1 = LCD_HEIGHT - font_h; 94 status_y1 = LCD_HEIGHT - font_h;
95 status_y2 = LCD_HEIGHT; 95 status_y2 = LCD_HEIGHT;
96 96
97 editpos = strlen(text);
98
97 max_chars = LCD_WIDTH / font_w; 99 max_chars = LCD_WIDTH / font_w;
98 kbd_setupkeys(line, page); 100 kbd_setupkeys(line, page);
99 101
@@ -106,43 +108,73 @@ int kbd_input(char* text, int buflen)
106 lcd_putsxy(0, i * font_h, line[i]); 108 lcd_putsxy(0, i * font_h, line[i]);
107 109
108 len = strlen(text); 110 len = strlen(text);
109 111
110 /* separator */ 112 /* separator */
111 lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin); 113 lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin);
112 114
113 /* write out the text */ 115 /* write out the text */
114 if (len <= max_chars) 116 if (editpos < max_chars - 3 )
115 { 117 {
116 /* if we have enough room */ 118 strncpy(outline, text, max_chars - 2);
117 lcd_putsxy(main_x, main_y, text); 119 if (len > max_chars - 2)
118 curpos = main_x + len * font_w; 120 lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
121 curpos = (1 + editpos) * font_w;
119 } 122 }
120 else 123 else
121 { 124 {
122 /* if we don't have enough room, write out the last bit only */ 125 /* not room for all text, cut left, right or both */
123 lcd_putsxy(0, main_y, "<"); 126 if (editpos == len )
124 lcd_invertrect(0, main_y, font_w, font_h); 127 {
125 128 if ( max_chars - 3 == len)
126 lcd_putsxy(font_w, main_y, text + len - (max_chars-1)); 129 {
127 curpos = main_x + max_chars * font_w; 130 strncpy(outline, text, max_chars - 2);
131 curpos = (1 + editpos) * font_w;
132 }
133 else
134 {
135 strncpy(outline, text + editpos - max_chars + 2,
136 max_chars - 2);
137 if (len > max_chars - 2)
138 lcd_putsxy(0, main_y, "<");
139 curpos = ( max_chars - 1) * font_w;
140 }
141 }
142 else
143 {
144 if (len - 1 == editpos)
145 {
146 strncpy(outline, text + editpos - max_chars + 3,
147 max_chars - 2);
148 curpos = ( max_chars - 2) * font_w;
149 }
150 else
151 {
152 strncpy(outline, text + editpos - max_chars + 4,
153 max_chars - 2);
154 curpos = ( max_chars - 3) * font_w;
155 }
156 lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
157 lcd_putsxy(0, main_y, "<");
158 }
128 } 159 }
129 160
161 lcd_putsxy(font_w,main_y,outline);
162
130 /* cursor */ 163 /* cursor */
131 lcd_drawline(curpos, main_y, curpos, main_y + font_h); 164 lcd_drawline(curpos, main_y, curpos, main_y + font_h);
132 165
133 /* draw the status bar */ 166 /* draw the status bar */
134 kbd_draw_statusbar_button(0, "Shift", status_y1, font_w); 167 kbd_draw_statusbar_button(0, "Shift", status_y1, font_w);
135 kbd_draw_statusbar_button(1, "Cancl", status_y1, font_w); 168 kbd_draw_statusbar_button(1, "OK", status_y1, font_w);
136 kbd_draw_statusbar_button(2, "Del", status_y1, font_w); 169 kbd_draw_statusbar_button(2, "Del", status_y1, font_w);
137 170
138 /* highlight the key that has focus */ 171 /* highlight the key that has focus */
139 lcd_invertrect(font_w * x, font_h * y, font_w, font_h); 172 lcd_invertrect(font_w * x, font_h * y, font_w, font_h);
140 lcd_update(); 173 lcd_update();
141 174
142 switch ( button_get(true) ) { 175 switch ( button_get(true) ) {
143 176
144 case BUTTON_OFF: 177 case BUTTON_OFF:
145 case BUTTON_F2:
146 /* abort */ 178 /* abort */
147 lcd_setfont(FONT_UI); 179 lcd_setfont(FONT_UI);
148 return -1; 180 return -1;
@@ -157,9 +189,9 @@ int kbd_input(char* text, int buflen)
157 189
158 case BUTTON_RIGHT: 190 case BUTTON_RIGHT:
159 case BUTTON_RIGHT | BUTTON_REPEAT: 191 case BUTTON_RIGHT | BUTTON_REPEAT:
160 if (x < (int)strlen(line[y]) - 1) 192 if (x < (int)strlen(line[y]) - 1)
161 x++; 193 x++;
162 else 194 else
163 x = 0; 195 x = 0;
164 break; 196 break;
165 197
@@ -190,12 +222,21 @@ int kbd_input(char* text, int buflen)
190 case BUTTON_F3: 222 case BUTTON_F3:
191 case BUTTON_F3 | BUTTON_REPEAT: 223 case BUTTON_F3 | BUTTON_REPEAT:
192 /* backspace */ 224 /* backspace */
193 if (len) 225 if (editpos > 0)
194 text[len-1] = 0; 226 {
227 for (i = editpos; i <= (len - 1);i++)
228 {
229 text[i-1] = text[i];
230 }
231 text[i-1]='\0';
232 editpos--;
233 if (editpos < 0)
234 editpos=0;
235 }
195 break; 236 break;
196 237
197 case BUTTON_ON: 238 case BUTTON_F2:
198 /* ON accepts what was entered and continues */ 239 /* F2 accepts what was entered and continues */
199 done = true; 240 done = true;
200 break; 241 break;
201 242
@@ -204,10 +245,41 @@ int kbd_input(char* text, int buflen)
204 if (len<buflen) 245 if (len<buflen)
205 { 246 {
206 c = line[y][x]; 247 c = line[y][x];
207 text[len] = c; 248 if ( editpos == len )
208 text[len+1] = 0; 249 {
250 text[len] = c;
251 text[len+1] = 0;
252 }
253 else
254 {
255 for (i = len ; i + 1 > editpos; i--)
256 text[i+1] = text[i];
257 text[editpos] = c;
258 }
259 editpos++;
209 } 260 }
210 break; 261 break;
262
263 case BUTTON_ON | BUTTON_RIGHT:
264 case BUTTON_ON | BUTTON_RIGHT | BUTTON_REPEAT:
265 /* moved cursor right */
266 editpos++;
267 if (editpos > len)
268 editpos = len;
269 break;
270
271 case BUTTON_ON | BUTTON_LEFT:
272 case BUTTON_ON | BUTTON_LEFT | BUTTON_REPEAT:
273 /* moved cursor left */
274 editpos--;
275 if (editpos < 0)
276 editpos = 0;
277 break;
278
279 case SYS_USB_CONNECTED:
280 usb_screen();
281 lcd_setfont(FONT_SYSFIXED);
282 break;
211 } 283 }
212 } 284 }
213 lcd_setfont(FONT_UI); 285 lcd_setfont(FONT_UI);