From 565505abd4f4fe6aec3ac3a8c12f1b55018cb4d3 Mon Sep 17 00:00:00 2001 From: Kjell Ericson Date: Mon, 27 Jan 2003 14:37:03 +0000 Subject: Added a "cursor"-function for the keyvoard. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@3171 a1c6a512-1295-4272-9138-f99709370657 --- apps/player/keyboard.c | 54 +++++++++++++++++++++++++++++-------------- firmware/drivers/lcd-player.c | 35 +++++++++++++++++++++++++++- firmware/drivers/lcd.h | 1 + 3 files changed, 72 insertions(+), 18 deletions(-) diff --git a/apps/player/keyboard.c b/apps/player/keyboard.c index b33dceb..42c0909 100644 --- a/apps/player/keyboard.c +++ b/apps/player/keyboard.c @@ -76,10 +76,11 @@ static unsigned short* kbd_setupkeys(int page, int* len) #define MENU_LINE_INPUT 0 #define MENU_LINE_NEWCHARS 1 -#define MENU_LINE_DELETE 2 -#define MENU_LINE_ACCEPT 3 -#define MENU_LINE_QUIT 4 -#define MENU_LINE_LAST 4 +#define MENU_LINE_BACKSPACE 2 +#define MENU_LINE_DELETE 3 +#define MENU_LINE_ACCEPT 4 +#define MENU_LINE_QUIT 5 +#define MENU_LINE_LAST 5 int kbd_input(char* text, int buflen) { @@ -91,7 +92,6 @@ int kbd_input(char* text, int buflen) int cursor_pos=0; int button_pressed; unsigned char temptext[12]; - bool cursor_on=true; /* Blinking cursor control */ int old_cursor_pos=0; /* Windowed cursor movement */ int left_pos=0; @@ -110,17 +110,11 @@ int kbd_input(char* text, int buflen) p=0; i = left_pos; while (p<10 && line[i]) { - if (i == cursor_pos && cursor_on) - { - temptext[p++]=KEYBOARD_CURSOR; - i++; - } else { - temptext[p++]=text[i++]; - } + temptext[p++]=text[i++]; } temptext[p]=0; lcd_puts(1, 0, temptext); - cursor_on = !cursor_on; + lcd_put_cursor(cursor_pos-left_pos+1, 0, 0x7f); old_cursor_pos=cursor_pos; switch (menu_line) { @@ -136,6 +130,9 @@ int kbd_input(char* text, int buflen) temptext[p]=0; lcd_puts(1, 1, temptext); break; + case MENU_LINE_BACKSPACE: + lcd_puts_scroll(1, 1, "Backspace"); + break; case MENU_LINE_DELETE: lcd_puts_scroll(1, 1, "Delete"); break; @@ -143,7 +140,7 @@ int kbd_input(char* text, int buflen) lcd_puts_scroll(1, 1, "Accept"); break; case MENU_LINE_QUIT: - lcd_puts_scroll(1, 1, "Cancel"); + lcd_puts_scroll(1, 1, "Abort"); break; } if (menu_line==MENU_LINE_INPUT) { @@ -156,7 +153,7 @@ int kbd_input(char* text, int buflen) lcd_update(); - button_pressed=button_get_w_tmo(HZ/2); + button_pressed=button_get(true); switch (menu_line) { case MENU_LINE_INPUT: @@ -167,14 +164,12 @@ int kbd_input(char* text, int buflen) if (cursor_pos0) cursor_pos--; button_pressed=BUTTON_NONE; - cursor_on=true; break; } break; @@ -214,6 +209,27 @@ int kbd_input(char* text, int buflen) } break; + case MENU_LINE_BACKSPACE: + switch (button_pressed) { + case BUTTON_ON: + case BUTTON_PLAY: + case BUTTON_PLAY | BUTTON_REPEAT: + button_pressed=BUTTON_NONE; + if (0 < cursor_pos) { + for (i=--cursor_pos; i<=len; i++) { + text[i]=text[i+1]; + } + } + break; + case BUTTON_STOP: + case BUTTON_STOP | BUTTON_REPEAT: + button_pressed=BUTTON_NONE; + for (i=cursor_pos; i<=len; i++) { + text[i]=text[i+1]; + } + break; + } + break; case MENU_LINE_DELETE: switch (button_pressed) { case BUTTON_ON: @@ -270,12 +286,16 @@ int kbd_input(char* text, int buflen) case BUTTON_RIGHT | BUTTON_REPEAT: if (menu_line0) menu_line--; + else + menu_line=MENU_LINE_LAST; break; } } diff --git a/firmware/drivers/lcd-player.c b/firmware/drivers/lcd-player.c index 0ca551c..a03b1b0 100644 --- a/firmware/drivers/lcd-player.c +++ b/firmware/drivers/lcd-player.c @@ -72,6 +72,17 @@ struct scrollinfo { int direction; /* +1 for right or -1 for left*/ }; +#define MAX_CURSOR_CHARS 8 +struct cursorinfo { + int len; + char text[MAX_CURSOR_CHARS]; + int textpos; + int y_pos; + int x_pos; + int divider; + int downcount; +} cursor; + static void scroll_thread(void); static char scroll_stack[DEFAULT_STACK_SIZE]; static char scroll_name[] = "scroll"; @@ -265,6 +276,7 @@ void lcd_clear_display(void) bool update=false; DEBUGF("lcd_clear_display()\n"); lcd_stop_scroll(); + cursor.len=0; /* Stop cursor */ for (i=0;i<22;i++) update|=lcdx_putc(i%11, i/11, ' '); if (update) @@ -301,6 +313,18 @@ void lcd_puts(int x, int y, unsigned char *string) return lcd_puts_cont_scroll(x, y, string); } +void lcd_put_cursor(int x, int y, char cursor_char) +{ + cursor.text[0]=buffer_xlcd[x][y]; + cursor.text[1]=cursor_char; + cursor.len=2; + cursor.textpos=0; + cursor.y_pos=y; + cursor.x_pos=x; + cursor.downcount=0; + cursor.divider=4; +} + void lcd_putc(int x, int y, unsigned short ch) { bool update; @@ -573,7 +597,16 @@ static void scroll_thread(void) lcd_puts_cont_scroll(s->startx, s->starty, buffer); } } - + if (cursor.len>0) { + if (cursor.downcount--<0) { + cursor.downcount=cursor.divider; + cursor.textpos++; + if (cursor.textpos>=cursor.len) + cursor.textpos=0; + update|=lcdx_putc(cursor.x_pos, cursor.y_pos, + cursor.text[cursor.textpos]); + } + } if (update) { lcd_update(); } diff --git a/firmware/drivers/lcd.h b/firmware/drivers/lcd.h index 6fe07c1..b4623c2 100644 --- a/firmware/drivers/lcd.h +++ b/firmware/drivers/lcd.h @@ -85,6 +85,7 @@ unsigned char lcd_get_locked_pattern(void); void lcd_unlock_pattern(unsigned char pat); void lcd_allow_bidirectional_scrolling(bool on); extern void lcd_bidir_scroll(int threshold); +void lcd_put_cursor(int x, int y, char cursor_char); #endif #if defined(HAVE_LCD_BITMAP) || defined(SIMULATOR) -- cgit v1.1