Mercurial > MadButterfly
changeset 937:191d3a5f74c8
Migrate testsvg.js to new interface of shift action.
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Fri, 12 Nov 2010 16:54:48 +0800 |
parents | a9abcdac0ae5 |
children | 13b9acbbe9a3 |
files | nodejs/animate.js nodejs/test.svg nodejs/testsvg.js |
diffstat | 3 files changed, 257 insertions(+), 64 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/animate.js Fri Nov 12 16:53:03 2010 +0800 +++ b/nodejs/animate.js Fri Nov 12 16:54:48 2010 +0800 @@ -15,12 +15,12 @@ x = (this.targetx - this.startposx) * percent + this.startposx; y = (this.targety - this.startposy) * percent + this.startposy; this.obj.center.move(x, y); - this.app.refresh(); + this._app.refresh(); } function shift(app,obj,shiftx,shifty) { obj.animated_shift = this; - this.app = app; + this._app = app; this.obj = obj; this.end = 0; this.targetx = shiftx + obj.center.x;
--- a/nodejs/test.svg Fri Nov 12 16:53:03 2010 +0800 +++ b/nodejs/test.svg Fri Nov 12 16:54:48 2010 +0800 @@ -15,7 +15,7 @@ height="480" id="svg2" sodipodi:version="0.32" - inkscape:version="0.47+devel r9312" + inkscape:version="0.47 r22583" sodipodi:docname="test.svg" version="1.0" inkscape:output_extension="org.inkscape.output.svg.inkscape"> @@ -33,7 +33,7 @@ inkscape:cx="267.0313" inkscape:cy="228.90269" inkscape:document-units="px" - inkscape:current-layer="layer1" + inkscape:current-layer="layer4" showgrid="false" inkscape:window-width="1347" inkscape:window-height="894" @@ -104,162 +104,324 @@ transform="translate(147.14286,-2.85715)" id="item1" mbname="item1" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.12571" + inkscape:bbox-y="419.49715" + inkscape:bbox-width="13.021875" + inkscape:bbox-height="21.072"> <text id="text2395" y="60" x="157.14285" - 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%" + 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;font-family:Times New Roman;-inkscape-font-specification:Times New Roman Bold" xml:space="preserve" - sodipodi:linespacing="125%"><tspan + sodipodi:linespacing="125%" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.12571" + inkscape:bbox-y="419.49715" + inkscape:bbox-width="13.021875" + inkscape:bbox-height="21.072"><tspan mbname="item1text" y="60" x="157.14285" id="tspan2397" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.12571" + inkscape:bbox-y="419.49715" + inkscape:bbox-width="13.021875" + inkscape:bbox-height="21.072">item1</tspan></text> </g> <g transform="translate(146.65319,39.689836)" id="item2" mbname="item2" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.81167" + inkscape:bbox-y="379.97032" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"> <text id="text2421" y="60" x="157.14285" - 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%" + 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;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold" xml:space="preserve" - sodipodi:linespacing="125%"><tspan + sodipodi:linespacing="125%" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.81167" + inkscape:bbox-y="379.97032" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"><tspan mbname="item2text" y="60" x="157.14285" id="tspan2423" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.81167" + inkscape:bbox-y="379.97032" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <g transform="translate(148.3266,82.236798)" id="item3" mbname="item3" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="307.48508" + inkscape:bbox-y="337.42336" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"> <text id="item3text" y="60" x="157.14285" - 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%" + 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;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold" xml:space="preserve" - sodipodi:linespacing="125%"><tspan + sodipodi:linespacing="125%" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="307.48508" + inkscape:bbox-y="337.42336" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"><tspan mbname="item3text" y="60" x="157.14285" id="tspan2429" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="307.48508" + inkscape:bbox-y="337.42336" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <g transform="translate(147.83692,124.7838)" id="item4" mbname="item4" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="306.9954" + inkscape:bbox-y="294.87636" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"> <text id="item4text" y="60" x="157.14285" - 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%" + 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;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold" xml:space="preserve" - sodipodi:linespacing="125%"><tspan + sodipodi:linespacing="125%" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="306.9954" + inkscape:bbox-y="294.87636" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"><tspan mbname="item4text" y="60" x="157.14285" id="tspan2435" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="306.9954" + inkscape:bbox-y="294.87636" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <g transform="translate(146.30615,167.33077)" id="item5" mbname="item5" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.46463" + inkscape:bbox-y="252.32939" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"> <text id="item5text" y="60" x="157.14285" - 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%" + 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;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold" xml:space="preserve" - sodipodi:linespacing="125%"><tspan + sodipodi:linespacing="125%" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.46463" + inkscape:bbox-y="252.32939" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"><tspan mbname="item5text" y="60" x="157.14285" id="tspan2441" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.46463" + inkscape:bbox-y="252.32939" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <g transform="translate(145.81648,209.87776)" id="item6" mbname="item6" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="304.97496" + inkscape:bbox-y="209.7824" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"> <text id="item6text" y="60" x="157.14285" - 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%" + 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;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Bold" xml:space="preserve" - sodipodi:linespacing="125%"><tspan + sodipodi:linespacing="125%" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="304.97496" + inkscape:bbox-y="209.7824" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219"><tspan mbname="item6text" y="60" x="157.14285" id="tspan2447" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="304.97496" + inkscape:bbox-y="209.7824" + inkscape:bbox-width="74.0625" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <g transform="translate(147.48989,252.42474)" id="item7" mbname="item7" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.47649" + inkscape:bbox-y="167.23542" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219"> <text id="item7text" y="60" x="157.14285" - 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%" + 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;font-family:Bitstream Vera Sans;-inkscape-font-specification:Bitstream Vera Sans Oblique" xml:space="preserve" - sodipodi:linespacing="125%"><tspan + sodipodi:linespacing="125%" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.47649" + inkscape:bbox-y="167.23542" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219"><tspan mbname="item7text" y="60" x="157.14285" id="tspan2453" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="305.47649" + inkscape:bbox-y="167.23542" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <g transform="translate(147.00021,294.97172)" id="item8" mbname="item8" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="306.40478" + inkscape:bbox-y="124.68844" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219"> <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 + style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" + xml:space="preserve" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="306.40478" + inkscape:bbox-y="124.68844" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219"><tspan mbname="item8text" y="60" x="157.14285" id="tspan2459" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="306.40478" + inkscape:bbox-y="124.68844" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <g transform="translate(143.79604,337.5187)" id="item9" mbname="item9" - style="fill-opacity:1"> + style="fill-opacity:1" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="303.20061" + inkscape:bbox-y="82.141456" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219"> <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 + style="font-size:24px;font-style:normal;font-weight:normal;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Bitstream Vera Sans" + xml:space="preserve" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="303.20061" + inkscape:bbox-y="82.141456" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219"><tspan mbname="item9text" y="60" x="157.14285" id="tspan2409" - sodipodi:role="line">item1</tspan></text> + sodipodi:role="line" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="303.20061" + inkscape:bbox-y="82.141456" + inkscape:bbox-width="65.027344" + inkscape:bbox-height="18.574219">item1</tspan></text> </g> <text id="text2416" @@ -281,27 +443,45 @@ mbname="item_lightbar" transform="matrix(0.9148913,0,0,1,168.41407,93.684101)" id="item_lightbar" - style="stroke:none"> + style="stroke:none" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="164.66374" + inkscape:bbox-y="326.01386" + inkscape:bbox-width="409.10203" + inkscape:bbox-height="33.623234"> <rect - style="opacity:0.3669725;fill:#001f41;fill-opacity:1;stroke:none;stroke-width:0.99680871;stroke-opacity:1" + style="opacity:0.3669725;fill:#001f41;fill-opacity:1;stroke:none" 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)" + transform="matrix(0.9999958,-0.00289533,0,1,0,0)" rx="10.000001" - ry="10" /> + ry="10" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="168.5966" + inkscape:bbox-y="326.01386" + inkscape:bbox-width="405.16917" + inkscape:bbox-height="30.41517" /> <rect - style="opacity:0.3669725;fill:#eafbf3;fill-opacity:1;stroke:none;stroke-width:0.99680871;stroke-opacity:1" + style="opacity:0.3669725;fill:#eafbf3;fill-opacity:1;stroke:none" 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)" + transform="matrix(0.9999958,-0.00289533,0,1,0,0)" rx="10" - ry="10" /> + ry="10" + inkscape:transform-center-x="0" + inkscape:transform-center-y="0" + inkscape:bbox-x="164.66374" + inkscape:bbox-y="329.22193" + inkscape:bbox-width="405.16911" + inkscape:bbox-height="30.41517" /> </g> <image y="78.788635"
--- a/nodejs/testsvg.js Fri Nov 12 16:53:03 2010 +0800 +++ b/nodejs/testsvg.js Fri Nov 12 16:54:48 2010 +0800 @@ -10,36 +10,49 @@ app.loadSVG("test.svg"); lightbar = app.get("item_lightbar"); item=1; -lightbar[5] = app.get("item"+item)[5]; +var target = app.get("item" + item); +sys.puts(lightbar.center.x); +sys.puts(lightbar.center.y); +lightbar.center.move_pnt(target.center); +// lightbar[5] = app.get("item"+item)[5]; app.files=fs.readdirSync("/tmp/"); for(i=1;i<10;i++) { var o = app.get("item"+i+"text"); - o.set_text(app.files[i]); + o.set_text(app.files[i]); } app.addKeyListener(mbapp.KEY_UP, function() { - item = item - 1; - if (item == 0) item = 1; - else { - var target = app.get("item"+item); - var an = new animate.linear(app,lightbar,target[2],target[5],0.3); - an.start(); - } + item = item - 1; + if (item == 0) + item = 1; + else { + var target = app.get("item"+item); + var shx = target.center.x - lightbar.center.x; + var shy = target.center.y - lightbar.center.y; + var action = new animate.shift(app, lightbar, shx, shy); + var an = new animate.linear(action, 0, 0.3); + an.start(); + } }); app.addKeyListener(mbapp.KEY_DOWN, function() { - item = item + 1; - if (item == 10) { - item = 9; - } else { - var target = app.get("item"+item); - var an = new animate.linear(app,lightbar,target[2],target[5],0.3); - an.start(); - } + item = item + 1; + if (item == 10) { + item = 9; + } else { + var target = app.get("item"+item); + var shx = target.center.x - lightbar.center.x; + var shy = target.center.y - lightbar.center.y; + var action = new animate.shift(app, lightbar, shx, shy); + var an = new animate.linear(action, 0, 0.3); + sys.puts(target.center.y); + sys.puts(lightbar.center.y); + an.start(); + } }); app.loop();