changeset 296:2e97e8082d83

* 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.
author wycc
date Sun, 01 Feb 2009 16:28:28 +0800
parents 2469f8d23658
children e885dc875f30
files configure.ac examples/Makefile.am examples/dynamic/Makefile.am examples/menu/Makefile.am examples/menu/list.svg examples/menu/main.c include/mbapp.h src/mbaf/mbapp.c tools/mb_c_source.m4 tools/svg2code.py
diffstat 10 files changed, 427 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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
--- 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
 
--- /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
+
--- /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 @@
+<?xml version="1.0" encoding="UTF-8" standalone="no"?>
+<!-- Created with Inkscape (http://www.inkscape.org/) -->
+<svg
+   xmlns:ns0="http://madbutterfly.sourceforge.net/DTD/madbutterfly.dtd"
+   xmlns:dc="http://purl.org/dc/elements/1.1/"
+   xmlns:cc="http://creativecommons.org/ns#"
+   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
+   xmlns:svg="http://www.w3.org/2000/svg"
+   xmlns="http://www.w3.org/2000/svg"
+   xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
+   xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
+   width="720"
+   height="480"
+   id="svg2"
+   sodipodi:version="0.32"
+   inkscape:version="0.46"
+   sodipodi:docname="list.svg"
+   version="1.0"
+   inkscape:output_extension="org.inkscape.output.svg.inkscape">
+  <sodipodi:namedview
+     id="base"
+     pagecolor="#ffffff"
+     bordercolor="#666666"
+     borderopacity="1.0"
+     gridtolerance="10000"
+     guidetolerance="10"
+     objecttolerance="10"
+     inkscape:pageopacity="0.0"
+     inkscape:pageshadow="2"
+     inkscape:zoom="0.7"
+     inkscape:cx="375"
+     inkscape:cy="177.14286"
+     inkscape:document-units="px"
+     inkscape:current-layer="lightbar"
+     showgrid="false"
+     inkscape:window-width="1124"
+     inkscape:window-height="867"
+     inkscape:window-x="212"
+     inkscape:window-y="90" />
+  <defs
+     id="defs4">
+    <inkscape:perspective
+       id="perspective10"
+       inkscape:persp3d-origin="372.04724 : 350.78739 : 1"
+       inkscape:vp_z="744.09448 : 526.18109 : 1"
+       inkscape:vp_y="0 : 1000 : 0"
+       inkscape:vp_x="0 : 526.18109 : 1"
+       sodipodi:type="inkscape:persp3d" />
+  </defs>
+  <metadata
+     id="metadata7">
+    <rdf:RDF>
+      <cc:Work
+         rdf:about="">
+        <dc:format>image/svg+xml</dc:format>
+        <dc:type
+           rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
+      </cc:Work>
+    </rdf:RDF>
+    <ns0:scenes
+       current="1" />
+  </metadata>
+  <g
+     id="layer1"
+     inkscape:groupmode="layer"
+     inkscape:label="Layer 1">
+    <g
+       id="item1"
+       mbname="item1">
+      <text
+         id="text2395"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item1text"
+           y="60"
+           x="157.14285"
+           id="tspan2397"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       transform="translate(-0.4896719,34.661551)"
+       id="item2"
+       mbname="item2">
+      <text
+         id="text2421"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item2text"
+           y="60"
+           x="157.14285"
+           id="tspan2423"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       transform="translate(1.1837399,71.616487)"
+       id="item3"
+       mbname="item3">
+      <text
+         id="item3text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item3text"
+           y="60"
+           x="157.14285"
+           id="tspan2429"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       transform="translate(0.6940599,106.27804)"
+       id="item4"
+       mbname="item4">
+      <text
+         id="item4text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item4text"
+           y="60"
+           x="157.14285"
+           id="tspan2435"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       transform="translate(-0.8367057,141.52253)"
+       id="item5"
+       mbname="item5">
+      <text
+         id="item5text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item5text"
+           y="60"
+           x="157.14285"
+           id="tspan2441"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       transform="translate(-1.3263777,176.18408)"
+       id="item6"
+       mbname="item6">
+      <text
+         id="item6text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item6text"
+           y="60"
+           x="157.14285"
+           id="tspan2447"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       transform="translate(0.3470343,213.13901)"
+       id="item7"
+       mbname="item7">
+      <text
+         id="item7text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item7text"
+           y="60"
+           x="157.14285"
+           id="tspan2453"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       transform="translate(-0.1426457,247.80057)"
+       id="item8"
+       mbname="item8">
+      <text
+         id="item8text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-weight:normal;fill:#000000;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
+           mbname="item8text"
+           y="60"
+           x="157.14285"
+           id="tspan2459"
+           sodipodi:role="line">item1</tspan></text>
+    </g>
+    <g
+       mbname="lightbar"
+       transform="translate(0,157)"
+       id="lightbar">
+      <rect
+         style="opacity:0.3669725;fill:#0068d3;fill-opacity:1;stroke:#00d300;stroke-width:0.99680871;stroke-opacity:1"
+         id="rect2405"
+         width="442.86035"
+         height="44.003193"
+         x="-0.93016708"
+         y="22.784119" />
+    </g>
+  </g>
+</svg>
--- /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 <stdio.h>
+#include <mb.h>
+#include <string.h>
+#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 */
--- 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
--- 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);
--- 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_])])
--- 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