From: aurium Date: Mon, 27 Apr 2009 05:06:46 +0000 (+0000) Subject: starting a move method for InkWeb. X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=ab0e73f2e0afb240fc4be439c7c6de26d4f05f34;p=inkscape.git starting a move method for InkWeb. --- diff --git a/share/extensions/inkweb.js b/share/extensions/inkweb.js index 5cb48869f..2be2e9b2b 100644 --- a/share/extensions/inkweb.js +++ b/share/extensions/inkweb.js @@ -26,7 +26,7 @@ var InkWeb = { - version: 0.03, + version: 0.04, NS: { svg: "http://www.w3.org/2000/svg", @@ -123,3 +123,45 @@ InkWeb.setAtt = function (conf) { } } +InkWeb.moveElTo = function (startConf) { + if ( typeof(startConf) == "string" ) { + // startConf may be only a element Id, to timeout recursive calls. + var el = document.getElementById( startConf ); + } else { + if ( typeof(startConf.el) == "string" ) + startConf.from = document.getElementById( startConf.el ); + var el = startConf.el; + } + if ( ! el.inkWebMoving ) { + el.inkWebMoving = { + step: 0 + }; + } + var conf = el.inkWebMoving; + if ( conf.step == 0 ) { + conf.x = startConf.x; + conf.y = startConf.y; + // dur : duration of the animation in seconds + if ( startConf.dur ) { conf.dur = startConf.dur } + else { conf.dur = 1 } + // steps : animation steps in a second + if ( startConf.stepsBySec ) { conf.stepsBySec = startConf.stepsBySec } + else { conf.stepsBySec = 16 } + conf.sleep = Math.round( 1000 / conf.stepsBySec ); + conf.steps = conf.dur * conf.stepsBySec; + var startPos = el.getBBox(); + conf.xInc = ( conf.x - startPos.x ) / conf.steps; + conf.yInc = ( conf.y - startPos.y ) / conf.steps; + conf.transform = el.ownerSVGElement.createSVGTransform(); + el.transform.baseVal.appendItem(conf.transform); + } + if ( conf.step < conf.steps ) { + conf.step++; + conf.transform.matrix.e += conf.xInc; + conf.transform.matrix.f += conf.yInc; + conf.timeout = setTimeout( 'InkWeb.moveElTo("'+el.id+'")', conf.sleep ); + } else { + delete el.inkWebMoving; + } +} + diff --git a/share/extensions/test/inkwebjs-move.test.svg b/share/extensions/test/inkwebjs-move.test.svg new file mode 100644 index 000000000..bab21d918 --- /dev/null +++ b/share/extensions/test/inkwebjs-move.test.svg @@ -0,0 +1,114 @@ + + + + + + + + + Test 1 - from left to right + Start + + End + + + + + + + + Test 2 - from right to left + Start + + End + + + + + + + + Test 3 - pre-translated + Start + + End + + + + + + + + Test 4 - pre-translated and scaled + Start + + End + + + + + + + + Test 5 - pre-translated and rotated + Start + + End + + + + + + + + Test 6 - with a transformation matrix + Start + + End + + + + + + + +