client/js/paper-renderer.js
changeset 39 84eea249ce7e
parent 38 092fc99f7558
child 43 90f6937c417e
equal deleted inserted replaced
38:092fc99f7558 39:84eea249ce7e
   190 Rkns.Renderer._BaseRepresentation = function(_renderer, _model) {
   190 Rkns.Renderer._BaseRepresentation = function(_renderer, _model) {
   191     if (typeof _renderer !== "undefined") {
   191     if (typeof _renderer !== "undefined") {
   192         this.renderer = _renderer;
   192         this.renderer = _renderer;
   193         this.project = _renderer.renkan.project;
   193         this.project = _renderer.renkan.project;
   194         this.model = _model;
   194         this.model = _model;
   195     }
   195         if (this.model) {
       
   196             var _this = this;
       
   197             this._changeBinding = function() {
       
   198                 _this.redraw();
       
   199             }
       
   200             this._removeBinding = function() {
       
   201                 _renderer.removeRepresentation(_this);
       
   202                 _renderer.redraw();
       
   203             }
       
   204             this.model.on("change", this._changeBinding );
       
   205             this.model.on("remove", this._removeBinding );
       
   206         }
       
   207     }
       
   208 }
       
   209 
       
   210 Rkns.Renderer._BaseRepresentation.prototype.super = function(_func) {
       
   211     Rkns.Renderer._BaseRepresentation.prototype[_func].apply(this, Array.prototype.slice.call(arguments, 1));
   196 }
   212 }
   197 
   213 
   198 Rkns.Renderer._BaseRepresentation.prototype.select = function() {}
   214 Rkns.Renderer._BaseRepresentation.prototype.select = function() {}
   199 
   215 
   200 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {}
   216 Rkns.Renderer._BaseRepresentation.prototype.unselect = function() {}
   203 
   219 
   204 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {}
   220 Rkns.Renderer._BaseRepresentation.prototype.unhighlight = function() {}
   205 
   221 
   206 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {}
   222 Rkns.Renderer._BaseRepresentation.prototype.mouseup = function() {}
   207 
   223 
   208 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {}
   224 Rkns.Renderer._BaseRepresentation.prototype.destroy = function() {
       
   225     if (this.model) {
       
   226         this.model.off("change", this._changeBinding );
       
   227         this.model.off("remove", this._removeBinding );
       
   228     }
       
   229 }
   209 
   230 
   210 Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
   231 Rkns.Renderer.Node = Rkns.Utils.inherit(Rkns.Renderer._BaseRepresentation);
   211 
   232 
   212 Rkns.Renderer.Node.prototype._init = function() {
   233 Rkns.Renderer.Node.prototype._init = function() {
   213     this.renderer.node_layer.activate();
   234     this.renderer.node_layer.activate();
   218     this.title = new paper.PointText([0,0]);
   239     this.title = new paper.PointText([0,0]);
   219     this.title.characterStyle = {
   240     this.title.characterStyle = {
   220         fontSize: Rkns.Renderer._NODE_FONT_SIZE,
   241         fontSize: Rkns.Renderer._NODE_FONT_SIZE,
   221         fillColor: 'black'
   242         fillColor: 'black'
   222     };
   243     };
   223     this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, {});
   244     this.edit_button = new Rkns.Renderer.NodeEditButton(this.renderer, null);
   224     this.edit_button.node_representation = this;
   245     this.edit_button.node_representation = this;
   225     this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, {});
   246     this.remove_button = new Rkns.Renderer.NodeRemoveButton(this.renderer, null);
   226     this.remove_button.node_representation = this;
   247     this.remove_button.node_representation = this;
   227     this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, {});
   248     this.link_button = new Rkns.Renderer.NodeLinkButton(this.renderer, null);
   228     this.link_button.node_representation = this;
   249     this.link_button.node_representation = this;
   229     this.title.paragraphStyle.justification = 'center';
   250     this.title.paragraphStyle.justification = 'center';
   230 }
   251 }
   231 
   252 
   232 Rkns.Renderer.Node.prototype.redraw = function() {
   253 Rkns.Renderer.Node.prototype.redraw = function() {
   340     this.renderer.click_target = null;
   361     this.renderer.click_target = null;
   341     this.renderer.is_dragging = false;
   362     this.renderer.is_dragging = false;
   342 }
   363 }
   343 
   364 
   344 Rkns.Renderer.Node.prototype.destroy = function(_event) {
   365 Rkns.Renderer.Node.prototype.destroy = function(_event) {
       
   366     this.super("destroy");
   345     this.edit_button.destroy();
   367     this.edit_button.destroy();
   346     this.remove_button.destroy();
   368     this.remove_button.destroy();
   347     this.link_button.destroy();
   369     this.link_button.destroy();
   348     this.circle.remove();
   370     this.circle.remove();
   349     this.title.remove();
   371     this.title.remove();
   374         fillColor: 'black'
   396         fillColor: 'black'
   375     };
   397     };
   376     this.text.paragraphStyle.justification = 'center';
   398     this.text.paragraphStyle.justification = 'center';
   377     this.text_angle = 0;
   399     this.text_angle = 0;
   378     this.arrow_angle = 0;
   400     this.arrow_angle = 0;
   379     this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, {});
   401     this.edit_button = new Rkns.Renderer.EdgeEditButton(this.renderer, null);
   380     this.edit_button.edge_representation = this;
   402     this.edit_button.edge_representation = this;
   381     this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, {});
   403     this.remove_button = new Rkns.Renderer.EdgeRemoveButton(this.renderer, null);
   382     this.remove_button.edge_representation = this;
   404     this.remove_button.edge_representation = this;
   383 }
   405 }
   384 
   406 
   385 Rkns.Renderer.Edge.prototype.redraw = function() {
   407 Rkns.Renderer.Edge.prototype.redraw = function() {
   386     var _p0a = this.from_representation.paper_coords,
   408     var _p0a = this.from_representation.paper_coords,
   454     this.to_representation.paperShift(_delta);
   476     this.to_representation.paperShift(_delta);
   455     this.renderer.redraw();
   477     this.renderer.redraw();
   456 }
   478 }
   457 
   479 
   458 Rkns.Renderer.Edge.prototype.destroy = function() {
   480 Rkns.Renderer.Edge.prototype.destroy = function() {
       
   481     this.super("destroy");
   459     this.line.remove();
   482     this.line.remove();
   460     this.arrow.remove();
   483     this.arrow.remove();
   461     this.text.remove();
   484     this.text.remove();
   462     this.edit_button.destroy();
   485     this.edit_button.destroy();
   463     this.remove_button.destroy();
   486     this.remove_button.destroy();
  1119 }
  1142 }
  1120 
  1143 
  1121 Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) {
  1144 Rkns.Renderer.Scene.prototype.addRepresentation = function(_type, _model) {
  1122     var _repr = new Rkns.Renderer[_type](this, _model);
  1145     var _repr = new Rkns.Renderer[_type](this, _model);
  1123     this.representations.push(_repr);
  1146     this.representations.push(_repr);
  1124     if (_model) {
       
  1125         var _this = this;
       
  1126         _model.on("change", function() {
       
  1127             _repr.redraw();
       
  1128         });
       
  1129         _model.on("remove", function() {
       
  1130             _this.removeRepresentation(_repr);
       
  1131             _this.redraw();
       
  1132         });
       
  1133     }
       
  1134     return _repr;
  1147     return _repr;
  1135 }
  1148 }
  1136 
  1149 
  1137 Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) {
  1150 Rkns.Renderer.Scene.prototype.addRepresentations = function(_type, _collection) {
  1138     var _this = this;
  1151     var _this = this;