/*#*
*#* $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.
*#*
*#*/
#include "menu.h"
-
#include <gfx/gfx.h>
#include <gfx/font.h>
#include <gfx/text.h>
#include <cfg/compiler.h>
#include <cfg/debug.h>
#include <appconfig.h>
+#include <string.h> /* strcpy() */
#if CPU_HARVARD
#include <avr/pgmspace.h> /* strncpy_P() */
#endif
-#include <string.h> /* strcpy() */
-
#if CONFIG_MENU_MENUBAR
#include "menubar.h"
#endif
#define DO_ABORT do {} while(0)
-#ifdef _DEBUG
/**
* Count the items present in a 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
#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,
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)
{
}
-/*!
+/**
* 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
}
-/*!
+/**
* 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
*/
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
#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
- (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(;;)
{
* 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();
}
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))
{
/*#*
*#* $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.
*#*
/* 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) */
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 */
#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) */
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);