Mercurial > MadButterfly
changeset 808:9b6c26cf9102
Move bounding box and center back to an object
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Wed, 01 Sep 2010 20:04:35 +0800 |
parents | 5723e5446b7c |
children | e21ccbc4afb1 |
files | nodejs/animate.js nodejs/svg.js |
diffstat | 2 files changed, 26 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/nodejs/animate.js Wed Sep 01 18:04:20 2010 +0800 +++ b/nodejs/animate.js Wed Sep 01 20:04:35 2010 +0800 @@ -87,9 +87,9 @@ cv = Math.cos(ang); mtx = [cv, -sv, 0, sv, cv, 0]; - shift = [1, 0, -obj.center_x, 0, 1, -obj.center_y]; + shift = [1, 0, -obj.center.x, 0, 1, -obj.center.y]; mtx = multiply(mtx, shift); - shift = [1, 0, obj.center_x, 0, 1, obj.center_y]; + shift = [1, 0, obj.center.x, 0, 1, obj.center.y]; mtx = multiply(shift, mtx); mtx = multiply(mtx, this._start_mtx); @@ -183,14 +183,18 @@ } holder.prototype = { - go_center: function(o) { + go: function(pos) { var sx, sy; - sx = o.center_x - this._coord.center_x; - sy = o.center_y - this._coord.center_y; + sx = pos.x - this._coord.center.x; + sy = pos.y - this._coord.center.y; this.shift(sx, sy); }, + go_center: function(o) { + this.go(o.center); + }, + home: function() { this._coord[2] = this._mtx[2]; this._coord[5] = this._mtx[5];
--- a/nodejs/svg.js Wed Sep 01 18:04:20 2010 +0800 +++ b/nodejs/svg.js Wed Sep 01 20:04:35 2010 +0800 @@ -250,40 +250,42 @@ loadSVG.prototype._set_bbox = function(node, tgt) { var a; var vstr; + var bbox, center; a = node.attr("bbox-x"); if(!a) return; + tgt.bbox = bbox = new Object(); vstr = a.value(); - tgt.bbox_x = parseFloat(vstr); + bbox.x = parseFloat(vstr); a = node.attr("bbox-y"); vstr = a.value(); - tgt.bbox_y = this.height - parseFloat(vstr); + bbox.y = this.height - parseFloat(vstr); a = node.attr("bbox-width"); vstr = a.value(); - tgt.bbox_width = parseFloat(vstr); + bbox.width = parseFloat(vstr); a = node.attr("bbox-height"); vstr = a.value(); - tgt.bbox_height = parseFloat(vstr); - tgt.bbox_y -= tgt.bbox_height; + bbox.height = parseFloat(vstr); + bbox.y -= bbox.height; - tgt.center_x = tgt.bbox_width / 2 + tgt.bbox_x; + tgt.center = center = new Object(); + + center.x = bbox.width / 2 + bbox.x; + center.y = bbox.height / 2 + bbox.y; a = node.attr("transform-center-x"); - if(a) { - vstr = a.value(); - tgt.center_x += parseFloat(vstr); - } + if(!a) + return; - tgt.center_y = tgt.bbox_height / 2 + tgt.bbox_y; + vstr = a.value(); + center.x += parseFloat(vstr); a = node.attr("transform-center-y"); - if(a) { - vstr = a.value(); - tgt.center_y -= parseFloat(vstr); - } + vstr = a.value(); + center.y -= parseFloat(vstr); } loadSVG.prototype._set_paint = function(node, tgt) {