changeset 309:4dfb850dee92

Add filebrowser program and SVG file.
author wycc
date Sun, 22 Feb 2009 13:45:28 +0800
parents 9e1d72eca57b
children 25a68d15e92f
files examples/menu/browser.svg examples/menu/filebrowser.c
diffstat 2 files changed, 530 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/menu/browser.svg	Sun Feb 22 13:45:28 2009 +0800
@@ -0,0 +1,350 @@
+<?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:xlink="http://www.w3.org/1999/xlink"
+   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="browser.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="1.0347223"
+     inkscape:cx="132.69574"
+     inkscape:cy="228.90269"
+     inkscape:document-units="px"
+     inkscape:current-layer="layer2"
+     showgrid="false"
+     inkscape:window-width="1124"
+     inkscape:window-height="867"
+     inkscape:window-x="212"
+     inkscape:window-y="90" />
+  <defs
+     id="defs4">
+    <linearGradient
+       id="linearGradient3183">
+      <stop
+         style="stop-color:#0000ff;stop-opacity:1;"
+         offset="0"
+         id="stop3185" />
+      <stop
+         style="stop-color:#505050;stop-opacity:1;"
+         offset="1"
+         id="stop3187" />
+    </linearGradient>
+    <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" />
+    <linearGradient
+       inkscape:collect="always"
+       xlink:href="#linearGradient3183"
+       id="linearGradient3189"
+       x1="0"
+       y1="239.5"
+       x2="719.99998"
+       y2="239.5"
+       gradientUnits="userSpaceOnUse" />
+  </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
+     inkscape:groupmode="layer"
+     id="layer2"
+     inkscape:label="Background">
+    <rect
+       style="opacity:1;fill:url(#linearGradient3189);fill-opacity:1;stroke:#000000;stroke-width:0.9993065;stroke-opacity:1"
+       id="rect3181"
+       width="719.00067"
+       height="480.0007"
+       x="0.49965325"
+       y="-0.50034672" />
+  </g>
+  <g
+     id="layer1"
+     inkscape:groupmode="layer"
+     inkscape:label="Layer 1">
+    <g
+       transform="translate(-124.18599,-2.85715)"
+       id="item1"
+       mbname="item1"
+       style="fill-opacity:1">
+      <text
+         id="text2395"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;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"
+         xml:space="preserve"
+         sodipodi:linespacing="125%"><tspan
+           mbname="item1text"
+           y="60"
+           x="157.14285"
+           id="tspan2397"
+           sodipodi:role="line">item111111111111111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-124.67566,39.689836)"
+       id="item2"
+       mbname="item2"
+       style="fill-opacity:1">
+      <text
+         id="text2421"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;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"
+         xml:space="preserve"
+         sodipodi:linespacing="125%"><tspan
+           mbname="item2text"
+           y="60"
+           x="157.14285"
+           id="tspan2423"
+           sodipodi:role="line">item1111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-123.00225,82.236798)"
+       id="item3"
+       mbname="item3"
+       style="fill-opacity:1">
+      <text
+         id="item3text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;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"
+         xml:space="preserve"
+         sodipodi:linespacing="125%"><tspan
+           mbname="item3text"
+           y="60"
+           x="157.14285"
+           id="tspan2429"
+           sodipodi:role="line">item1111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-123.49193,124.7838)"
+       id="item4"
+       mbname="item4"
+       style="fill-opacity:1">
+      <text
+         id="item4text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;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"
+         xml:space="preserve"
+         sodipodi:linespacing="125%"><tspan
+           mbname="item4text"
+           y="60"
+           x="157.14285"
+           id="tspan2435"
+           sodipodi:role="line">item1111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-125.0227,167.33077)"
+       id="item5"
+       mbname="item5"
+       style="fill-opacity:1">
+      <text
+         id="item5text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;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"
+         xml:space="preserve"
+         sodipodi:linespacing="125%"><tspan
+           mbname="item5text"
+           y="60"
+           x="157.14285"
+           id="tspan2441"
+           sodipodi:role="line">item1111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-125.51237,209.87776)"
+       id="item6"
+       mbname="item6"
+       style="fill-opacity:1">
+      <text
+         id="item6text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;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"
+         xml:space="preserve"
+         sodipodi:linespacing="125%"><tspan
+           mbname="item6text"
+           y="60"
+           x="157.14285"
+           id="tspan2447"
+           sodipodi:role="line">item1111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-123.83896,252.42474)"
+       id="item7"
+       mbname="item7"
+       style="fill-opacity:1">
+      <text
+         id="item7text"
+         y="60"
+         x="157.14285"
+         style="font-size:24px;font-style:oblique;font-variant:normal;font-weight:normal;font-stretch:normal;text-align:start;line-height:125%;writing-mode:lr-tb;text-anchor:start;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"
+         xml:space="preserve"
+         sodipodi:linespacing="125%"><tspan
+           mbname="item7text"
+           y="60"
+           x="157.14285"
+           id="tspan2453"
+           sodipodi:role="line">item111111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-124.32864,294.97172)"
+       id="item8"
+       mbname="item8"
+       style="fill-opacity:1">
+      <text
+         id="item8text"
+         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
+           mbname="item8text"
+           y="60"
+           x="157.14285"
+           id="tspan2459"
+           sodipodi:role="line">item111111111111111111111</tspan></text>
+    </g>
+    <g
+       transform="translate(-127.53281,337.5187)"
+       id="item9"
+       mbname="item9"
+       style="fill-opacity:1">
+      <text
+         mbname=""
+         id="text2407"
+         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
+           mbname="item9text"
+           y="60"
+           x="157.14285"
+           id="tspan2409"
+           sodipodi:role="line">item111111111111111111111</tspan></text>
+    </g>
+    <g
+       mbname="preview"
+       id="preview">
+      <rect
+         ry="10"
+         rx="10"
+         y="26.738289"
+         x="449.39597"
+         height="237.74495"
+         width="252.24159"
+         id="rect2418"
+         style="opacity:1;fill:#ffffff;fill-opacity:1;stroke:none;stroke-opacity:1" />
+    </g>
+    <flowRoot
+       xml:space="preserve"
+       id="flowRoot2420"
+       style="font-size:22px;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"><flowRegion
+         id="flowRegion2422"><rect
+           id="rect2424"
+           width="240.64427"
+           height="162.36241"
+           x="458.09393"
+           y="295.40942"
+           style="font-size:22px;fill:#ffffff;fill-opacity:1" /></flowRegion><flowPara
+         id="flowPara2426" /></flowRoot>    <g
+       mbname="fileinfo"
+       id="fileinfo">
+      <flowRoot
+         mbname="fileinfo"
+         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"
+         id="flowRoot2582"
+         xml:space="preserve"><flowRegion
+           id="flowRegion3200"><rect
+             style="font-size:24px"
+             y="287.67786"
+             x="454.22815"
+             height="172.99327"
+             width="244.51006"
+             id="rect3202" /></flowRegion><flowPara
+           style="fill:#ffffff;fill-opacity:1"
+           id="flowPara3204">File infiormation</flowPara></flowRoot>    </g>
+    <text
+       xml:space="preserve"
+       style="font-size:40px;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"
+       x="155.59731"
+       y="185.23492"
+       id="text2427"><tspan
+         sodipodi:role="line"
+         id="tspan2430" /></text>
+    <text
+       xml:space="preserve"
+       style="font-size:40px;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"
+       x="236.7785"
+       y="393.02014"
+       id="text2429"><tspan
+         sodipodi:role="line"
+         id="tspan2431" /></text>
+  </g>
+  <g
+     inkscape:groupmode="layer"
+     id="layer4"
+     inkscape:label="lightbar">
+    <g
+       mbname="item_lightbar"
+       transform="matrix(0.9148913,0,0,1,17.648985,179.69752)"
+       id="item_lightbar"
+       style="stroke:none">
+      <rect
+         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"
+         x="0.19951171"
+         y="31.140766"
+         transform="matrix(0.9999958,-2.895334e-3,0,1,0,0)"
+         rx="10.000001"
+         ry="10" />
+      <rect
+         style="opacity:0.3669725;fill:#eafbf3;fill-opacity:1;stroke:none;stroke-width:0.99680871;stroke-opacity:1"
+         id="rect2405"
+         width="442.86224"
+         height="29.190758"
+         x="-4.099226"
+         y="27.920256"
+         transform="matrix(0.9999958,-2.8953343e-3,0,1,0,0)"
+         rx="10"
+         ry="10" />
+    </g>
+  </g>
+</svg>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/examples/menu/filebrowser.c	Sun Feb 22 13:45:28 2009 +0800
@@ -0,0 +1,180 @@
+/*! \file
+ *
+ *  This is the demo program for the animated menu. We will use to test the MBAF API.
+ *  We need to have group item1-item9 in the SVG file. Initially, we will show
+ *  item1-item8 only. When a up/down key is pressed, we will draw the next item in item9 and 
+ *  add two words to move item1-item9 smoothly. The first word move items to the 3/4 position 
+ *  fastly. The second will move it from 3/4 to the final position slowly to make retard effect.
+ *
+ *  If we press another key before the second words finish, we will delete the word and replace 
+ *  it with a word to move it fastly to the final position and then we will repeat the procedure
+ *  to add another two words to move it to the next position.
+ */
+#include <stdio.h>
+#include <mb.h>
+#include <string.h>
+#include <dirent.h>
+#include "menu.h"
+#include "mbapp.h"
+#include <animated_menu.h>
+
+
+
+struct fileinfo {
+	int height;
+	int width;
+	int depth;
+	int bitrate;
+	int duration;
+	int year;
+	char *comment;
+};
+#define MAX_ENTRY 1000
+typedef struct {
+	mb_animated_menu_t *m;
+	char *curDir;
+	struct fileinfo *files[MAX_ENTRY];
+	char *titles[MAX_ENTRY];
+	int nFiles;
+}MyAppData;
+
+MBApp *myApp;
+
+
+
+void myselect(mb_animated_menu_t *m, int select)
+{
+    MyAppData *data = MBAPP_DATA(myApp,MyAppData);
+    char path[1024];
+    int len,i;
+
+    if (strcmp(data->titles[select],"..")==0) {
+	    strcpy(path, data->curDir);
+	    len = strlen(path);
+	    for(i=len-1;i>0;i--) {
+		    if (path[i] == '/') {
+			    path[i] = 0;
+			    break;
+		    }
+	    }
+    } else {
+    	snprintf(path,1024,"%s/%s", data->curDir,data->titles[select]);
+    }
+
+    MyApp_fillDirInfo(myApp, path);
+}
+
+
+struct fileinfo *fileinfo_new()
+{
+    struct fileinfo *f = (struct fileinfo *) malloc(sizeof(struct fileinfo));
+
+    f->width = 0;
+    f->height = 0;
+    f->depth = 0;
+    f->bitrate = 0;
+    f->duration = 0;
+    f->year = 0;
+    f->comment = NULL;
+    return f;
+}
+
+void fileinfo_free(struct fileinfo *f)
+{
+    free(f);
+}
+
+
+MyApp_fillDirInfo(MBApp *app,char *curdir)
+{
+    MyAppData *data = MBAPP_DATA(myApp,MyAppData);
+    DIR *dir;
+    struct dirent *e;
+    struct fileinfo *f;
+    int i;
+
+    if (data->curDir)
+	    free(data->curDir);
+    data->curDir = strdup(curdir);
+    dir = opendir(curdir);
+    if (dir == NULL) {
+	    printf("We can not open the direftory %s\n", curdir);
+	    return;
+    }
+
+    if (data->files) {
+	    for(i=0;i<data->nFiles;i++) {
+		    fileinfo_free(data->files[i]);
+		    free(data->titles[i]);
+	    }    
+    }
+    data->nFiles = 0;
+    while(e = readdir(dir)) {
+	    if (strcmp(e->d_name,".")==0) continue;
+	    if (e->d_type == DT_DIR) {
+		    if (data->nFiles < MAX_ENTRY) {
+			    f = fileinfo_new();
+			    data->files[data->nFiles] = f;
+			    data->titles[data->nFiles++] = strdup(e->d_name);
+			    printf("%s\n", e->d_name);
+		    }
+	    }
+    }
+
+    closedir(dir);
+    dir = opendir(curdir);
+    while(e = readdir(dir)) {
+	    if (strcmp(e->d_name,".")==0) continue;
+	    if (e->d_type == DT_REG) {
+		    if (data->nFiles < MAX_ENTRY) {
+			    f = fileinfo_new();
+			    data->files[data->nFiles] = f;
+			    data->titles[data->nFiles++] = strdup(e->d_name);
+			    printf("%s\n", e->d_name);
+		    }
+	    }
+    }
+    closedir(dir);
+    data->titles[data->nFiles] = NULL;
+    mb_animated_menu_set_titles(data->m,data->titles);
+}
+
+
+MyApp_InitContent(char *dir)
+{
+    MyAppData *data = MBAPP_DATA(myApp,MyAppData);
+    subject_t *key = MBAPP_keySubject(myApp);
+    char name[255];
+    coord_t *l;
+    int i;
+    mb_sprite_t *sprite=myApp->rootsprite;
+    
+    data->m = mb_animated_menu_new(myApp,myApp->rootsprite,"item",NULL);
+    mb_animated_menu_set_callback(data->m, myselect);
+    data->curDir = NULL;
+    data->nFiles=0;
+    MyApp_fillDirInfo(myApp,dir);
+    mb_animated_menu_set_speed(data->m,300);
+}
+
+int main(int argc, char * const argv[]) {
+    subject_t *subject;
+    mb_obj_t *button;
+    MyAppData data;
+    mb_timeval_t tmo,interval;
+    char *dir;
+
+    if (argc > 1)
+	    dir = argv[1];
+    else
+	    dir ="/tmp";
+    myApp = MBApp_Init("browser");
+    MBApp_setData(myApp,&data);
+    MyApp_InitContent(dir);
+
+    MBApp_loop(myApp);
+
+    return 0;
+}
+
+/* vim: set ts=4 */