forked from len0rd/rockbox
Keyboard rework & fixes: (1) Separator line no longr wraps at the right border. (2) More compact & straightfoward calculation of cursor position & string part. (3) Code cleanup. (4) Also spell the string when characters are deleted.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@5822 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
4e7c201b73
commit
0b31a007bb
1 changed files with 71 additions and 114 deletions
|
@ -19,6 +19,7 @@
|
||||||
#include "lcd.h"
|
#include "lcd.h"
|
||||||
#include "button.h"
|
#include "button.h"
|
||||||
#include "kernel.h"
|
#include "kernel.h"
|
||||||
|
#include "system.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "debug_menu.h"
|
#include "debug_menu.h"
|
||||||
#include "sprintf.h"
|
#include "sprintf.h"
|
||||||
|
@ -74,7 +75,8 @@
|
||||||
|
|
||||||
static void kbd_setupkeys(const char* line[KEYBOARD_LINES], int page)
|
static void kbd_setupkeys(const char* line[KEYBOARD_LINES], int page)
|
||||||
{
|
{
|
||||||
switch (page) {
|
switch (page)
|
||||||
|
{
|
||||||
case 0:
|
case 0:
|
||||||
line[0] = "ABCDEFG !?\" @#$%+'";
|
line[0] = "ABCDEFG !?\" @#$%+'";
|
||||||
line[1] = "HIJKLMN 789 &_()-`";
|
line[1] = "HIJKLMN 789 &_()-`";
|
||||||
|
@ -99,15 +101,13 @@ static void kbd_setupkeys(const char* line[KEYBOARD_LINES], int page)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* helper function to spell a char if voice UI is enabled */
|
/* helper function to spell a char if voice UI is enabled */
|
||||||
void kbd_spellchar(char c)
|
static void kbd_spellchar(char c)
|
||||||
{
|
{
|
||||||
char spell_char[2]; /* store char to pass to talk_spell */
|
static char spell_char[2] = "\0\0"; /* store char to pass to talk_spell */
|
||||||
|
|
||||||
if (global_settings.talk_menu) /* voice UI? */
|
if (global_settings.talk_menu) /* voice UI? */
|
||||||
{
|
{
|
||||||
spell_char[0] = c;
|
spell_char[0] = c;
|
||||||
spell_char[1] = '\0'; /* mark end of char string */
|
|
||||||
|
|
||||||
talk_spell(spell_char, false);
|
talk_spell(spell_char, false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -120,9 +120,9 @@ int kbd_input(char* text, int buflen)
|
||||||
int font_w = 0, font_h = 0, i;
|
int font_w = 0, font_h = 0, i;
|
||||||
int x = 0, y = 0;
|
int x = 0, y = 0;
|
||||||
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;
|
||||||
int len;
|
int len;
|
||||||
int editpos;
|
int editpos, curpos, leftpos;
|
||||||
bool redraw = true;
|
bool redraw = true;
|
||||||
const char* line[KEYBOARD_LINES];
|
const char* line[KEYBOARD_LINES];
|
||||||
#ifdef KBD_MODES
|
#ifdef KBD_MODES
|
||||||
|
@ -146,7 +146,7 @@ int kbd_input(char* text, int buflen)
|
||||||
|
|
||||||
editpos = strlen(text);
|
editpos = strlen(text);
|
||||||
|
|
||||||
max_chars = LCD_WIDTH / font_w;
|
max_chars = LCD_WIDTH / font_w - 2; /* leave room for < and > */
|
||||||
kbd_setupkeys(line, page);
|
kbd_setupkeys(line, page);
|
||||||
|
|
||||||
if (global_settings.talk_menu) /* voice UI? */
|
if (global_settings.talk_menu) /* voice UI? */
|
||||||
|
@ -167,61 +167,24 @@ int kbd_input(char* text, int buflen)
|
||||||
lcd_putsxy(0, 8+i * font_h, line[i]);
|
lcd_putsxy(0, 8+i * font_h, line[i]);
|
||||||
|
|
||||||
/* separator */
|
/* separator */
|
||||||
lcd_drawline(0, main_y - margin, LCD_WIDTH, main_y - margin);
|
lcd_drawline(0, main_y - margin, LCD_WIDTH - 1, main_y - margin);
|
||||||
|
|
||||||
/* write out the text */
|
/* write out the text */
|
||||||
if (editpos < max_chars - 3 )
|
curpos = MIN(editpos, max_chars - MIN(len - editpos, 2));
|
||||||
{
|
leftpos = editpos - curpos;
|
||||||
strncpy(outline, text, max_chars - 2);
|
strncpy(outline, text + leftpos, max_chars);
|
||||||
if (len > max_chars - 2)
|
outline[max_chars] = 0;
|
||||||
lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
|
|
||||||
curpos = (1 + editpos) * font_w;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
/* not room for all text, cut left, right or both */
|
|
||||||
if (editpos == len )
|
|
||||||
{
|
|
||||||
if ( max_chars - 3 == len)
|
|
||||||
{
|
|
||||||
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, "<");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Zero terminate the string */
|
lcd_putsxy(font_w, main_y, outline);
|
||||||
outline[max_chars - 2] = '\0';
|
|
||||||
|
|
||||||
lcd_putsxy(font_w,main_y,outline);
|
if (leftpos)
|
||||||
|
lcd_putsxy(0, main_y, "<");
|
||||||
|
if (len - leftpos > max_chars)
|
||||||
|
lcd_putsxy(LCD_WIDTH - font_w, main_y, ">");
|
||||||
|
|
||||||
/* cursor */
|
/* cursor */
|
||||||
lcd_drawline(curpos, main_y, curpos, main_y + font_h);
|
i = (curpos + 1) * font_w;
|
||||||
|
lcd_drawline(i, main_y, i, main_y + font_h);
|
||||||
|
|
||||||
#if CONFIG_KEYPAD == RECORDER_PAD
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
||||||
/* draw the status bar */
|
/* draw the status bar */
|
||||||
|
@ -264,13 +227,13 @@ int kbd_input(char* text, int buflen)
|
||||||
case BUTTON_RIGHT | BUTTON_REPEAT:
|
case BUTTON_RIGHT | BUTTON_REPEAT:
|
||||||
#ifdef KBD_MODES
|
#ifdef KBD_MODES
|
||||||
if (line_edit) /* right doubles as cursor_right in line_edit */
|
if (line_edit) /* right doubles as cursor_right in line_edit */
|
||||||
|
{
|
||||||
|
if (editpos < len)
|
||||||
{
|
{
|
||||||
editpos++;
|
editpos++;
|
||||||
if (editpos > len)
|
|
||||||
editpos = len;
|
|
||||||
else
|
|
||||||
kbd_spellchar(text[editpos]);
|
kbd_spellchar(text[editpos]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -293,13 +256,13 @@ int kbd_input(char* text, int buflen)
|
||||||
case BUTTON_LEFT | BUTTON_REPEAT:
|
case BUTTON_LEFT | BUTTON_REPEAT:
|
||||||
#ifdef KBD_MODES
|
#ifdef KBD_MODES
|
||||||
if (line_edit) /* left doubles as cursor_left in line_edit */
|
if (line_edit) /* left doubles as cursor_left in line_edit */
|
||||||
|
{
|
||||||
|
if (editpos)
|
||||||
{
|
{
|
||||||
editpos--;
|
editpos--;
|
||||||
if (editpos < 0)
|
|
||||||
editpos = 0;
|
|
||||||
else
|
|
||||||
kbd_spellchar(text[editpos]);
|
kbd_spellchar(text[editpos]);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
|
@ -382,38 +345,34 @@ int kbd_input(char* text, int buflen)
|
||||||
{
|
{
|
||||||
if (editpos > 0)
|
if (editpos > 0)
|
||||||
{
|
{
|
||||||
for (i = editpos; i <= (len - 1);i++)
|
for (i = editpos; i < len; i++)
|
||||||
{
|
|
||||||
text[i-1] = text[i];
|
text[i-1] = text[i];
|
||||||
}
|
text[i-1] = '\0';
|
||||||
text[i-1]='\0';
|
|
||||||
editpos--;
|
editpos--;
|
||||||
if (editpos < 0)
|
|
||||||
editpos=0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
if (len<buflen)
|
if (len < buflen)
|
||||||
{
|
{
|
||||||
c = line[y][x];
|
c = line[y][x];
|
||||||
if ( editpos == len )
|
if (editpos == len)
|
||||||
{
|
{
|
||||||
text[len] = c;
|
text[len] = c;
|
||||||
text[len+1] = 0;
|
text[len+1] = 0;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
for (i = len ; i + 1 > editpos; i--)
|
for (i = len ; i >= editpos; i--)
|
||||||
text[i+1] = text[i];
|
text[i+1] = text[i];
|
||||||
text[editpos] = c;
|
text[editpos] = c;
|
||||||
}
|
}
|
||||||
editpos++;
|
editpos++;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if (global_settings.talk_menu) /* voice UI? */
|
if (global_settings.talk_menu) /* voice UI? */
|
||||||
talk_spell(text, false); /* speak revised text */
|
talk_spell(text, false); /* speak revised text */
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
#ifndef KBD_MODES
|
#ifndef KBD_MODES
|
||||||
|
@ -421,33 +380,31 @@ int kbd_input(char* text, int buflen)
|
||||||
case KBD_BACKSPACE | BUTTON_REPEAT:
|
case KBD_BACKSPACE | BUTTON_REPEAT:
|
||||||
if (editpos > 0)
|
if (editpos > 0)
|
||||||
{
|
{
|
||||||
for (i = editpos; i <= (len - 1);i++)
|
for (i = editpos; i < len; i++)
|
||||||
{
|
|
||||||
text[i-1] = text[i];
|
text[i-1] = text[i];
|
||||||
}
|
text[i-1] = '\0';
|
||||||
text[i-1]='\0';
|
|
||||||
editpos--;
|
editpos--;
|
||||||
if (editpos < 0)
|
|
||||||
editpos=0;
|
|
||||||
}
|
}
|
||||||
|
if (global_settings.talk_menu) /* voice UI? */
|
||||||
|
talk_spell(text, false); /* speak revised text */
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBD_CURSOR_RIGHT:
|
case KBD_CURSOR_RIGHT:
|
||||||
case KBD_CURSOR_RIGHT | BUTTON_REPEAT:
|
case KBD_CURSOR_RIGHT | BUTTON_REPEAT:
|
||||||
|
if (editpos < len)
|
||||||
|
{
|
||||||
editpos++;
|
editpos++;
|
||||||
if (editpos > len)
|
|
||||||
editpos = len;
|
|
||||||
else
|
|
||||||
kbd_spellchar(text[editpos]);
|
kbd_spellchar(text[editpos]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case KBD_CURSOR_LEFT:
|
case KBD_CURSOR_LEFT:
|
||||||
case KBD_CURSOR_LEFT | BUTTON_REPEAT:
|
case KBD_CURSOR_LEFT | BUTTON_REPEAT:
|
||||||
|
if (editpos)
|
||||||
|
{
|
||||||
editpos--;
|
editpos--;
|
||||||
if (editpos < 0)
|
|
||||||
editpos = 0;
|
|
||||||
else
|
|
||||||
kbd_spellchar(text[editpos]);
|
kbd_spellchar(text[editpos]);
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
#endif /* !KBD_MODES */
|
#endif /* !KBD_MODES */
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue