client/js/paper-renderer.js
changeset 3 7722ec70c01b
parent 2 3360c3f7fb18
child 4 f5297dde9053
equal deleted inserted replaced
2:3360c3f7fb18 3:7722ec70c01b
    27     this.node_text.__controller = this;
    27     this.node_text.__controller = this;
    28     this.redraw();
    28     this.redraw();
    29 }
    29 }
    30 
    30 
    31 Rkns.Renderers.Paper__Controllers.Node.prototype.redraw = function() {
    31 Rkns.Renderers.Paper__Controllers.Node.prototype.redraw = function() {
    32     this.node_model_coords = new paper.Point(this._element.position.x, this._element.position.y);
    32     this.node_model_coords = new paper.Point(this._element.position);
    33     this.node_paper_coords = this._renderer.toPaperCoords(this.node_model_coords);
    33     this.node_paper_coords = this._renderer.toPaperCoords(this.node_model_coords);
    34     this.node_circle.position = this.node_paper_coords;
    34     this.node_circle.position = this.node_paper_coords;
    35     this.node_text.content = this._element.title;
    35     this.node_text.content = this._element.title;
    36     this.node_text.position = this.node_paper_coords.add([0, 35]);
    36     this.node_text.position = this.node_paper_coords.add([0, 35]);
    37     this.node_circle.strokeColor = this._element.created_by.color;
    37     this.node_circle.strokeColor = this._element.created_by.color;
    38 }
    38 }
    39 
    39 
    40 Rkns.Renderers.Paper__Controllers.Node.prototype.paperShift = function(_delta) {
    40 Rkns.Renderers.Paper__Controllers.Node.prototype.paperShift = function(_delta) {
    41     this.node_paper_coords = this.node_paper_coords.add(_delta);
    41     this._element.setPosition(Rkns._FROM_GRAPHICS, this._renderer.toModelCoords(this.node_paper_coords.add(_delta)));
    42     this.node_model_coords = this._renderer.toModelCoords(this.node_paper_coords);
       
    43     this._element.position.x = this.node_model_coords.x;
       
    44     this._element.position.y = this.node_model_coords.y;
       
    45     this._renderer.redraw();
    42     this._renderer.redraw();
    46 }
    43 }
    47 
    44 
    48 /* */
    45 /* */
    49 
    46 
   135         _yy = this._project.nodes.map(function(_node) { return _node.position.y }),
   132         _yy = this._project.nodes.map(function(_node) { return _node.position.y }),
   136         _minx = Math.min.apply(Math, _xx),
   133         _minx = Math.min.apply(Math, _xx),
   137         _miny = Math.min.apply(Math, _yy),
   134         _miny = Math.min.apply(Math, _yy),
   138         _maxx = Math.max.apply(Math, _xx),
   135         _maxx = Math.max.apply(Math, _xx),
   139         _maxy = Math.max.apply(Math, _yy);
   136         _maxy = Math.max.apply(Math, _yy);
   140     this.scale = Math.min((paper.view.size.width - 100) / (_maxx - _minx), (paper.view.size.height - 100) / (_maxy - _miny));
   137     this.scale = Math.min((paper.view.size.width - 160) / (_maxx - _minx), (paper.view.size.height - 100) / (_maxy - _miny));
   141     this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(this.scale));
   138     this.offset = paper.view.center.subtract(new paper.Point([(_maxx + _minx) / 2, (_maxy + _miny) / 2]).multiply(this.scale));
   142     this.nodes = this._project.nodes.map(function(_node) {
   139     this.nodes = this._project.nodes.map(function(_node) {
   143         return new Rkns.Renderers.Paper__Controllers.Node(_this, _node);
   140         return new Rkns.Renderers.Paper__Controllers.Node(_this, _node);
   144     });
   141     });
   145     this.edges = this._project.edges.map(function(_edge) {
   142     this.edges = this._project.edges.map(function(_edge) {
   175         this.offset = this.offset.add(_event.delta);
   172         this.offset = this.offset.add(_event.delta);
   176         this.redraw();
   173         this.redraw();
   177     }
   174     }
   178 }
   175 }
   179 
   176 
   180 Rkns.Renderers.Paper.prototype.onScroll = function(_event, _delta) {
   177 Rkns.Renderers.Paper.prototype.onScroll = function(_event, _scrolldelta) {
   181     this.totalScroll += _delta;
   178     this.totalScroll += _scrolldelta;
   182     if (Math.abs(this.totalScroll) >= 1) {
   179     if (Math.abs(this.totalScroll) >= 1) {
       
   180         var _off = Rkns.$("#"+this._project._opts.canvas_id).offset(),
       
   181             _delta = new paper.Point([
       
   182                 _event.pageX - _off.left,
       
   183                 _event.pageY - _off.top
       
   184             ]).subtract(this.offset).multiply( Math.SQRT2 - 1 );
   183         if (this.totalScroll > 0) {
   185         if (this.totalScroll > 0) {
       
   186             this.offset = this.offset.subtract(_delta);
   184             this.scale *= Math.SQRT2;
   187             this.scale *= Math.SQRT2;
   185         } else {
   188         } else {
       
   189             this.offset = this.offset.add(_delta.divide( Math.SQRT2 ));
   186             this.scale *= Math.SQRT1_2;
   190             this.scale *= Math.SQRT1_2;
   187         }
   191         }
   188         console.log(this.scale);
       
   189         this.totalScroll = 0;
   192         this.totalScroll = 0;
   190         this.redraw();
   193         this.redraw();
   191     }
   194     }
   192 }
   195 }