client/js/paper-renderer.js
changeset 154 0f87088e03bc
parent 153 7fcb35795ff4
child 155 7d5f722d76b2
equal deleted inserted replaced
153:7fcb35795ff4 154:0f87088e03bc
   429     _editor.source_representation = this;
   429     _editor.source_representation = this;
   430     _editor.draw();
   430     _editor.draw();
   431 }
   431 }
   432 
   432 
   433 Rkns.Renderer.Node.prototype.select = function() {
   433 Rkns.Renderer.Node.prototype.select = function() {
       
   434 	this.selected = true;
   434     this.circle.strokeWidth = this.options.selected_node_stroke_width;
   435     this.circle.strokeWidth = this.options.selected_node_stroke_width;
   435     if (this.renderer.isEditable()) {
   436     if (this.renderer.isEditable()) {
   436     	this.buttons.forEach(function(b) {
   437     	this.buttons.forEach(function(b) {
   437     		b.show();
   438     		b.show();
   438     	});
   439     	});
   455     	this.minimap_circle.strokeColor = this.options.minimap_highlight_color;
   456     	this.minimap_circle.strokeColor = this.options.minimap_highlight_color;
   456     }
   457     }
   457 }
   458 }
   458 
   459 
   459 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
   460 Rkns.Renderer.Node.prototype.unselect = function(_newTarget) {
       
   461 	this.selected = false;
   460     if (!_newTarget || _newTarget.source_representation !== this) {
   462     if (!_newTarget || _newTarget.source_representation !== this) {
   461     	this.buttons.forEach(function(b) {
   463     	this.buttons.forEach(function(b) {
   462     		b.hide();
   464     		b.hide();
   463     	});
   465     	});
   464     	this.circle.strokeWidth = this.options.node_stroke_width;
   466     	this.circle.strokeWidth = this.options.node_stroke_width;
   467     		this.minimap_circle.strokeColor = undefined;
   469     		this.minimap_circle.strokeColor = undefined;
   468     	}
   470     	}
   469     }
   471     }
   470 }
   472 }
   471 
   473 
       
   474 Rkns.Renderer.Node.prototype.toggleSelect = function() {
       
   475 	if (this.selected) {
       
   476 		this.unselect(null);
       
   477 	} else {
       
   478 		this.renderer.unselectAll();
       
   479 		this.select();
       
   480 	}
       
   481 }
       
   482 	
   472 Rkns.Renderer.Node.prototype.highlight = function() {
   483 Rkns.Renderer.Node.prototype.highlight = function() {
   473     this.circle.fillColor = this.options.highlighted_node_fill_color;
   484     this.circle.fillColor = this.options.highlighted_node_fill_color;
   474     if (this.node_image) {
   485     if (this.node_image) {
   475         this.node_image.opacity = .5;
   486         this.node_image.opacity = .5;
   476     }
   487     }
   494     if (this.renderer.isEditable()) {
   505     if (this.renderer.isEditable()) {
   495     	this.model.set(_data);
   506     	this.model.set(_data);
   496     }
   507     }
   497 }
   508 }
   498 
   509 
   499 Rkns.Renderer.Node.prototype.mouseup = function(_event) {
   510 Rkns.Renderer.Node.prototype.mouseup = function(_event, _isTouch) {
   500     if (this.renderer.isEditable() && this.renderer.is_dragging) {
   511     if (this.renderer.isEditable() && this.renderer.is_dragging) {
   501         this.saveCoords();
   512         this.saveCoords();
   502     }
   513     } else {
   503     else {
   514     	if (_isTouch) {
   504         this.openEditor();
   515     		this.toggleSelect();
       
   516     		paper.view.draw();
       
   517     	} else {
       
   518     		this.openEditor();
       
   519     	}
   505     }
   520     }
   506     this.renderer.click_target = null;
   521     this.renderer.click_target = null;
   507     this.renderer.is_dragging = false;
   522     this.renderer.is_dragging = false;
   508     this.is_dragging = false;
   523     this.is_dragging = false;
   509 }
   524 }
   631     _editor.source_representation = this;
   646     _editor.source_representation = this;
   632     _editor.draw();
   647     _editor.draw();
   633 }
   648 }
   634 
   649 
   635 Rkns.Renderer.Edge.prototype.select = function() {
   650 Rkns.Renderer.Edge.prototype.select = function() {
       
   651 	this.selected = true;
   636     this.line.strokeWidth = this.options.selected_edge_stroke_width;
   652     this.line.strokeWidth = this.options.selected_edge_stroke_width;
   637     if (this.renderer.isEditable()) {
   653     if (this.renderer.isEditable()) {
   638 	    this.edit_button.show();
   654 	    this.edit_button.show();
   639 	    this.remove_button.show();
   655 	    this.remove_button.show();
   640    	}
   656    	}
   642         this.openEditor();
   658         this.openEditor();
   643     }
   659     }
   644 }
   660 }
   645 
   661 
   646 Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) {
   662 Rkns.Renderer.Edge.prototype.unselect = function(_newTarget) {
       
   663 	this.selected = false;
   647     if (!_newTarget || _newTarget.source_representation !== this) {
   664     if (!_newTarget || _newTarget.source_representation !== this) {
   648     	if (this.options.editor_mode) {
   665     	if (this.options.editor_mode) {
   649 	        this.edit_button.hide();
   666 	        this.edit_button.hide();
   650 	        this.remove_button.hide();
   667 	        this.remove_button.hide();
   651         }
   668         }
   652         this.line.strokeWidth = this.options.edge_stroke_width;
   669         this.line.strokeWidth = this.options.edge_stroke_width;
   653     }
   670     }
   654 }
   671 }
   655 
   672 
   656 Rkns.Renderer.Edge.prototype.mouseup = function(_event) {
   673 Rkns.Renderer.Edge.prototype.toggleSelect = function() {
       
   674 	if (this.selected) {
       
   675 		this.unselect(null);
       
   676 	} else {
       
   677 		this.renderer.unselectAll();
       
   678 		this.select();
       
   679 	}
       
   680 }
       
   681 
       
   682 Rkns.Renderer.Edge.prototype.mouseup = function(_event, _isTouch) {
   657     if (!this.renkan.read_only) {
   683     if (!this.renkan.read_only) {
   658         if (this.renderer.is_dragging) {
   684         if (this.renderer.is_dragging) {
   659             this.from_representation.saveCoords();
   685             this.from_representation.saveCoords();
   660             this.to_representation.saveCoords();
   686             this.to_representation.saveCoords();
   661             this.from_representation.is_dragging = false;
   687             this.from_representation.is_dragging = false;
   662             this.to_representation.is_dragging = false;
   688             this.to_representation.is_dragging = false;
   663         } else {
   689         } else {
   664             this.openEditor();
   690 	    	if (_isTouch) {
   665         }
   691 	    		this.toggleSelect();
       
   692 	    		paper.view.draw();
       
   693 	    	} else {
       
   694 	    		this.openEditor();
       
   695 	    	}
       
   696     	}
   666     }
   697     }
   667     this.renderer.click_target = null;
   698     this.renderer.click_target = null;
   668     this.renderer.is_dragging = false;
   699     this.renderer.is_dragging = false;
   669 }
   700 }
   670 
   701 
   745     var _hitResult = paper.project.hitTest(this.end_pos);
   776     var _hitResult = paper.project.hitTest(this.end_pos);
   746     this.renderer.findTarget(_hitResult);
   777     this.renderer.findTarget(_hitResult);
   747     this.redraw();
   778     this.redraw();
   748 }
   779 }
   749 
   780 
   750 Rkns.Renderer.TempEdge.prototype.mouseup = function(_event) {
   781 Rkns.Renderer.TempEdge.prototype.mouseup = function(_event, _isTouch) {
   751     var _hitResult = paper.project.hitTest(_event.point),
   782     var _hitResult = paper.project.hitTest(_event.point),
   752         _model = this.from_representation.model,
   783         _model = this.from_representation.model,
   753         _endDrag = true;
   784         _endDrag = true;
   754     if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
   785     if (_hitResult && typeof _hitResult.item.__representation !== "undefined") {
   755         var _target = _hitResult.item.__representation;
   786         var _target = _hitResult.item.__representation;
  1299     this.$.html(this.template(_renkan));
  1330     this.$.html(this.template(_renkan));
  1300     this.onStatusChange();
  1331     this.onStatusChange();
  1301     this.canvas_$ = this.$.find(".Rk-Canvas");
  1332     this.canvas_$ = this.$.find(".Rk-Canvas");
  1302     this.editor_$ = this.$.find(".Rk-Editor");
  1333     this.editor_$ = this.$.find(".Rk-Editor");
  1303     this.notif_$ = this.$.find(".Rk-Notifications");
  1334     this.notif_$ = this.$.find(".Rk-Notifications");
       
  1335     this.canvas_$.attr({
       
  1336     	width: this.canvas_$.width(),
       
  1337     	height: this.canvas_$.height()
       
  1338     })
  1304     paper.setup(this.canvas_$[0]);
  1339     paper.setup(this.canvas_$[0]);
  1305     this.scale = 1;
  1340     this.scale = 1;
  1306     this.offset = paper.view.center;
  1341     this.offset = paper.view.center;
  1307     this.totalScroll = 0;
  1342     this.totalScroll = 0;
  1308     this.mouse_down = false;
  1343     this.mouse_down = false;
  1349     
  1384     
  1350     this.bundles = [];
  1385     this.bundles = [];
  1351     this.click_mode = false;
  1386     this.click_mode = false;
  1352     
  1387     
  1353     var _this = this,
  1388     var _this = this,
  1354         _allowScroll = true;
  1389         _allowScroll = true,
       
  1390         _originalScale,
       
  1391         _zooming = false;
  1355     
  1392     
  1356     this.canvas_$.on({
  1393     this.canvas_$.on({
  1357     	mousedown: function(_event) {
  1394     	mousedown: function(_event) {
  1358     		_this.onMouseDown(_event);
  1395     		_this.onMouseDown(_event, false);
  1359     	},
  1396     	},
  1360     	mousemove: function(_event) {
  1397     	mousemove: function(_event) {
  1361         _this.onMouseMove(_event);
  1398         	_this.onMouseMove(_event, false);
  1362 	    },
  1399 	    },
  1363 	    mouseup: function(_event) {
  1400 	    mouseup: function(_event) {
  1364 	        _this.onMouseUp(_event);
  1401 	        _this.onMouseUp(_event, false);
  1365 	    },
  1402 	    },
  1366 	    mousewheel: function(_event, _delta) {
  1403 	    mousewheel: function(_event, _delta) {
  1367 	        if (_allowScroll) {
  1404 	        if (_allowScroll) {
  1368 	        	_this.onScroll(_event, _delta);
  1405 	        	_this.onScroll(_event, _delta);
  1369 	        }
  1406 	        }
  1370 	    },
  1407 	    },
       
  1408 	    touchstart: function(_event) {
       
  1409 	    	_event.preventDefault();
       
  1410 	    	_originalScale = _this.scale;
       
  1411 	    	_zooming = false;
       
  1412 	    	_this.onMouseDown(_event.originalEvent.changedTouches[0], true);
       
  1413 	    },
       
  1414 	    touchmove: function(_event) {
       
  1415 	    	_event.preventDefault();
       
  1416 	    	if (_event.originalEvent.scale == 1) {
       
  1417 	    		_this.onMouseMove(_event.originalEvent.changedTouches[0], true);
       
  1418 	    	} else {
       
  1419 	    		if (!_zooming) {
       
  1420 	    			_this.onMouseUp(_event, true);
       
  1421 			        _this.click_target = null;
       
  1422 			        _this.is_dragging = false;
       
  1423 			        _zooming = true;
       
  1424 	    		}
       
  1425 	    		var _newScale = _event.originalEvent.scale * _originalScale;
       
  1426 	    		//TODO: Correct Offset !
       
  1427 	    		_this.setScale(_newScale, _this.offset);
       
  1428 	    	}
       
  1429 	    },
       
  1430 	    touchend: function(_event) {
       
  1431 	    	_event.preventDefault();
       
  1432 	    	_this.onMouseUp(_event.originalEvent.changedTouches[0], true);
       
  1433 	    },
  1371 	    dblclick: function(_event) {
  1434 	    dblclick: function(_event) {
  1372 	        _this.onDoubleClick(_event);
  1435 	        _this.onDoubleClick(_event);
  1373 	    },
  1436 	    },
  1374 	    mouseleave: function(_event) {
  1437 	    mouseleave: function(_event) {
  1375 	        _this.onMouseUp(_event);
  1438 	        _this.onMouseUp(_event, false);
  1376 	        _this.click_target = null;
  1439 	        _this.click_target = null;
  1377 	        _this.is_dragging = false;
  1440 	        _this.is_dragging = false;
  1378 	    },
  1441 	    },
  1379 	    dragover: function(_event) {
  1442 	    dragover: function(_event) {
  1380 	    	_event.preventDefault();
  1443 	    	_event.preventDefault();
  1496     	for (var i = 0; i < fields.length; i++) {
  1559     	for (var i = 0; i < fields.length; i++) {
  1497     		var f = fields[i];
  1560     		var f = fields[i];
  1498     		if (res["text/x-iri-" + f] || res[f]) {
  1561     		if (res["text/x-iri-" + f] || res[f]) {
  1499     			newNode[f] = res["text/x-iri-" + f] || res[f];
  1562     			newNode[f] = res["text/x-iri-" + f] || res[f];
  1500     		}
  1563     		}
       
  1564     		if (newNode[f] === "none" || newNode[f] === "null") {
       
  1565     			newNode[f] = undefined;
       
  1566     		}
  1501     	}
  1567     	}
  1502     	if (newNode.title || newNode.description || newNode.uri) {
  1568     	if (newNode.title || newNode.description || newNode.uri) {
  1503     		var _off = _this.canvas_$.offset(),
  1569     		var _off = _this.canvas_$.offset(),
  1504             _point = new paper.Point([
  1570             _point = new paper.Point([
  1505                 _event.originalEvent.pageX - _off.left,
  1571                 _event.originalEvent.pageX - _off.left,
  1674     if (this.minimap) {
  1740     if (this.minimap) {
  1675 	    window.setInterval(function() {
  1741 	    window.setInterval(function() {
  1676 	    	_this.rescaleMinimap()
  1742 	    	_this.rescaleMinimap()
  1677 	    }, 2000);
  1743 	    }, 2000);
  1678     }
  1744     }
       
  1745 
  1679 }
  1746 }
  1680 
  1747 
  1681 Rkns.Renderer.Scene.prototype.template = Rkns._.template(
  1748 Rkns.Renderer.Scene.prototype.template = Rkns._.template(
  1682     '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>'
  1749     '<% if (options.show_top_bar) { %><div class="Rk-TopBar"><% if (!options.editor_mode) { %><h2 class="Rk-PadTitle"><%- project.get("title") || translate("Untitled project")%></h2>'
  1683     + '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>'
  1750     + '<% } else { %><input type="text" class="Rk-PadTitle" value="<%- project.get("title") || "" %>" placeholder="<%-translate("Untitled project")%>" /><% } %>'
  1881     Rkns._(this.representations).each(function(_repr) {
  1948     Rkns._(this.representations).each(function(_repr) {
  1882         _repr.unhighlight();
  1949         _repr.unhighlight();
  1883     });
  1950     });
  1884 }
  1951 }
  1885 
  1952 
       
  1953 Rkns.Renderer.Scene.prototype.unselectAll = function(_model) {
       
  1954     Rkns._(this.representations).each(function(_repr) {
       
  1955         _repr.unselect();
       
  1956     });
       
  1957 }
       
  1958 
  1886 Rkns.Renderer.Scene.prototype.redraw = function() {
  1959 Rkns.Renderer.Scene.prototype.redraw = function() {
  1887     Rkns._(this.representations).each(function(_representation) {
  1960     Rkns._(this.representations).each(function(_representation) {
  1888     	_representation.redraw(true);
  1961     	_representation.redraw(true);
  1889     });
  1962     });
  1890     if (this.minimap) {
  1963     if (this.minimap) {
  1911             _newTarget.select(this.selected_target);
  1984             _newTarget.select(this.selected_target);
  1912             this.selected_target = _newTarget;
  1985             this.selected_target = _newTarget;
  1913         }
  1986         }
  1914     } else {
  1987     } else {
  1915         if (this.selected_target) {
  1988         if (this.selected_target) {
  1916             this.selected_target.unselect(null);
  1989             this.selected_target.unselect();
  1917         }
  1990         }
  1918         this.selected_target = null;
  1991         this.selected_target = null;
  1919     }
  1992     }
  1920 }
  1993 }
  1921 
  1994 
  1946         this.findTarget(_hitResult);
  2019         this.findTarget(_hitResult);
  1947     }
  2020     }
  1948     paper.view.draw();
  2021     paper.view.draw();
  1949 }
  2022 }
  1950 
  2023 
  1951 Rkns.Renderer.Scene.prototype.onMouseDown = function(_event) {
  2024 Rkns.Renderer.Scene.prototype.onMouseDown = function(_event, _isTouch) {
  1952     var _off = this.canvas_$.offset(),
  2025     var _off = this.canvas_$.offset(),
  1953     	_point = new paper.Point([
  2026     	_point = new paper.Point([
  1954             _event.pageX - _off.left,
  2027             _event.pageX - _off.left,
  1955             _event.pageY - _off.top
  2028             _event.pageY - _off.top
  1956         ]);
  2029         ]);
  1996             this.click_mode = false;
  2069             this.click_mode = false;
  1997         }
  2070         }
  1998     }
  2071     }
  1999 }
  2072 }
  2000 
  2073 
  2001 Rkns.Renderer.Scene.prototype.onMouseUp = function(_event) {
  2074 Rkns.Renderer.Scene.prototype.onMouseUp = function(_event, _isTouch) {
  2002 	this.mouse_down = false;
  2075 	this.mouse_down = false;
  2003     if (this.click_target) {
  2076     if (this.click_target) {
  2004         var _off = this.canvas_$.offset();
  2077         var _off = this.canvas_$.offset();
  2005         this.click_target.mouseup(
  2078         this.click_target.mouseup(
  2006             {
  2079             {
  2007                 point: new paper.Point([
  2080                 point: new paper.Point([
  2008                     _event.pageX - _off.left,
  2081                     _event.pageX - _off.left,
  2009                     _event.pageY - _off.top
  2082                     _event.pageY - _off.top
  2010                 ])
  2083                 ])
  2011             }
  2084             },
       
  2085             _isTouch
  2012         );
  2086         );
  2013     } else {
  2087     } else {
  2014         this.click_target = null;
  2088         this.click_target = null;
  2015         this.is_dragging = false;
  2089         this.is_dragging = false;
       
  2090         if (_isTouch) {
       
  2091         	this.unselectAll();
       
  2092         	paper.view.draw();
       
  2093         }
  2016     }
  2094     }
  2017 }
  2095 }
  2018 
  2096 
  2019 Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) {
  2097 Rkns.Renderer.Scene.prototype.onScroll = function(_event, _scrolldelta) {
  2020     this.totalScroll += _scrolldelta;
  2098     this.totalScroll += _scrolldelta;