diff -r a9b9e6c7be63 -r 01f66ed90e32 client/js/paper-renderer.js --- a/client/js/paper-renderer.js Mon Feb 11 18:08:19 2013 +0100 +++ b/client/js/paper-renderer.js Wed Feb 13 13:41:19 2013 +0100 @@ -235,6 +235,10 @@ } } +Rkns.Renderer._BaseRepresentation.prototype.resetCoords = function() { + this.paper_coords = undefined; +} + Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation); Rkns.Renderer.Node.prototype._init = function() { @@ -259,8 +263,10 @@ } Rkns.Renderer.Node.prototype.redraw = function() { - var _model_coords = new paper.Point(this.model.get("position")); - this.paper_coords = this.renderer.toPaperCoords(_model_coords); + if (!this.paper_coords) { + var _model_coords = new paper.Point(this.model.get("position")); + this.paper_coords = this.renderer.toPaperCoords(_model_coords); + } this.circle.position = this.paper_coords; this.title.content = this.model.get("title"); this.title.position = this.paper_coords.add([0, Rkns.Renderer._NODE_RADIUS + 1.5 *Rkns.Renderer._NODE_FONT_SIZE]); @@ -313,15 +319,8 @@ } Rkns.Renderer.Node.prototype.paperShift = function(_delta) { - var _coords = this.renderer.toModelCoords(this.paper_coords.add(_delta)), - _data = { - position: { - x: _coords.x, - y: _coords.y - } - }; - this.model.set(_data); - //this.renderer.redraw(); + this.paper_coords = this.paper_coords.add(_delta); + this.redraw(); } Rkns.Renderer.Node.prototype.openEditor = function() { @@ -369,8 +368,22 @@ } } +Rkns.Renderer.Node.prototype.saveCoords = function() { + var _coords = this.renderer.toModelCoords(this.paper_coords), + _data = { + position: { + x: _coords.x, + y: _coords.y + } + }; + this.model.set(_data); +} + Rkns.Renderer.Node.prototype.mouseup = function(_event) { - if (!this.renderer.is_dragging) { + if (this.renderer.is_dragging) { + this.saveCoords(); + } + else { this.openEditor(); } this.renderer.click_target = null; @@ -480,7 +493,10 @@ } Rkns.Renderer.Edge.prototype.mouseup = function(_event) { - if (!this.renderer.is_dragging) { + if (this.renderer.is_dragging) { + this.from_representation.saveCoords(); + this.to_representation.saveCoords(); + } else { this.openEditor(); } this.renderer.click_target = null; @@ -490,7 +506,6 @@ Rkns.Renderer.Edge.prototype.paperShift = function(_delta) { this.from_representation.paperShift(_delta); this.to_representation.paperShift(_delta); - this.renderer.redraw(); } Rkns.Renderer.Edge.prototype.destroy = function() { @@ -1095,6 +1110,7 @@ paper.view.onResize = function(_event) { _this.offset = _this.offset.add(_event.delta.divide(2)); + _this.resetCoords(); _this.redraw(); } @@ -1170,6 +1186,7 @@ Rkns.Renderer.Scene.prototype.setScale = function(_newScale) { this.scale = _newScale; + this.resetCoords(); this.redraw(); } @@ -1192,6 +1209,12 @@ } } +Rkns.Renderer.Scene.prototype.resetCoords = function(_point) { + _(this.representations).each(function(r) { + r.resetCoords(); + }); +} + Rkns.Renderer.Scene.prototype.toPaperCoords = function(_point) { return _point.multiply(this.scale).add(this.offset); } @@ -1312,6 +1335,7 @@ this.click_target.paperShift(_event.delta); } else { this.offset = this.offset.add(_event.delta); + this.resetCoords(); this.redraw(); } } else {