From 492c82095f185078d3c11f2c61ab72da4953b374 Mon Sep 17 00:00:00 2001 From: bernie Date: Wed, 22 Mar 2006 09:49:51 +0000 Subject: [PATCH] Simplifications from Grillo. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@581 38d2e660-2303-0410-9eaa-f027e97ec537 --- mware/menu.c | 86 +++++++++++++++++++++++++--------------------------- mware/menu.h | 31 ++++++++++++++----- 2 files changed, 64 insertions(+), 53 deletions(-) diff --git a/mware/menu.c b/mware/menu.c index 1349f215..8fdbcb13 100755 --- a/mware/menu.c +++ b/mware/menu.c @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.5 2006/03/22 09:49:51 bernie + *#* Simplifications from project_grl. + *#* *#* Revision 1.4 2006/03/20 17:48:35 bernie *#* Implement support for ROM menus. *#* @@ -72,7 +75,6 @@ *#*/ #include "menu.h" - #include #include #include @@ -80,13 +82,12 @@ #include #include #include +#include /* strcpy() */ #if CPU_HARVARD #include /* strncpy_P() */ #endif -#include /* strcpy() */ - #if CONFIG_MENU_MENUBAR #include "menubar.h" #endif @@ -105,7 +106,6 @@ #define DO_ABORT do {} while(0) -#ifdef _DEBUG /** * Count the items present in a menu. */ @@ -130,8 +130,26 @@ static int menu_count(const struct Menu *menu) return cnt; } -#endif /* _DEBUG */ +#if 0 /* UNUSED */ +/** + * Compute total number of visible entries, which excludes items + * without a label. + */ +static int menu_count_visible(const struct Menu *menu) +{ + struct MenuItem *item; + int visible_entries = 0; + + for (item = menu->items; (item->label || item->hook); ++item) + { + if (!(item->flags & MIF_HIDDEN)) + ++visible_entries; + } + + return visible_entries; +} +#endif #if CONFIG_MENU_MENUBAR @@ -173,8 +191,8 @@ static void menu_update_menubar( #endif /* CONFIG_MENU_MENUBAR */ -/*! - * Show a menu on the LCD display. +/** + * Show a menu on the display. */ static void menu_layout( const struct Menu *menu, @@ -188,7 +206,7 @@ static void menu_layout( ypos = menu->startrow; if (title) - text_xprintf(menu->bitmap, ypos++, 0, STYLEF_BOLD | TEXT_FILL, title); + text_xprintf(menu->bitmap, ypos++, 0, STYLEF_UNDERLINE | STYLEF_BOLD | TEXT_CENTER | TEXT_FILL, title); for (cnt = 0; cnt < items_per_page; ++cnt) { @@ -263,11 +281,12 @@ static void menu_doselect(const struct Menu *menu, struct MenuItem *item) } -/*! +/** * Return the next visible item (rolls back to the first item) */ -static int menu_next_visible_item(const struct Menu *menu, int index, int total) +static int menu_next_visible_item(const struct Menu *menu, int index) { + int total = menu_count(menu); int item_flags; do @@ -291,11 +310,12 @@ static int menu_next_visible_item(const struct Menu *menu, int index, int total) } -/*! +/** * Return the previous visible item (rolls back to the last item) */ -static int menu_prev_visible_item(const struct Menu *menu, int index, int total) +static int menu_prev_visible_item(const struct Menu *menu, int index) { + int total = menu_count(menu); int item_flags; do @@ -324,7 +344,7 @@ static int menu_prev_visible_item(const struct Menu *menu, int index, int total) */ iptr_t menu_handle(const struct Menu *menu) { - uint8_t entries, visible_entries, items_per_page; + uint8_t items_per_page; uint8_t first_item, selected; #if CONFIG_MENU_MENUBAR @@ -347,30 +367,6 @@ iptr_t menu_handle(const struct Menu *menu) #endif /* CONFIG_MENU_MENUBAR */ - /* - * Compute total number of items in menu (entries) and - * the number of visible entries, which excludes items - * without a label. - */ - for (entries = 0, visible_entries = 0; /*NOP*/; ++entries) - { - const MenuItem *item = &menu->items[entries]; -#if CPU_HARVARD - MenuItem ram_item; - if (menu->flags & MF_ROMITEMS) - { - memcpy_P(&ram_item, item, sizeof(ram_item)); - item = &ram_item; - } -#endif - - if (!(item->flags & MIF_HIDDEN)) - ++visible_entries; - - if (!(item->label || item->hook)) - break; - } - items_per_page = (menu->bitmap->height / menu->bitmap->font->height) - menu->startrow @@ -380,7 +376,7 @@ iptr_t menu_handle(const struct Menu *menu) - (menu->title ? 1 : 0); /* Selected item should be a visible entry */ - first_item = selected = menu_next_visible_item(menu, -1, entries); + first_item = selected = menu_next_visible_item(menu, -1); for(;;) { @@ -390,17 +386,17 @@ iptr_t menu_handle(const struct Menu *menu) * Keep selected item visible */ while (selected < first_item) - first_item = menu_prev_visible_item(menu, first_item, entries); + first_item = menu_prev_visible_item(menu, first_item); while (selected >= first_item + items_per_page) - first_item = menu_next_visible_item(menu, first_item, entries); + first_item = menu_next_visible_item(menu, first_item); /* Clear screen */ text_clear(menu->bitmap); menu_layout(menu, first_item, items_per_page, selected); -#if CONFIG_MENU_MENUBAR - menu_update_menubar(menu, &mb, selected); -#endif + #if CONFIG_MENU_MENUBAR + menu_update_menubar(menu, &mb, selected); + #endif key = kbd_get(); @@ -423,11 +419,11 @@ iptr_t menu_handle(const struct Menu *menu) } else if (key & K_UP) { - selected = menu_prev_visible_item(menu, selected, entries); + selected = menu_prev_visible_item(menu, selected); } else if (key & K_DOWN) { - selected = menu_next_visible_item(menu, selected, entries); + selected = menu_next_visible_item(menu, selected); } else if (key & K_CANCEL && !(menu->flags & MF_TOPLEVEL)) { diff --git a/mware/menu.h b/mware/menu.h index 06e41203..893a6c72 100755 --- a/mware/menu.h +++ b/mware/menu.h @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.3 2006/03/22 09:49:51 bernie + *#* Simplifications from project_grl. + *#* *#* Revision 1.2 2006/03/20 17:48:35 bernie *#* Implement support for ROM menus. *#* @@ -57,10 +60,12 @@ /* Fwd decl */ struct Bitmap; -/*! Menu callback function */ +/** Menu callback function */ typedef void (*MenuHook)(iptr_t userdata); -/*! Menu item description */ +/** + * Menu item description. + */ typedef struct MenuItem { const_iptr_t label; /*!< Item label (ID or ptr to string, 0 to disable) */ @@ -69,8 +74,13 @@ typedef struct MenuItem iptr_t userdata; /*!< User data to be passed back to the hook */ } MenuItem; -/*! Flags for MenuItem.flags */ -#define MIF_EXCLUDE_MASK 0x00FF +/** + * \name Flags for MenuItem.flags. + * \{ + */ +#define MIF_EXCLUDE_MASK 0x00FF /**< Mask for mutual exclusion map (shared with priority). */ +#define MIF_PRI_MASK 0x00FF /**< Mask for priority value (shared with mutual exclusion). */ +#define MIF_PRI(x) ((x) & MIF_PRI_MASK) /**< Set menu item priority. */ #define MIF_EXCLUDE_0 BV(0) /*!< Exclude item 0 when this item is checked */ #define MIF_EXCLUDE_1 BV(1) /*!< Exclude item 1 when this item is checked */ #define MIF_EXCLUDE_2 BV(2) /*!< Exclude item 2 when this item is checked */ @@ -85,9 +95,11 @@ typedef struct MenuItem #define MIF_HIDDEN BV(11) /*!< This menu item is not visible */ #define MIF_DISABLED BV(12) /*!< This menu item is not visible */ #define MIF_RAMLABEL BV(13) /*!< Item label is stored in RAM, not in program memory */ +/* \} */ - -/*! Menu description */ +/** + * Menu description. + */ typedef struct Menu { MenuItem *items; /*!< Array of items (end with a NULL hook) */ @@ -97,11 +109,14 @@ typedef struct Menu int startrow; /*!< Display starting row */ } 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) */ - +/* \} */ /* Function prototypes */ iptr_t menu_handle(const struct Menu *menu); -- 2.25.1