Mercurial > MadButterfly
changeset 371:3d21115297ba
Add textmenu template
author | wycc |
---|---|
date | Tue, 17 Mar 2009 08:31:04 +0800 |
parents | fce37d9c296f |
children | 2212f515584c 7d244a85dd68 |
files | inkscape/firefox/content/inkscape.js inkscape/firefox/content/madbuilder.html inkscape/firefox/content/wizard.js inkscape/firefox/template/textmenu/Makefile inkscape/firefox/template/textmenu/app.c inkscape/firefox/template/textmenu/app.h inkscape/firefox/template/textmenu/app.prj inkscape/firefox/template/textmenu/list.mbsvg inkscape/firefox/template/textmenu/main.c |
diffstat | 9 files changed, 492 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/inkscape/firefox/content/inkscape.js Mon Mar 16 09:00:51 2009 +0800 +++ b/inkscape/firefox/content/inkscape.js Tue Mar 17 08:31:04 2009 +0800 @@ -472,14 +472,20 @@ function project_loadScene(node) { var file = node.textContent; - inkscape = new Inkscape("file://"+file); + if (file.substr(0,1) == '/') + inkscape = new Inkscape("file://"+file); + else + inkscape = new Inkscape("file://"+project_dir+'/'+file); } function project_loadEditor(node) { var file = node.textContent; - editor = new TextEditor("file://"+file); + if (file.substr(0,1) == '/') + editor = new TextEditor("file://"+file); + else + editor = new TextEditor("file://"+project_dir+'/'+file); } function project_parse(xml) @@ -689,7 +695,7 @@ .createInstance( Components.interfaces.nsIFileOutputStream ); fostream.init( file,0x02|0x8|0x20, 0666,0); } catch(e) { - alert(fname+" does not exist"); + alert('can not create '+fname); } return fostream; } @@ -713,10 +719,39 @@ } } +function system_mkdir(path) +{ + try { + netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect"); + } catch (e) { + alert("Permission to read file was denied."); + } + var file = Components.classes["@mozilla.org/file/local;1"] + .createInstance(Components.interfaces.nsILocalFile); + try { + file.initWithPath(path); + if( !file.exists() || !file.isDirectory() ) { // if it doesn't exist, create + file.create(Components.interfaces.nsIFile.DIRECTORY_TYPE, 0777); + } + } catch(e) { + alert('Failed to create directopry '+path+e); + } +} + +function getPathDirectory(path) +{ + var s = path.lastIndexOf('/'); + if (s == -1) + return ''; + else + return path.substr(0,s); +} + function project_loadFile() { prjname = $('#mbsvg').attr('value'); project_name = prjname; + project_dir = getPathDirectory(prjname); var prj = system_read(prjname); project_parse(prj); filedialog.dialog('close'); @@ -750,6 +785,7 @@ function onLoadProject(path) { project_name = path; + project_dir = getPathDirectory(project_name); var prj = system_read(project_name); project_parse(prj); }
--- a/inkscape/firefox/content/madbuilder.html Mon Mar 16 09:00:51 2009 +0800 +++ b/inkscape/firefox/content/madbuilder.html Tue Mar 17 08:31:04 2009 +0800 @@ -77,7 +77,7 @@ <input type=text id='wizardname' value='default'/><br> Please select the type of applications.<br> <ul> - <a href='#' onClick="wizard.step1_cb('text')"><li> Text only menu </li></a> + <a href='#' onClick="wizard.step1_cb('textmenu')"><li> Text only menu </li></a> <a href='#' onClick="wizard.step1_cb('preview')"><li> Text with preview menu </li></a> </ul> @@ -87,10 +87,10 @@ Please select the output path<br> <input id='outputpath' type=file value='/tmp' /><br> <a class 'buttopn' href='#'><span onClick='wizard.step1_cb()'>Prev</span></a> - <a class 'buttopn' href='#'><span onClick='wizard.step3_cb()'>Next</span></a> + <a class 'buttopn' href='#'><span onClick='wizard.step2_cb()'>Next</span></a> </div> <div id='wizard_step3'> - The step 3 is not implemented yet + Generating files<br> </div> <script type="text/javascript" src="inkscape.js" >
--- a/inkscape/firefox/content/wizard.js Mon Mar 16 09:00:51 2009 +0800 +++ b/inkscape/firefox/content/wizard.js Tue Mar 17 08:31:04 2009 +0800 @@ -29,44 +29,47 @@ // In the step 2, get the output path Wizard.prototype.step2_cb=function() { - this.dir = $('#wizardpath').attr('value'); + this.dir = $('#outputpath').attr('value'); this.step2.dialog('close'); this.step3.dialog('open'); -} - -// In the step 3, generate files -Wizard.prototype.step3_cb=function() -{ + system_mkdir(this.dir); this.generate_source('main.c','main.c'); + this.step3.append('main.c<br>'); + this.generate_source('list.mbsvg','list.mbsvg'); + this.step3.append('list.mbsvg<br>'); this.generate_source('app.h',this.name+'.h'); + this.step3.append(this.name+'.h<br>'); this.generate_source('app.c',this.name+'.c'); + this.step3.append(this.name+'.c<br>'); this.generate_source('app.prj',this.name+'.prj'); + this.step3.append('app.prj<br>'); this.generate_source('Makefile','Makefile'); + this.step3.append('Makefile<br>'); this.done_cb(); } Wizard.prototype.done_cb=function() { this.step3.dialog('close'); - this.cb(this.dir+this.name+'.prj'); + this.cb(this.dir+'/'+this.name+'.prj'); } Wizard.prototype.generate_source=function (tmpl,fname) { var file = system_open_write(this.dir+'/'+fname); - var template = system_open_read('wizard/'+this.type+'/'+tmpl); + var template = system_open_read('/usr/local/share/mb/template/'+this.type+'/'+tmpl); if (template == null) { - alert('Can not find template file '+tmpl); return; } if (file == null) { - alert('Can not create '+fname); return; } var data = template.read(template.available()); + var regex = /\%n/gi; // FIXME: replace name here - file.write(data.data.length); + data=data.replace(regex,this.name); + file.write(data,data.length); file.close(); template.close(); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/template/textmenu/Makefile Tue Mar 17 08:31:04 2009 +0800 @@ -0,0 +1,18 @@ +SRC=main.c %f.c +OBJ=$(SRC:.c=.o) +CFLAGS+=`pkg-config --cflags libmbfly` `pkg-config --cflags pangocairo` +LDFLAGS=`pkg-config --libs libmbfly` + +.c.o: + $(CC) $(CFLAGS) -c -o $@ $< + +%.so:%.mbsvg + svg2code.py $< $(<:.mbsvg=.mb) + m4 -I /usr/local/share/mb mb_c_header.m4 $(<:.mbsvg=.mb) > $(<:.mbsvg=.h) + m4 -I /usr/local/share/mb mb_c_source.m4 $(<:.mbsvg=.mb) > $(<:.mbsvg=.c) + $(CC) $(CFLAGS) -I../../include -I ../../include -shared -o $@ $(<:.mbsvg=.c) + +all: list.so textmenu + +textmenu : $(OBJ) + $(CC) -o textmenu $(LDFLAGS) $(OBJ)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/template/textmenu/app.c Tue Mar 17 08:31:04 2009 +0800 @@ -0,0 +1,16 @@ +#include <stdio.h> +#include <mb.h> +#include "mbapp.h" +#include "animated_menu.h" +#include "app.h" + +void myselect_callback(mb_animated_menu_t *m, int select) +{ + printf("menu %d is selected\n", select); + // Put the callback function for menu select here +} + +void MyApp_InitContent(MBApp *app,int argc,char *argv[]) +{ + // This function is called when the application is started. +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/template/textmenu/app.h Tue Mar 17 08:31:04 2009 +0800 @@ -0,0 +1,10 @@ +#ifndef _APP_H +#define _APP_H +typedef struct { + mb_animated_menu_t *m; +}MyAppData; + +extern void MyApp_InitContent(MBApp *app,int argc, char *argv[]); + +void myselect_callback(mb_animated_menu_t *m, int select); +#endif
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/template/textmenu/app.prj Tue Mar 17 08:31:04 2009 +0800 @@ -0,0 +1,7 @@ +<project> + <scene src='list.mbsvg' /> + <source src='main.c'/> + <source src='%n.c'/> + <source src='%n.h'/> + <source src='Makefile'/> +</project>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/template/textmenu/list.mbsvg Tue Mar 17 08:31:04 2009 +0800 @@ -0,0 +1,333 @@ +<?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="list.mbsvg" + 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="267.0313" + inkscape:cy="228.90269" + inkscape:document-units="px" + inkscape:current-layer="item7" + 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 + id="stop3185" + offset="0" + style="stop-color:#000000;stop-opacity:1;" /> + <stop + id="stop3187" + offset="1" + style="stop-color:#505050;stop-opacity:1;" /> + </linearGradient> + <inkscape:perspective + sodipodi:type="inkscape:persp3d" + inkscape:vp_x="0 : 526.18109 : 1" + inkscape:vp_y="0 : 1000 : 0" + inkscape:vp_z="744.09448 : 526.18109 : 1" + inkscape:persp3d-origin="372.04724 : 350.78739 : 1" + id="perspective10" /> + <linearGradient + gradientUnits="userSpaceOnUse" + y2="239.5" + x2="719.99998" + y1="239.5" + x1="0" + id="linearGradient3189" + xlink:href="#linearGradient3183" + inkscape:collect="always" /> + </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="2"> + <ns0:scene + start="1" + ref="g1122" /> + <ns0:scene + start="2" + ref="s2319" /> + <ns0:scene + start="1" + ref="g1123" /> + <ns0:scene + start="1" + ref="g1124" /> + </ns0:scenes> + </metadata> + <g + sodipodi:insensitive="true" + inkscape:label="Background" + id="layer2" + inkscape:groupmode="layer"> + <g + style="display:none" + id="g1122"> + <rect + y="-0.50034672" + x="0.49965325" + height="480.0007" + width="719.00067" + id="rect3181" + style="opacity:1;fill:url(#linearGradient3189);fill-opacity:1;stroke:#000000;stroke-width:0.9993065;stroke-opacity:1" /> + </g> + <g + style="" + id="s2319" /> + </g> + <g + inkscape:label="Layer 1" + inkscape:groupmode="layer" + id="layer1"> + <g + style="display:none" + id="g1123"> + <g + style="fill-opacity:1" + mbname="item1" + id="item1" + transform="translate(147.14286,-2.85715)"> + <text + sodipodi:linespacing="125%" + xml:space="preserve" + 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%" + x="157.14285" + y="60" + id="text2395"><tspan + sodipodi:role="line" + id="tspan2397" + x="157.14285" + y="60" + mbname="item1text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item2" + id="item2" + transform="translate(146.65319,39.689836)"> + <text + sodipodi:linespacing="125%" + xml:space="preserve" + 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%" + x="157.14285" + y="60" + id="text2421"><tspan + sodipodi:role="line" + id="tspan2423" + x="157.14285" + y="60" + mbname="item2text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item3" + id="item3" + transform="translate(148.3266,82.236798)"> + <text + sodipodi:linespacing="125%" + xml:space="preserve" + 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%" + x="157.14285" + y="60" + id="item3text"><tspan + sodipodi:role="line" + id="tspan2429" + x="157.14285" + y="60" + mbname="item3text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item4" + id="item4" + transform="translate(147.83692,124.7838)"> + <text + sodipodi:linespacing="125%" + xml:space="preserve" + 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%" + x="157.14285" + y="60" + id="item4text"><tspan + sodipodi:role="line" + id="tspan2435" + x="157.14285" + y="60" + mbname="item4text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item5" + id="item5" + transform="translate(146.30615,167.33077)"> + <text + sodipodi:linespacing="125%" + xml:space="preserve" + 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%" + x="157.14285" + y="60" + id="item5text"><tspan + sodipodi:role="line" + id="tspan2441" + x="157.14285" + y="60" + mbname="item5text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item6" + id="item6" + transform="translate(145.81648,209.87776)"> + <text + sodipodi:linespacing="125%" + xml:space="preserve" + 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%" + x="157.14285" + y="60" + id="item6text"><tspan + sodipodi:role="line" + id="tspan2447" + x="157.14285" + y="60" + mbname="item6text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item7" + id="item7" + transform="translate(147.48989,252.42474)"> + <text + sodipodi:linespacing="125%" + xml:space="preserve" + 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%" + x="157.14285" + y="60" + id="item7text"><tspan + sodipodi:role="line" + id="tspan2453" + x="157.14285" + y="60" + mbname="item7text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item8" + id="item8" + transform="translate(147.00021,294.97172)"> + <text + xml:space="preserve" + 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" + x="157.14285" + y="60" + id="item8text"><tspan + sodipodi:role="line" + id="tspan2459" + x="157.14285" + y="60" + mbname="item8text">item1</tspan></text> + </g> + <g + style="fill-opacity:1" + mbname="item9" + id="item9" + transform="translate(143.79604,337.5187)"> + <text + xml:space="preserve" + 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" + x="157.14285" + y="60" + id="text2407" + mbname=""><tspan + sodipodi:role="line" + id="tspan2409" + x="157.14285" + y="60" + mbname="item9text">item1</tspan></text> + </g> + <text + xml:space="preserve" + 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" + x="24.177626" + y="44.383541" + id="text2416"><tspan + sodipodi:role="line" + id="tspan2418" + x="24.177626" + y="44.383541" + mbname="item1text">Menu test</tspan></text> + </g> + </g> + <g + inkscape:label="lightbar" + id="layer4" + inkscape:groupmode="layer"> + <g + style="display:none" + id="g1124"> + <g + style="stroke:none" + id="item_lightbar" + transform="matrix(0.9148913,0,0,1,167.44763,103.34853)" + mbname="item_lightbar"> + <rect + ry="10" + rx="10.000001" + transform="matrix(0.9999958,-2.895334e-3,0,1,0,0)" + y="31.140766" + x="0.19951171" + height="29.190758" + width="442.8623" + id="rect3191" + style="opacity:0.3669725;fill:#001f41;fill-opacity:1;stroke:none;stroke-width:0.99680871;stroke-opacity:1" /> + <rect + ry="10" + rx="10" + transform="matrix(0.9999958,-2.8953343e-3,0,1,0,0)" + y="27.920256" + x="-4.099226" + height="29.190758" + width="442.86224" + id="rect2405" + style="opacity:0.3669725;fill:#eafbf3;fill-opacity:1;stroke:none;stroke-width:0.99680871;stroke-opacity:1" /> + </g> + </g> + </g> +</svg>
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/inkscape/firefox/template/textmenu/main.c Tue Mar 17 08:31:04 2009 +0800 @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <mb.h> +#include <string.h> +//#include "menu.h" +#include "mbapp.h" +#include "animated_menu.h" +#include "app.h" + + +char *menus[] = { + "This is item 1", + "This is item 2", + "This is item 3", + "This is item 4", + "This is item 5", + "This is item 6", + "This is item 7", + "This is item 8" +}; + + +MBApp *myApp; + +_MyApp_InitContent(int argc, char *argv[]) +{ + 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",menus); + mb_animated_menu_set_callback(data->m, myselect_callback); + MyApp_InitContent(myApp,argc,argv); +} + +int main(int argc, char * const argv[]) { + subject_t *subject; + mb_obj_t *button; + MyAppData data; + + myApp = MBApp_Init("list"); + MBApp_setData(myApp,&data); + _MyApp_InitContent(argc,argv); + + MBApp_loop(myApp); + + return 0; +} + +/* vim: set ts=4 */