forked from len0rd/rockbox
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
This commit is contained in:
parent
a039091187
commit
aa2972d41b
1 changed files with 103 additions and 31 deletions
|
@ -23,10 +23,8 @@
|
||||||
#include "debug_menu.h"
|
#include "debug_menu.h"
|
||||||
#include "sprintf.h"
|
#include "sprintf.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "bmp.h"
|
|
||||||
#include "icons.h"
|
|
||||||
#include "font.h"
|
#include "font.h"
|
||||||
|
#include "screens.h"
|
||||||
|
|
||||||
#define KEYBOARD_LINES 4
|
#define KEYBOARD_LINES 4
|
||||||
#define KEYBOARD_PAGES 3
|
#define KEYBOARD_PAGES 3
|
||||||
|
@ -45,7 +43,7 @@ static void kbd_setupkeys(char* line[KEYBOARD_LINES], int page)
|
||||||
line[0] = "abcdefg ¢£¤¥¦§©®¬";
|
line[0] = "abcdefg ¢£¤¥¦§©®¬";
|
||||||
line[1] = "hijklmn «»°ºª¹²³¶";
|
line[1] = "hijklmn «»°ºª¹²³¶";
|
||||||
line[2] = "opqrstu ¯±×÷¡¿µ·¨";
|
line[2] = "opqrstu ¯±×÷¡¿µ·¨";
|
||||||
line[3] = "vwxyz ¼½¾ ";
|
line[3] = "vwxyz., ¼½¾ ";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
@ -79,8 +77,10 @@ int kbd_input(char* text, int buflen)
|
||||||
int main_x, main_y, max_chars, margin;
|
int main_x, main_y, max_chars, margin;
|
||||||
int status_y1, status_y2, curpos;
|
int status_y1, status_y2, curpos;
|
||||||
int len;
|
int len;
|
||||||
|
int editpos;
|
||||||
char* line[KEYBOARD_LINES];
|
char* line[KEYBOARD_LINES];
|
||||||
|
|
||||||
|
char outline[256];
|
||||||
char c = 0;
|
char c = 0;
|
||||||
struct font* font = font_get(FONT_SYSFIXED);
|
struct font* font = font_get(FONT_SYSFIXED);
|
||||||
|
|
||||||
|
@ -94,6 +94,8 @@ int kbd_input(char* text, int buflen)
|
||||||
status_y1 = LCD_HEIGHT - font_h;
|
status_y1 = LCD_HEIGHT - font_h;
|
||||||
status_y2 = LCD_HEIGHT;
|
status_y2 = LCD_HEIGHT;
|
||||||
|
|
||||||
|
editpos = strlen(text);
|
||||||
|
|
||||||
max_chars = LCD_WIDTH / font_w;
|
max_chars = LCD_WIDTH / font_w;
|
||||||
kbd_setupkeys(line, page);
|
kbd_setupkeys(line, page);
|
||||||
|
|
||||||
|
@ -111,28 +113,59 @@ int kbd_input(char* text, int buflen)
|
||||||
lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin);
|
lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin);
|
||||||
|
|
||||||
/* write out the text */
|
/* write out the text */
|
||||||
if (len <= max_chars)
|
if (editpos < max_chars - 3 )
|
||||||
{
|
{
|
||||||
/* if we have enough room */
|
strncpy(outline, text, max_chars - 2);
|
||||||
lcd_putsxy(main_x, main_y, text);
|
if (len > max_chars - 2)
|
||||||
curpos = main_x + len * font_w;
|
lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
|
||||||
|
curpos = (1 + editpos) * font_w;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* if we don't have enough room, write out the last bit only */
|
/* not room for all text, cut left, right or both */
|
||||||
lcd_putsxy(0, main_y, "<");
|
if (editpos == len )
|
||||||
lcd_invertrect(0, main_y, font_w, font_h);
|
{
|
||||||
|
if ( max_chars - 3 == len)
|
||||||
lcd_putsxy(font_w, main_y, text + len - (max_chars-1));
|
{
|
||||||
curpos = main_x + max_chars * font_w;
|
strncpy(outline, text, max_chars - 2);
|
||||||
|
curpos = (1 + editpos) * font_w;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strncpy(outline, text + editpos - max_chars + 2,
|
||||||
|
max_chars - 2);
|
||||||
|
if (len > max_chars - 2)
|
||||||
|
lcd_putsxy(0, main_y, "<");
|
||||||
|
curpos = ( max_chars - 1) * font_w;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (len - 1 == editpos)
|
||||||
|
{
|
||||||
|
strncpy(outline, text + editpos - max_chars + 3,
|
||||||
|
max_chars - 2);
|
||||||
|
curpos = ( max_chars - 2) * font_w;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
strncpy(outline, text + editpos - max_chars + 4,
|
||||||
|
max_chars - 2);
|
||||||
|
curpos = ( max_chars - 3) * font_w;
|
||||||
|
}
|
||||||
|
lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
|
||||||
|
lcd_putsxy(0, main_y, "<");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
lcd_putsxy(font_w,main_y,outline);
|
||||||
|
|
||||||
/* cursor */
|
/* cursor */
|
||||||
lcd_drawline(curpos, main_y, curpos, main_y + font_h);
|
lcd_drawline(curpos, main_y, curpos, main_y + font_h);
|
||||||
|
|
||||||
/* draw the status bar */
|
/* draw the status bar */
|
||||||
kbd_draw_statusbar_button(0, "Shift", status_y1, font_w);
|
kbd_draw_statusbar_button(0, "Shift", status_y1, font_w);
|
||||||
kbd_draw_statusbar_button(1, "Cancl", status_y1, font_w);
|
kbd_draw_statusbar_button(1, "OK", status_y1, font_w);
|
||||||
kbd_draw_statusbar_button(2, "Del", status_y1, font_w);
|
kbd_draw_statusbar_button(2, "Del", status_y1, font_w);
|
||||||
|
|
||||||
/* highlight the key that has focus */
|
/* highlight the key that has focus */
|
||||||
|
@ -142,7 +175,6 @@ int kbd_input(char* text, int buflen)
|
||||||
switch ( button_get(true) ) {
|
switch ( button_get(true) ) {
|
||||||
|
|
||||||
case BUTTON_OFF:
|
case BUTTON_OFF:
|
||||||
case BUTTON_F2:
|
|
||||||
/* abort */
|
/* abort */
|
||||||
lcd_setfont(FONT_UI);
|
lcd_setfont(FONT_UI);
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -190,12 +222,21 @@ int kbd_input(char* text, int buflen)
|
||||||
case BUTTON_F3:
|
case BUTTON_F3:
|
||||||
case BUTTON_F3 | BUTTON_REPEAT:
|
case BUTTON_F3 | BUTTON_REPEAT:
|
||||||
/* backspace */
|
/* backspace */
|
||||||
if (len)
|
if (editpos > 0)
|
||||||
text[len-1] = 0;
|
{
|
||||||
|
for (i = editpos; i <= (len - 1);i++)
|
||||||
|
{
|
||||||
|
text[i-1] = text[i];
|
||||||
|
}
|
||||||
|
text[i-1]='\0';
|
||||||
|
editpos--;
|
||||||
|
if (editpos < 0)
|
||||||
|
editpos=0;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case BUTTON_ON:
|
case BUTTON_F2:
|
||||||
/* ON accepts what was entered and continues */
|
/* F2 accepts what was entered and continues */
|
||||||
done = true;
|
done = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -204,9 +245,40 @@ int kbd_input(char* text, int buflen)
|
||||||
if (len<buflen)
|
if (len<buflen)
|
||||||
{
|
{
|
||||||
c = line[y][x];
|
c = line[y][x];
|
||||||
|
if ( editpos == len )
|
||||||
|
{
|
||||||
text[len] = c;
|
text[len] = c;
|
||||||
text[len+1] = 0;
|
text[len+1] = 0;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (i = len ; i + 1 > editpos; i--)
|
||||||
|
text[i+1] = text[i];
|
||||||
|
text[editpos] = c;
|
||||||
|
}
|
||||||
|
editpos++;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BUTTON_ON | BUTTON_RIGHT:
|
||||||
|
case BUTTON_ON | BUTTON_RIGHT | BUTTON_REPEAT:
|
||||||
|
/* moved cursor right */
|
||||||
|
editpos++;
|
||||||
|
if (editpos > len)
|
||||||
|
editpos = len;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BUTTON_ON | BUTTON_LEFT:
|
||||||
|
case BUTTON_ON | BUTTON_LEFT | BUTTON_REPEAT:
|
||||||
|
/* moved cursor left */
|
||||||
|
editpos--;
|
||||||
|
if (editpos < 0)
|
||||||
|
editpos = 0;
|
||||||
|
break;
|
||||||
|
|
||||||
|
case SYS_USB_CONNECTED:
|
||||||
|
usb_screen();
|
||||||
|
lcd_setfont(FONT_SYSFIXED);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue