# HG changeset patch # User Thinker K.F. Li # Date 1283342675 -28800 # Node ID 9b6c26cf9102e3a5c908a0a786434bba4880adc4 # Parent 5723e5446b7cbe7575059da671d8b3443762f4c7 Move bounding box and center back to an object diff -r 5723e5446b7c -r 9b6c26cf9102 nodejs/animate.js --- 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]; diff -r 5723e5446b7c -r 9b6c26cf9102 nodejs/svg.js --- 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) {