summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorLinus Nielsen Feltzing <linus@haxx.se>2004-04-09 17:47:18 +0000
committerLinus Nielsen Feltzing <linus@haxx.se>2004-04-09 17:47:18 +0000
commit361dd29cadda4a5476f20b642aab6cbe3d6877ff (patch)
treefbe2ca1b585668123437770d139a2c1f7a81e0e5 /apps
parentfbca8aaa19d19866fe0eed2241508faace51bf9a (diff)
downloadrockbox-361dd29cadda4a5476f20b642aab6cbe3d6877ff.tar.gz
rockbox-361dd29cadda4a5476f20b642aab6cbe3d6877ff.tar.bz2
rockbox-361dd29cadda4a5476f20b642aab6cbe3d6877ff.zip
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
Diffstat (limited to 'apps')
-rw-r--r--apps/menu.c78
1 files changed, 24 insertions, 54 deletions
diff --git a/apps/menu.c b/apps/menu.c
index eae5ca2021..147d4b2aee 100644
--- a/apps/menu.c
+++ b/apps/menu.c
@@ -156,17 +156,23 @@ void menu_draw(int m)
int menu_lines = MENU_LINES;
#endif
- lcd_clear_display(); /* ...then clean the screen */
+ lcd_clear_display();
#ifdef HAVE_LCD_BITMAP
lcd_setmargins(MARGIN_X,MARGIN_Y); /* leave room for cursor and icon */
#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)
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;
(i < menus[m].itemcount) && (i<menus[m].top+menu_lines);
i++) {
+
+ /* We want to scroll the line where the cursor is */
if((menus[m].cursor - menus[m].top)==(i-menus[m].top))
#ifdef HAVE_LCD_BITMAP
if (global_settings.invert_cursor)
@@ -181,6 +187,7 @@ void menu_draw(int m)
/* place the cursor */
put_cursorxy(CURSOR_X, menus[m].cursor - menus[m].top, true);
+
#ifdef HAVE_LCD_BITMAP
if (global_settings.scrollbar && menus[m].itemcount > menu_lines)
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)
{
- bool do_update = true;
-#ifdef HAVE_LCD_BITMAP
- int fw, fh;
- int menu_lines;
- int height = LCD_HEIGHT;
+ int voice_id;
- 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;
menu_draw(m);
- if ( target < menus[m].top ) {
- menus[m].top--;
- menu_draw(m);
- do_update = false;
- }
- 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? */
+ /* "say" the entry under the cursor */
+ if(global_settings.talk_menu)
+ {
+ voice_id = menus[m].items[menus[m].cursor].voice_id;
+ if (voice_id >= 0) /* valid ID given? */
talk_id(voice_id, false); /* say it */
}
-
}
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;
int key;
- int voice_id;
#ifdef HAVE_LCD_BITMAP
int fw, fh;
int menu_lines;
@@ -316,25 +288,23 @@ int menu_show(int m)
menu_lines = height / fh;
#endif
- menu_draw(m);
-
- /* 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 */
+ /* Put the cursor on the first line and draw the menu */
+ put_cursor(m, 0);
while (!exit) {
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 )
- key = menus[m].callback(key, m); /* make sure there's no match in the switch */
-
+ key = menus[m].callback(key, m);
+
switch( key ) {
#ifdef HAVE_RECORDER_KEYPAD