# HG changeset patch # User wycc # Date 1233476908 -28800 # Node ID 2e97e8082d83871baa90759107d7760877b6953b # Parent 2469f8d2365848a47c6e1e40a35e85f8a24431aa * Fix the symbol definition code which does not assume the id is the same as the mbname. * Add appleTV style list demo. We need to add animation latter. It is staic for now. diff -r 2469f8d23658 -r 2e97e8082d83 configure.ac --- a/configure.ac Sun Feb 01 15:10:18 2009 +0800 +++ b/configure.ac Sun Feb 01 16:28:28 2009 +0800 @@ -42,7 +42,8 @@ examples/svg2code_ex/Makefile examples/tank/Makefile examples/drag/Makefile - examples/dynamic/Makefile + examples/dynamic/Makefile + examples/menu/Makefile src/Makefile include/Makefile inkscape/Makefile diff -r 2469f8d23658 -r 2e97e8082d83 examples/Makefile.am --- a/examples/Makefile.am Sun Feb 01 15:10:18 2009 +0800 +++ b/examples/Makefile.am Sun Feb 01 16:28:28 2009 +0800 @@ -1,1 +1,1 @@ -SUBDIRS = calculator svg2code_ex tank dynamic drag +SUBDIRS = calculator svg2code_ex tank dynamic drag menu diff -r 2469f8d23658 -r 2e97e8082d83 examples/dynamic/Makefile.am --- a/examples/dynamic/Makefile.am Sun Feb 01 15:10:18 2009 +0800 +++ b/examples/dynamic/Makefile.am Sun Feb 01 16:28:28 2009 +0800 @@ -25,7 +25,7 @@ noinst_PROGRAMS = dynamic hello text button.so mytext.so scene.so EXTRA_DIST = menu.svg button.svg -dynamic_SOURCES = main.c mbapp.c mbapp.h mbbutton.c mbbutton.h +dynamic_SOURCES = main.c nodist_dynamic_SOURCES = CPPFLAGS = @pangocairo_CFLAGS@ $(INCLUDES) dynamic_LDFLAGS = @pangocairo_LIBS@ @@ -34,12 +34,12 @@ CLEANFILES = menu.c menu.h menu.mb button.mb -hello_SOURCES = hello.c mbapp.c mbapp.h +hello_SOURCES = hello.c hello_LDFLAGS = @pangocairo_LIBS@ hello_LDADD = $(top_builddir)/src/libmbfly.la -text_SOURCES = text.c mbapp.c mbapp.h +text_SOURCES = text.c text_LDFLAGS = @pangocairo_LIBS@ text_LDADD = $(top_builddir)/src/libmbfly.la diff -r 2469f8d23658 -r 2e97e8082d83 examples/menu/Makefile.am --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/menu/Makefile.am Sun Feb 01 16:28:28 2009 +0800 @@ -0,0 +1,22 @@ +include $(top_srcdir)/config.mk + +#SUFFIXES=.svg .so + +list.so:list.svg + $(top_srcdir)/tools/svg2code.py $< $<.mb + m4 -I $(top_srcdir)/tools mb_c_source.m4 $<.mb > $(<:.svg=.c) + m4 -I $(top_srcdir)/tools mb_c_header.m4 $<.mb > $(<:.svg=.h) + $(MAKE) $(<:.svg=.o) + $(CC) -shared -o $@ $(<:.svg=.o) + +noinst_PROGRAMS = menu +EXTRA_DIST = + +menu_SOURCES = main.c +nodist_dynamic_SOURCES = +CFLAGS = @pangocairo_CFLAGS@ +menu_CFLAGS = @pangocairo_CFLAGS@ +menu_LDFLAGS = @pangocairo_LIBS@ +menu_LDADD = $(top_builddir)/src/libmbfly.la +CLEANFILES = menu.mb menu.c menu.h + diff -r 2469f8d23658 -r 2e97e8082d83 examples/menu/list.svg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/menu/list.svg Sun Feb 01 16:28:28 2009 +0800 @@ -0,0 +1,207 @@ + + + + + + + + + + + image/svg+xml + + + + + + + + item1 + + + item1 + + + item1 + + + item1 + + + item1 + + + item1 + + + item1 + + + item1 + + + + + + diff -r 2469f8d23658 -r 2e97e8082d83 examples/menu/main.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/examples/menu/main.c Sun Feb 01 16:28:28 2009 +0800 @@ -0,0 +1,184 @@ +/*! \file + * + * This is the demo program for the animated menu. We will use to test the MBAF API. + */ +#include +#include +#include +#include "menu.h" +#include "mbapp.h" + +char *menus[] = { + "Item 1", + "Item 2", + "Item 3", + "Item 4", + "Item 5", + "Item 6", + "Item 7", + "Item 8", + "Item 9", + "Item 10", + "Item 11", + "Item 12", + "Item 13", + "Item 14", + "Item 15", + "Item 16", + "Item 17", + "Item 18", +}; + +typedef struct { + int top; + int cur; + int max; +}MyAppData; + +MBApp *myApp; + +static void fillMenuContent() +{ + int i; + MyAppData *data = MBAPP_DATA(myApp,MyAppData); + mb_sprite_t *sprite=myApp->rootsprite; + shape_t *text; + coord_t *group; + coord_t *lightbar; + char name[255]; + + for(i=0;i<8;i++) { + if (i+data->top > data->max) break; + snprintf(name,sizeof(name),"item%dtext", i+1); + text = (shape_t *) MB_SPRITE_GET_OBJ(sprite, name); + if (text == NULL) { + printf("Can not find object %s\n",name); + continue; + } + sh_text_set_text(text,menus[i+data->top]); + rdman_shape_changed(MBAPP_RDMAN(myApp), text); + } + for(;i<8;i++) { + snprintf(name,sizeof(name),"item%dtext", i+1); + text = (shape_t *) MB_SPRITE_GET_OBJ(sprite, name); + if (text == NULL) { + printf("Can not find object %s\n",name); + continue; + } + sh_text_set_text(text,""); + rdman_shape_changed(MBAPP_RDMAN(myApp), text); + } + lightbar = (coord_t *) MB_SPRITE_GET_OBJ(sprite, "lightbar"); + snprintf(name,sizeof(name),"item%d", data->cur+1); + group = (coord_t *) MB_SPRITE_GET_OBJ(sprite, name); + coord_x(lightbar) = coord_x(group); + coord_y(lightbar) = coord_y(group); + rdman_coord_changed(MBAPP_RDMAN(myApp), lightbar); + rdman_redraw_changed(MBAPP_RDMAN(myApp)); +} + +void menu_up() +{ + MyAppData *data = MBAPP_DATA(myApp,MyAppData); + + if (data->cur > 5) + data->cur--; + else { + if (data->top > 0) { + data->top--; + } else { + if (data->cur == 0) + return; + data->cur--; + } + } + fillMenuContent(); +} +void menu_down() +{ + MyAppData *data = MBAPP_DATA(myApp,MyAppData); + + if (data->cur < 5) { + if (data->top+data->cur <= data->max) + data->cur++; + } else { + if ((data->top+8) < data->max) { + data->top++; + } else { + if (data->cur+data->top < data->max-1) + data->cur++; + else + return; + } + printf("top=%d\n",data->top); + } + fillMenuContent(); +} +void menu_select() +{ + MyAppData *data = MBAPP_DATA(myApp,MyAppData); + + printf("menu '%s' is selected\n", menus[data->top+data->cur]); +} + +void keyHandler(event_t *ev, void *arg) +{ + X_kb_event_t *xkey = (X_kb_event_t *)ev; + if(xkey->event.type != EVT_KB_PRESS) { + return; + } + switch(xkey->sym) { + case 0xff51: /* left */ + break; + + case 0xff52: /* up */ + menu_up(); + break; + + case 0xff53: /* right */ + break; + + case 0xff54: /* down */ + menu_down(); + break; + + case 0xff0d: /* enter */ + menu_select(); + break; + default: + return; + } +} + +MyApp_InitContent() +{ + MyAppData *data = MBAPP_DATA(myApp,MyAppData); + subject_t *key = MBAPP_keySubject(myApp); + + data->top = 0; + data->cur = 0; + data->max = sizeof(menus)/sizeof(int)-1; + + fillMenuContent(); + subject_add_observer(key, keyHandler,NULL); +} + +int main(int argc, char * const argv[]) { + subject_t *subject; + mb_obj_t *button; + MyAppData data; + mb_timeval_t tmo,interval; + + if (argc > 1) + myApp = MBApp_Init(argv[1]); + else + myApp = MBApp_Init("list"); + MBApp_setData(myApp,&data); + MyApp_InitContent(); + + MBApp_loop(myApp); + + return 0; +} + +/* vim: set ts=4 */ diff -r 2469f8d23658 -r 2e97e8082d83 include/mbapp.h --- a/include/mbapp.h Sun Feb 01 15:10:18 2009 +0800 +++ b/include/mbapp.h Sun Feb 01 16:28:28 2009 +0800 @@ -6,6 +6,7 @@ redraw_man_t *rdman; mb_sprite_t *rootsprite; mb_obj_t *root; + subject_t *kbevents; void *private; }; MBApp *MBApp_Init(char *module); @@ -14,6 +15,7 @@ void MBApp_loop(MBApp *en); #define MBAPP_DATA(app,type) ((type *) ((app)->private)) #define MBAPP_RDMAN(app) (((MBApp *) app)->rdman) +#define MBAPP_keySubject(app) ((app)->kbevents) #include "mbbutton.h" #endif diff -r 2469f8d23658 -r 2e97e8082d83 src/mbaf/mbapp.c --- a/src/mbaf/mbapp.c Sun Feb 01 15:10:18 2009 +0800 +++ b/src/mbaf/mbapp.c Sun Feb 01 16:28:28 2009 +0800 @@ -9,6 +9,7 @@ app->rt = rt; app->rdman = X_MB_rdman(rt); + app->kbevents = X_MB_kbevents(rt); app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord); rdman_attach_backend(app->rdman, rt); MB_SPRITE_GOTO_SCENE(app->rootsprite, 1); diff -r 2469f8d23658 -r 2e97e8082d83 tools/mb_c_source.m4 --- a/tools/mb_c_source.m4 Sun Feb 01 15:10:18 2009 +0800 +++ b/tools/mb_c_source.m4 Sun Feb 01 16:28:28 2009 +0800 @@ -371,7 +371,7 @@ divert[]dnl ]) -define([Y_ADD_SYMBOL],[[{"$1", MB_SPRITE_OFFSET($1)},]]) +define([Y_ADD_SYMBOL],[[{"$2", MB_SPRITE_OFFSET($1)},]]) define([DECLARE_SYMS], [divert([-1]) define([YIMPORT],[IMPORT(]QUOTE($[]1)[,[Y_])]) diff -r 2469f8d23658 -r 2e97e8082d83 tools/svg2code.py --- a/tools/svg2code.py Sun Feb 01 15:10:18 2009 +0800 +++ b/tools/svg2code.py Sun Feb 01 16:28:28 2009 +0800 @@ -362,7 +362,8 @@ ## \note mbname declare that this node should be in the # symbol table. mbname = obj.getAttribute('mbname') - print >> codefo, 'ADD_SYMBOL([%s])dnl' % (mbname) + id = obj.getAttribute('id') + print >> codefo, 'ADD_SYMBOL([%s],[%s])dnl' % (id,mbname) pass func(obj, coord_id, codefo, doc) pass @@ -572,7 +573,8 @@ ## \note mbname declare that this node should be in the # symbol table. mbname = text.getAttribute('mbname') - print >> codefo, 'ADD_SYMBOL([%s])dnl' % (mbname) + id = text.getAttribute('id') + print >> codefo, 'ADD_SYMBOL([%s],[%s])dnl' % (id,mbname) pass pass