1
0
Fork 0
forked from len0rd/rockbox

Cleaned up the menu drawing code, and fixed a bug where the menu entry wasn't spoken if the menu scrolled

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4481 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Linus Nielsen Feltzing 2004-04-09 17:47:18 +00:00
parent fbca8aaa19
commit 361dd29cad

View file

@ -156,17 +156,23 @@ void menu_draw(int m)
int menu_lines = MENU_LINES; int menu_lines = MENU_LINES;
#endif #endif
lcd_clear_display(); /* ...then clean the screen */ lcd_clear_display();
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */ lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */
#endif #endif
/* correct cursor pos if out of screen */ /* Adjust cursor pos if it's below the screen */
if (menus[m].cursor - menus[m].top >= menu_lines) if (menus[m].cursor - menus[m].top >= menu_lines)
menus[m].top++; menus[m].top++;
/* Adjust cursor pos if it's above the screen */
if(menus[m].cursor < menus[m].top)
menus[m].top = menus[m].cursor;
for (i = menus[m].top; for (i = menus[m].top;
(i < menus[m].itemcount) && (i<menus[m].top+menu_lines); (i < menus[m].itemcount) && (i<menus[m].top+menu_lines);
i++) { i++) {
/* We want to scroll the line where the cursor is */
if((menus[m].cursor - menus[m].top)==(i-menus[m].top)) if((menus[m].cursor - menus[m].top)==(i-menus[m].top))
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
if (global_settings.invert_cursor) if (global_settings.invert_cursor)
@ -181,6 +187,7 @@ void menu_draw(int m)
/* place the cursor */ /* place the cursor */
put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true); put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true);
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
if (global_settings.scrollbar && menus[m].itemcount > menu_lines) if (global_settings.scrollbar && menus[m].itemcount > menu_lines)
scrollbar(SCROLLBAR_X, SCROLLBAR_Y, SCROLLBAR_WIDTH - 1, scrollbar(SCROLLBAR_X, SCROLLBAR_Y, SCROLLBAR_WIDTH - 1,
@ -201,52 +208,18 @@ void menu_draw(int m)
*/ */
static void put_cursor(int m, int target) static void put_cursor(int m, int target)
{ {
bool do_update = true; int voice_id;
#ifdef HAVE_LCD_BITMAP
int fw, fh;
int menu_lines;
int height = LCD_HEIGHT;
lcd_setfont(FONT_UI);
lcd_getstringsize("A", &fw, &fh);
if(global_settings.statusbar)
height -= STATUSBAR_HEIGHT;
if(global_settings.buttonbar && menus[m].use_buttonbar)
height -= BUTTONBAR_HEIGHT;
menu_lines = height / fh;
#else
int menu_lines = MENU_LINES;
#endif
put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, false);
menus[m].cursor = target; menus[m].cursor = target;
menu_draw(m); menu_draw(m);
if ( target < menus[m].top ) { /* "say" the entry under the cursor */
menus[m].top--; if(global_settings.talk_menu)
menu_draw(m); {
do_update = false; voice_id = menus[m].items[menus[m].cursor].voice_id;
} if (voice_id >= 0) /* valid ID given? */
else if ( target-menus[m].top > menu_lines-1 ) {
menus[m].top++;
menu_draw(m);
do_update = false;
}
if (do_update && !global_settings.invert_cursor) {
put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true);
lcd_update();
}
if (do_update)
{ /* "say" the entry under the cursor */
int voice_id = menus[m].items[menus[m].cursor].voice_id;
if (voice_id >= 0 && global_settings.talk_menu) /* valid ID given? */
talk_id(voice_id, false); /* say it */ talk_id(voice_id, false); /* say it */
} }
} }
int menu_init(struct menu_item* mitems, int count, int (*callback)(int, int), int menu_init(struct menu_item* mitems, int count, int (*callback)(int, int),
@ -295,7 +268,6 @@ int menu_show(int m)
{ {
bool exit = false; bool exit = false;
int key; int key;
int voice_id;
#ifdef HAVE_LCD_BITMAP #ifdef HAVE_LCD_BITMAP
int fw, fh; int fw, fh;
int menu_lines; int menu_lines;
@ -316,25 +288,23 @@ int menu_show(int m)
menu_lines = height / fh; menu_lines = height / fh;
#endif #endif
menu_draw(m); /* Put the cursor on the first line and draw the menu */
put_cursor(m, 0);
/* say current entry */
voice_id = menus[m].items[menus[m].cursor].voice_id;
if (voice_id >= 0 && global_settings.talk_menu) /* valid ID given? */
talk_id(voice_id, false); /* say it */
while (!exit) { while (!exit) {
key = button_get_w_tmo(HZ/2); key = button_get_w_tmo(HZ/2);
/* /*
* "short-circuit" the default keypresses by running the callback function * "short-circuit" the default keypresses by running the
* callback function
* The callback may return a new key value, often this will be
* BUTTON_NONE or the same key value, but it's perfectly legal
* to "simulate" key presses by returning another value.
*/ */
if( menus[m].callback != NULL ) if( menus[m].callback != NULL )
key = menus[m].callback(key, m); /* make sure there's no match in the switch */ key = menus[m].callback(key, m);
switch( key ) { switch( key ) {
#ifdef HAVE_RECORDER_KEYPAD #ifdef HAVE_RECORDER_KEYPAD