From d599db8632e2cd967d7df7507665d723b8f74b4e Mon Sep 17 00:00:00 2001 From: bernie Date: Tue, 11 Apr 2006 00:07:33 +0000 Subject: [PATCH] Implemenent MF_SAVESEL flag. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@593 38d2e660-2303-0410-9eaa-f027e97ec537 --- app/demo/demo.c | 29 ++++++++++++++++------------- cfg/compiler.h | 5 +++++ mware/menu.c | 48 ++++++++++++++++++++++++++++++++++++++++++++---- mware/menu.h | 14 +++++++++----- 4 files changed, 74 insertions(+), 22 deletions(-) diff --git a/app/demo/demo.c b/app/demo/demo.c index e40eea0e..fa03616c 100755 --- a/app/demo/demo.c +++ b/app/demo/demo.c @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2006/04/11 00:07:32 bernie + *#* Implemenent MF_SAVESEL flag. + *#* *#* Revision 1.2 2006/03/27 04:49:50 bernie *#* Add bouncing logo demo. *#* @@ -44,27 +47,27 @@ static struct MenuItem settings_items[] = { - { (const_iptr_t)"settings_0", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"settings_1", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"settings_2", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"settings_3", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"settings_4", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"settings_5", MIF_TOGGLE, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"System", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Mouse", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Keyboard", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Networking", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Date & Time",0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Power Saving", MIF_TOGGLE, (MenuHook)0, (iptr_t)0 }, { (const_iptr_t)0, 0, NULL, (iptr_t)0 } }; -static struct Menu settings_menu = { settings_items, "Settings Menu", MF_STICKY, &lcd_bitmap, 0 }; +static struct Menu settings_menu = { settings_items, "Settings Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 }; /*** DISPLAY MENU ****************************/ static struct MenuItem display_items[] = { - { (const_iptr_t)"display_0", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"display_1", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"display_2", 0, (MenuHook)0, (iptr_t)0 }, - { (const_iptr_t)"display_3", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Background", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Colors", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Style", 0, (MenuHook)0, (iptr_t)0 }, + { (const_iptr_t)"Icon Theme", 0, (MenuHook)0, (iptr_t)0 }, { (const_iptr_t)0, 0, NULL, (iptr_t)0 } }; -static struct Menu display_menu = { display_items, "Display Menu", MF_STICKY, &lcd_bitmap, 0 }; +static struct Menu display_menu = { display_items, "Display Menu", MF_SAVESEL, &lcd_bitmap, 0 }; /*** SETUP MENU ******************************/ @@ -77,7 +80,7 @@ static struct MenuItem setup_items[] = { (const_iptr_t)"Setup 3", 0, (MenuHook)NULL, (iptr_t)0 }, { (const_iptr_t)0, 0, NULL, NULL } }; -static struct Menu setup_menu = { setup_items, "Setup Menu", MF_STICKY, &lcd_bitmap, 0 }; +static struct Menu setup_menu = { setup_items, "Setup Menu", MF_STICKY | MF_SAVESEL, &lcd_bitmap, 0 }; /*** MAIN MENU *******************************/ diff --git a/cfg/compiler.h b/cfg/compiler.h index 78a63bdc..028ef3ad 100755 --- a/cfg/compiler.h +++ b/cfg/compiler.h @@ -14,6 +14,9 @@ /*#* *#* $Log$ + *#* Revision 1.19 2006/04/11 00:07:33 bernie + *#* Implemenent MF_SAVESEL flag. + *#* *#* Revision 1.18 2006/03/22 13:34:34 bernie *#* MSVC support. *#* @@ -371,11 +374,13 @@ #define EXTERN_C_BEGIN extern "C" { #define EXTERN_C_END } #define EXTERN_CONST extern const + #define CONST_CAST(TYPE,EXPR) (const_cast(EXPR)) #else #define EXTERN_C extern #define EXTERN_C_BEGIN /* nothing */ #define EXTERN_C_END /* nothing */ #define EXTERN_CONST const + #define CONST_CAST(TYPE,EXPR) ((TYPE)(EXPR)) /* FIXME: How can we suppress the warning in C? */ #endif diff --git a/mware/menu.c b/mware/menu.c index 8fdbcb13..be52b5ff 100755 --- a/mware/menu.c +++ b/mware/menu.c @@ -1,7 +1,7 @@ /*! * \file * @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.6 2006/04/11 00:07:32 bernie + *#* Implemenent MF_SAVESEL flag. + *#* *#* Revision 1.5 2006/03/22 09:49:51 bernie *#* Simplifications from project_grl. *#* @@ -203,11 +206,37 @@ static void menu_layout( int ypos, cnt; const char * PROGMEM title = PTRMSG(menu->title); - ypos = menu->startrow; + ypos = 0; if (title) text_xprintf(menu->bitmap, ypos++, 0, STYLEF_UNDERLINE | STYLEF_BOLD | TEXT_CENTER | TEXT_FILL, title); +#if CONFIG_MENU_SMOOTH + static coord_t yoffset = 0; + static int old_first_item = 0; + if (old_first_item != first_item) + { + if (old_first_item > first_item) + { + if (++yoffset > menu->bitmap->font->height) + { + yoffset = 0; + --old_first_item; + } + } + else + { + if (--yoffset < -menu->bitmap->font->height) + { + yoffset = 0; + ++old_first_item; + } + } + first_item = old_first_item; + } + text_offset(menu->bitmap, 0, yoffset); +#endif + for (cnt = 0; cnt < items_per_page; ++cnt) { const MenuItem *item = &menu->items[first_item + cnt]; @@ -369,14 +398,13 @@ iptr_t menu_handle(const struct Menu *menu) items_per_page = (menu->bitmap->height / menu->bitmap->font->height) - - menu->startrow #if CONFIG_MENU_MENUBAR - 1 /* menu bar labels */ #endif - (menu->title ? 1 : 0); /* Selected item should be a visible entry */ - first_item = selected = menu_next_visible_item(menu, -1); + first_item = selected = menu_next_visible_item(menu, menu->selected - 1); for(;;) { @@ -398,7 +426,11 @@ iptr_t menu_handle(const struct Menu *menu) menu_update_menubar(menu, &mb, selected); #endif +#if CONFIG_MENU_SMOOTH + key = kbd_peek(); +#else key = kbd_get(); +#endif if (key & K_OK) { @@ -415,7 +447,12 @@ iptr_t menu_handle(const struct Menu *menu) /* Return userdata as result */ if (!menu->flags & MF_STICKY) + { + /* Store currently selected item before leaving. */ + if (menu->flags & MF_SAVESEL) + CONST_CAST(struct Menu *, menu)->selected = selected; return item->userdata; + } } else if (key & K_UP) { @@ -427,6 +464,9 @@ iptr_t menu_handle(const struct Menu *menu) } else if (key & K_CANCEL && !(menu->flags & MF_TOPLEVEL)) { + /* Store currently selected item before leaving. */ + if (menu->flags & MF_SAVESEL) + CONST_CAST(struct Menu *, menu)->selected = selected; return 0; } } diff --git a/mware/menu.h b/mware/menu.h index 893a6c72..63aa0e8d 100755 --- a/mware/menu.h +++ b/mware/menu.h @@ -1,7 +1,7 @@ /*! * \file * @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.4 2006/04/11 00:07:32 bernie + *#* Implemenent MF_SAVESEL flag. + *#* *#* Revision 1.3 2006/03/22 09:49:51 bernie *#* Simplifications from project_grl. *#* @@ -106,16 +109,17 @@ typedef struct Menu const_iptr_t title; /*!< Menu title (ID or ptr to string, 0 to disable) */ int flags; /*!< See MF_#? definitions below */ struct Bitmap *bitmap; /*!< Bitmap where the menu is rendered */ - int startrow; /*!< Display starting row */ + int selected; /*!< Initial selection (written to if #MF_SAVESEL is set). */ } Menu; /** * \name Flags for Menu.flags. * \{ */ -#define MF_STICKY BV(0) /*!< Stay in the menu when the items called return */ -#define MF_TOPLEVEL BV(1) /*!< Top-level menu (do not display "back" label) */ -#define MF_ROMITEMS BV(2) /*!< Menu is in ROM (default is RAM) */ +#define MF_STICKY BV(0) /**< Stay in the menu when the items called return */ +#define MF_TOPLEVEL BV(1) /**< Top-level menu (do not display "back" label) */ +#define MF_ROMITEMS BV(2) /**< Menu items are stored in ROM (default is RAM) */ +#define MF_SAVESEL BV(3) /**< Remember the selected item across invocations. */ /* \} */ /* Function prototypes */ -- 2.25.1