/*#*
*#* $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.
*#*
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 ******************************/
{ (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 *******************************/
/*!
* \file
* <!--
- * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
* Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
* All Rights Reserved.
* -->
/*#*
*#* $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.
*#*
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];
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(;;)
{
menu_update_menubar(menu, &mb, selected);
#endif
+#if CONFIG_MENU_SMOOTH
+ key = kbd_peek();
+#else
key = kbd_get();
+#endif
if (key & K_OK)
{
/* 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)
{
}
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;
}
}
/*!
* \file
* <!--
- * Copyright 2003, 2004 Develer S.r.l. (http://www.develer.com/)
+ * Copyright 2003, 2004, 2006 Develer S.r.l. (http://www.develer.com/)
* Copyright 2000 Bernardo Innocenti <bernie@codewiz.org>
* All Rights Reserved.
* -->
/*#*
*#* $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.
*#*
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 */