client/js/paper-renderer.js
changeset 21 b43dd87f7ffa
parent 20 bd58970ffd16
child 23 70c8af9b44ec
equal deleted inserted replaced
20:bd58970ffd16 21:b43dd87f7ffa
   378     this.arrow_angle = _a;
   378     this.arrow_angle = _a;
   379 }
   379 }
   380 
   380 
   381 Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) {
   381 Rkns.Renderer.TempEdge.prototype.paperShift = function(_delta) {
   382     this.end_pos = this.end_pos.add(_delta);
   382     this.end_pos = this.end_pos.add(_delta);
   383     this._renderer.onMouseMove({point: this.end_pos});
   383     var _hitResult = paper.project.hitTest(this.end_pos);
       
   384     this._renderer.findTarget(_hitResult);
   384     this.redraw();
   385     this.redraw();
   385 }
   386 }
   386 
   387 
   387 Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) {
   388 Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) {
   388     var _hitResult = paper.project.hitTest(_event.point);
   389     var _hitResult = paper.project.hitTest(_event.point);
   777         _this.onMouseDown(_event);
   778         _this.onMouseDown(_event);
   778     }
   779     }
   779     _tool.onMouseDrag = function(_event) {
   780     _tool.onMouseDrag = function(_event) {
   780         _this.onMouseDrag(_event);
   781         _this.onMouseDrag(_event);
   781     }
   782     }
   782     _tool.onMouseUp = function(_event) {
   783     this.canvas_$.mouseup(function(_event) {
   783         _this.onMouseUp(_event);
   784         _this.onMouseUp(_event);
   784     }
   785     });
   785     this.canvas_$.mousewheel(function(_event, _delta) {
   786     this.canvas_$.mousewheel(function(_event, _delta) {
   786         _this.onScroll(_event, _delta);
   787         _this.onScroll(_event, _delta);
   787     })
   788     });
   788     this.canvas_$.dblclick(function(_event) {
   789     this.canvas_$.dblclick(function(_event) {
   789         _this.onDoubleClick(_event);
   790         _this.onDoubleClick(_event);
       
   791     });
       
   792     this.canvas_$.mouseenter(function(_event) {
       
   793         _this.onMouseEnter(_event);
   790     });
   794     });
   791     this.editor_$.find(".Rk-ZoomOut").click(function() {
   795     this.editor_$.find(".Rk-ZoomOut").click(function() {
   792         _this.offset = new paper.Point([
   796         _this.offset = new paper.Point([
   793             _this.canvas_$.width(),
   797             _this.canvas_$.width(),
   794             _this.canvas_$.height()
   798             _this.canvas_$.height()
   880     _tmpEdge.from_controller = _from;
   884     _tmpEdge.from_controller = _from;
   881     _tmpEdge.redraw();
   885     _tmpEdge.redraw();
   882     this.click_target = _tmpEdge;
   886     this.click_target = _tmpEdge;
   883 }
   887 }
   884 
   888 
   885 Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) {
   889 Rkns.Renderer.Scene.prototype.findTarget = function(_hitResult) {
   886     var _hitResult = paper.project.hitTest(_event.point);
       
   887     if (_hitResult && typeof _hitResult.item.__controller !== "undefined") {
   890     if (_hitResult && typeof _hitResult.item.__controller !== "undefined") {
   888         var _newTarget = _hitResult.item.__controller;
   891         var _newTarget = _hitResult.item.__controller;
   889         if (this.selected_target !== _hitResult.item.__controller) {
   892         if (this.selected_target !== _hitResult.item.__controller) {
   890             if (this.selected_target) {
   893             if (this.selected_target) {
   891                 this.selected_target.unselect(_newTarget);
   894                 this.selected_target.unselect(_newTarget);
   899         }
   902         }
   900         this.selected_target = null;
   903         this.selected_target = null;
   901     }
   904     }
   902 }
   905 }
   903 
   906 
       
   907 Rkns.Renderer.Scene.prototype.onMouseMove = function(_event) {
       
   908     var _hitResult = paper.project.hitTest(_event.point);
       
   909     if (this.is_dragging) {
       
   910         if (this.click_target && typeof this.click_target.paperShift === "function") {
       
   911             this.click_target.paperShift(_event.delta);
       
   912         } else {
       
   913             this.offset = this.offset.add(_event.delta);
       
   914             this.redraw();
       
   915         }
       
   916     } else {
       
   917         this.findTarget(_hitResult);
       
   918     }
       
   919 }
       
   920 
   904 Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) {
   921 Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) {
   905     this.is_dragging = false;
   922     this.is_dragging = false;
   906     var _hitResult = paper.project.hitTest(_event.point);
   923     var _hitResult = paper.project.hitTest(_event.point);
   907     if (_hitResult && typeof _hitResult.item.__controller !== "undefined") {
   924     if (_hitResult && typeof _hitResult.item.__controller !== "undefined") {
   908         this.click_target = _hitResult.item.__controller;
   925         this.click_target = _hitResult.item.__controller;
   917     }
   934     }
   918 }
   935 }
   919 
   936 
   920 Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) {
   937 Rkns.Renderer.Scene.prototype.onMouseDrag = function(_event) {
   921     this.is_dragging = true;
   938     this.is_dragging = true;
   922     if (this.click_target && typeof this.click_target.paperShift === "function") {
   939     this.onMouseMove(_event);
   923         this.click_target.paperShift(_event.delta);
       
   924     } else {
       
   925         this.offset = this.offset.add(_event.delta);
       
   926         this.redraw();
       
   927     }
       
   928 }
   940 }
   929 
   941 
   930 Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) {
   942 Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) {
   931     if (this.click_target) {
   943     if (this.click_target) {
   932         this.click_target.mouseup(_event);
   944         var _off = this.canvas_$.offset();
       
   945         this.click_target.mouseup(
       
   946             {
       
   947                 point: new paper.Point([
       
   948                     _event.pageX - _off.left,
       
   949                     _event.pageY - _off.top
       
   950                 ])
       
   951             }
       
   952         );
   933     }
   953     }
   934     this.is_dragging = false;
   954     this.is_dragging = false;
   935     this.click_target = null;
   955     this.click_target = null;
   936 }
   956 }
   937 
   957 
   972             }, Rkns._RENDER_AND_SAVE);
   992             }, Rkns._RENDER_AND_SAVE);
   973         _node.__controller.openEditor();
   993         _node.__controller.openEditor();
   974     }
   994     }
   975     paper.view.draw();
   995     paper.view.draw();
   976 }
   996 }
       
   997 
       
   998 Rkns.Renderer.Scene.prototype.onMouseEnter = function(_event) {
       
   999     var _newEl = this.renkan.selected_bin_item;
       
  1000     if (_newEl) {
       
  1001         var _off = this.canvas_$.offset(),
       
  1002             _point = new paper.Point([
       
  1003                 _event.pageX - _off.left,
       
  1004                 _event.pageY - _off.top
       
  1005             ]),
       
  1006             _coords = this.toModelCoords(_point),
       
  1007             _node = this._project.addNode({
       
  1008                 uri: _newEl.uri,
       
  1009                 title: _newEl.title,
       
  1010                 description: _newEl.description,
       
  1011                 position: {
       
  1012                     x: _coords.x,
       
  1013                     y: _coords.y
       
  1014                 }
       
  1015             }, Rkns._RENDER_AND_SAVE);
       
  1016         this.is_dragging = true;
       
  1017         this.click_target = _node.__controller;
       
  1018     }
       
  1019 }