Mercurial > MadButterfly
changeset 306:c981e561ac37
* Keep the font name as the original case.
* Add some new functions for the mb_animated_menu_t widget class.
author | wycc |
---|---|
date | Sat, 21 Feb 2009 21:45:04 +0800 |
parents | 0231b05552fe |
children | b6891068109f |
files | examples/menu/list.svg examples/menu/main.c tools/svg2code.py |
diffstat | 3 files changed, 71 insertions(+), 30 deletions(-) [+] |
line wrap: on
line diff
--- a/examples/menu/list.svg Sun Feb 15 09:19:59 2009 +0800 +++ b/examples/menu/list.svg Sat Feb 21 21:45:04 2009 +0800 @@ -29,10 +29,10 @@ inkscape:pageopacity="0.0" inkscape:pageshadow="2" inkscape:zoom="1.0347223" - inkscape:cx="255.43399" - inkscape:cy="240.5" + inkscape:cx="267.0313" + inkscape:cy="228.90269" inkscape:document-units="px" - inkscape:current-layer="layer1" + inkscape:current-layer="item7" showgrid="false" inkscape:window-width="1124" inkscape:window-height="867" @@ -107,8 +107,9 @@ id="text2395" y="60" x="157.14285" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan + style="font-size:24px;font-style:normal;font-weight:bold;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Times New Roman;-inkscape-font-specification:Times New Roman Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + xml:space="preserve" + sodipodi:linespacing="125%"><tspan mbname="item1text" y="60" x="157.14285" @@ -124,8 +125,9 @@ id="text2421" y="60" x="157.14285" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan + style="font-size:24px;font-style:normal;font-weight:bold;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + xml:space="preserve" + sodipodi:linespacing="125%"><tspan mbname="item2text" y="60" x="157.14285" @@ -141,8 +143,9 @@ id="item3text" y="60" x="157.14285" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan + style="font-size:24px;font-style:normal;font-weight:bold;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + xml:space="preserve" + sodipodi:linespacing="125%"><tspan mbname="item3text" y="60" x="157.14285" @@ -158,8 +161,9 @@ id="item4text" y="60" x="157.14285" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan + style="font-size:24px;font-style:normal;font-weight:bold;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + xml:space="preserve" + sodipodi:linespacing="125%"><tspan mbname="item4text" y="60" x="157.14285" @@ -175,8 +179,9 @@ id="item5text" y="60" x="157.14285" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan + style="font-size:24px;font-style:normal;font-weight:bold;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + xml:space="preserve" + sodipodi:linespacing="125%"><tspan mbname="item5text" y="60" x="157.14285" @@ -192,8 +197,9 @@ id="item6text" y="60" x="157.14285" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan + style="font-size:24px;font-style:normal;font-weight:bold;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + xml:space="preserve" + sodipodi:linespacing="125%"><tspan mbname="item6text" y="60" x="157.14285" @@ -209,8 +215,9 @@ id="item7text" y="60" x="157.14285" - style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans" - xml:space="preserve"><tspan + style="font-size:24px;font-style:oblique;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Oblique;font-stretch:normal;font-variant:normal;text-anchor:start;text-align:start;writing-mode:lr;line-height:125%" + xml:space="preserve" + sodipodi:linespacing="125%"><tspan mbname="item7text" y="60" x="157.14285" @@ -270,11 +277,11 @@ inkscape:label="lightbar"> <g mbname="item_lightbar" - transform="matrix(0.9148913,0,0,1,167.44763,131.37537)" + transform="matrix(0.9148913,0,0,1,167.44763,103.34853)" id="item_lightbar" style="stroke:none"> <rect - style="opacity:0.36697249999999998;fill:#001f41;fill-opacity:1;stroke:none;stroke-width:0.99680871000000004;stroke-opacity:1" + style="opacity:0.3669725;fill:#001f41;fill-opacity:1;stroke:none;stroke-width:0.99680871;stroke-opacity:1" id="rect3191" width="442.8623" height="29.190758"
--- a/examples/menu/main.c Sun Feb 15 09:19:59 2009 +0800 +++ b/examples/menu/main.c Sat Feb 21 21:45:04 2009 +0800 @@ -17,7 +17,7 @@ #include "mbapp.h" -typedef struct { +typedef struct _mb_animated_menu { char **titles; int *menus_y; int *items; @@ -25,10 +25,12 @@ int cur; int max; int ready; + int speed; MBApp *app; mb_sprite_t *sprite; mb_obj_t **objects; mb_obj_t *lightbar; + void (*callback)(struct _mb_animated_menu *m, int sel); } mb_animated_menu_t; char *menus[] = { @@ -52,10 +54,6 @@ "Item 18", }; -int menus_y[10]; -int items[10]; -#define SPEED 300000 - typedef struct { mb_animated_menu_t *m; }MyAppData; @@ -135,7 +133,7 @@ progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); MB_TIMEVAL_SET(&start, 0, 0); - MB_TIMEVAL_SET(&playing, 0, SPEED); + MB_TIMEVAL_SET(&playing, 0, m->speed); word = mb_progm_next_word(progm, &start, &playing); get_now(&now); @@ -158,7 +156,7 @@ lightbar = (coord_t *) m->lightbar; mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word); - MB_TIMEVAL_SET(&start, 0, SPEED); + MB_TIMEVAL_SET(&start, 0, m->speed); MB_TIMEVAL_SET(&playing, 0, 0); word = mb_progm_next_word(progm, &start, &playing); textgroup = (coord_t *) m->objects[m->items[7]]; @@ -196,7 +194,7 @@ progm = mb_progm_new(2, MBAPP_RDMAN(m->app)); MB_TIMEVAL_SET(&start, 0, 0); - MB_TIMEVAL_SET(&playing, 0, SPEED); + MB_TIMEVAL_SET(&playing, 0, m->speed); word = mb_progm_next_word(progm, &start, &playing); get_now(&now); @@ -214,7 +212,7 @@ mb_shift_new(0,m->menus_y[m->cur]-coord_y((coord_t *)m->lightbar),((coord_t *)(m->lightbar)),word); - MB_TIMEVAL_SET(&start, 0, SPEED); + MB_TIMEVAL_SET(&start, 0, m->speed); MB_TIMEVAL_SET(&playing, 0, 0); word = mb_progm_next_word(progm, &start, &playing); mb_visibility_new(VIS_VISIBLE, (coord_t *) m->objects[m->items[0]],word); @@ -241,11 +239,20 @@ progm = mb_progm_new(1, MBAPP_RDMAN(m->app)); MB_TIMEVAL_SET(&start, 0, 0); - MB_TIMEVAL_SET(&playing, 0, SPEED); + MB_TIMEVAL_SET(&playing, 0, m->speed); word = mb_progm_next_word(progm, &start, &playing); get_now(&now); lightbar = (coord_t *) m->lightbar; +#if 1 + // The redraw algorithm has bugs so that the items is not redrawed correctly. We redraw the items under the lightbar to work around it. + // Comment these lines if the algprothm is fixed. + rdman_coord_changed(MBAPP_RDMAN(m->app),m->objects[m->cur]); + if (m->cur != 0) + mb_shift_new(0,0,m->objects[m->cur-1],word); + if (m->cur != 7) + mb_shift_new(0,0,m->objects[m->cur+1],word); +#endif mb_shift_new(0,m->menus_y[m->cur]-coord_y(lightbar),lightbar,word); mb_progm_free_completed(progm); m->ready--; @@ -292,8 +299,15 @@ } } } + +void mb_animated_menu_set_callback(mb_animated_menu_t *m, void (*f)(mb_animated_menu_t *m, int sel)) +{ + m->callback = f; +} void mb_animated_menu_select(mb_animated_menu_t *m) { + if (m->callback) + m->callback(m,m->top+m->cur); } void mb_animated_menu_keyHandler(event_t *ev, void *arg) @@ -355,6 +369,8 @@ m->items = (int *) (m+1); m->menus_y = (int *) (m->items+len); m->objects = (mb_obj_t **) (m->menus_y+len); + m->callback = NULL; + m->speed = 300000; for(i=0;i<9;i++) { m->items[i] = i; snprintf(name,sizeof(name),"%s%d", objnames, i+1); @@ -375,6 +391,23 @@ return m; } + +void mb_animated_menu_set_speed(mb_animated_menu_t *m,int speed) +{ + m->speed = speed*1000; +} + +int mb_animated_menu_get_speed(mb_animated_menu_t *m) +{ + return m->speed/1000; +} + +void myselect(mb_animated_menu_t *m, int select) +{ + printf("menu %d is selected\n", select); +} + + MyApp_InitContent() { MyAppData *data = MBAPP_DATA(myApp,MyAppData); @@ -385,6 +418,7 @@ mb_sprite_t *sprite=myApp->rootsprite; data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",menus); + mb_animated_menu_set_callback(data->m, myselect); } int main(int argc, char * const argv[]) {
--- a/tools/svg2code.py Sun Feb 15 09:19:59 2009 +0800 +++ b/tools/svg2code.py Sat Feb 21 21:45:04 2009 +0800 @@ -489,7 +489,7 @@ pass if style_map.has_key('font-family'): - font_family = style_map['font-family'].lower() + font_family = style_map['font-family'] print >> codefo, 'PANGO_FAMILY(%s,%d,%d)' % (font_family,start,end) pass if style_map.has_key('text-anchor'):