From: bernie Date: Wed, 13 Sep 2006 13:58:33 +0000 (+0000) Subject: Add RenderHook support. X-Git-Tag: 1.0.0~562 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=2a70613911a7b15fea22adc7f2a88bd5bb7b8a19;p=bertos.git Add RenderHook support. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@679 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/gui/menu.c b/gui/menu.c index 756aba53..4583e312 100755 --- a/gui/menu.c +++ b/gui/menu.c @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.8 2006/09/13 13:58:32 bernie + *#* Add RenderHook support. + *#* *#* Revision 1.7 2006/08/01 12:22:46 bernie *#* Mention DevLib license. *#* @@ -57,6 +60,7 @@ *#*/ #include "menu.h" + #include #include #include @@ -88,6 +92,7 @@ #define PTRMSG(x) ((const char *)x) #endif + /* Temporary fake defines for ABORT stuff... */ #define abort_top 0 #define PUSH_ABORT false @@ -159,6 +164,39 @@ static void menu_update_menubar( #endif /* CONFIG_MENU_MENUBAR */ +static void menu_defaultRenderHook(struct Bitmap *bm, int ypos, bool selected, const struct MenuItem *item) +{ + if (item->flags & MIF_CHECKIT) + { + gfx_rectClear(bm, 0, ypos, + bm->font->height, ypos + bm->font->height); + + if (item->flags & MIF_TOGGLE) + gfx_rectDraw(bm, 2, ypos + 2, + bm->font->height - 2, ypos + bm->font->height - 2); + if (item->flags & MIF_CHECKED) + { + gfx_line(bm, + 3, ypos + 3, + bm->font->height - 3, ypos + bm->font->height - 3); + gfx_line(bm, + bm->font->height - 3, ypos + 3, + 3, ypos + bm->font->height - 3); + } + } + +#if CPU_HARVARD + ((item->flags & MIF_RAMLABEL) ? text_xyprintf : text_xyprintf_P) +#else + text_xyprintf +#endif + ( + bm, (item->flags & MIF_CHECKIT) ? bm->font->height : 0, ypos, + selected ? (STYLEF_INVERT | TEXT_FILL) : TEXT_FILL, + PTRMSG(item->label) + ); +} + /** * Show a menu on the display. */ @@ -254,35 +292,11 @@ static void menu_layout( /* Only print visible items */ if (!(item->flags & MIF_HIDDEN)) { - if (item->flags & MIF_CHECKIT) - { - gfx_rectClear(bm, 0, ypos, - bm->font->height, ypos + bm->font->height); + /* Check if a special render function is supplied, otherwise use defaults */ + RenderHook renderhook = (item->flags & MIF_RENDERHOOK) ? (RenderHook)item->label : menu_defaultRenderHook; - if (item->flags & MIF_TOGGLE) - gfx_rectDraw(bm, 2, ypos + 2, - bm->font->height - 2, ypos + bm->font->height - 2); - if (item->flags & MIF_CHECKED) - { - gfx_line(bm, - 3, ypos + 3, - bm->font->height - 3, ypos + bm->font->height - 3); - gfx_line(bm, - bm->font->height - 3, ypos + 3, - 3, ypos + bm->font->height - 3); - } - } - -#if CPU_HARVARD - ((item->flags & MIF_RAMLABEL) ? text_xyprintf : text_xyprintf_P) -#else - text_xyprintf -#endif - ( - bm, (item->flags & MIF_CHECKIT) ? bm->font->height : 0, ypos, - (i == selected) ? (STYLEF_INVERT | TEXT_FILL) : TEXT_FILL, - PTRMSG(item->label) - ); + /* Render menuitem */ + renderhook(menu->bitmap, ypos++, (i == selected), item); ypos += bm->font->height; } diff --git a/gui/menu.h b/gui/menu.h index c46c7615..30ec2c12 100755 --- a/gui/menu.h +++ b/gui/menu.h @@ -16,6 +16,9 @@ /*#* *#* $Log$ + *#* Revision 1.4 2006/09/13 13:58:33 bernie + *#* Add RenderHook support. + *#* *#* Revision 1.3 2006/07/19 12:56:27 bernie *#* Convert to new Doxygen style. *#* @@ -86,6 +89,9 @@ typedef struct MenuItem iptr_t userdata; /**< User data to be passed back to the hook */ } MenuItem; +/** Render hook callback function prototype */ +typedef void (*RenderHook)(struct Bitmap *bitmap, int ypos, bool selected, const struct MenuItem *item); + /** * \name Flags for MenuItem.flags. * \{ @@ -107,6 +113,7 @@ 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 */ +#define MIF_RENDERHOOK BV(14) /**< Menu render function is passed in label field */ /* \} */ /**