tentone преди 5 години
родител
ревизия
4844f39b03
променени са 5 файла, в които са добавени 56 реда и са изтрити 12 реда
  1. 5 6
      build/escher.js
  2. 8 0
      source/Object2D.js
  3. 4 0
      source/Renderer.js
  4. 12 2
      source/objects/node/NodeConnector.js
  5. 27 4
      source/objects/node/NodeHook.js

+ 5 - 6
build/escher.js

@@ -905,7 +905,7 @@
 		/**
 		 * Indicates if this object uses pointer events.
 		 *
-		 * Can be set false to skip the pointer interaction events (improves performance).
+		 * Can be set false to skip the pointer interaction events, better performance if pointer events are not required.
 		 *
 		 * @type {boolean}
 		 */
@@ -3476,14 +3476,14 @@
 		 *
 		 * @type {NodeHook}
 		 */
-		this.origin = null;
+		this.outputHook = null;
 
 		/**
 		 * Destination hook that is attached to a node.
 		 *
 		 * @type {NodeHook}
 		 */
-		this.destination = null;
+		this.inputHook = null;
 	}
 
 	NodeConnector.prototype = Object.create(BezierCurve.prototype);
@@ -3580,14 +3580,13 @@
 		if(this.connector === null)
 		{
 			var connector = new NodeConnector();
-
 			if(this.direction === NodeHook.INPUT)
 			{
-				connector.destination = this;
+				connector.inputHook = this;
 			}
 			else if(this.direction === NodeHook.OUTPUT)
 			{
-				connector.origin = this;
+				connector.outputHook = this;
 			}
 
 			this.node.parent.add(connector);

+ 8 - 0
source/Object2D.js

@@ -378,6 +378,14 @@ Object2D.prototype.onPointerDrag = function(pointer, viewport, delta)
 	this.position.add(delta);
 };
 
+/**
+ * Callback method called when the pointer drag ends after the button has been released.
+ *
+ * @param {Pointer} pointer Pointer object that receives the user input.
+ * @param {Viewport} viewport Viewport where the object is drawn.
+ */
+Object2D.prototype.onPointerDragEnd = null;
+
 /**
  * Method called when the object its added to a parent.
  *

+ 4 - 0
source/Renderer.js

@@ -195,6 +195,10 @@ Renderer.prototype.update = function(object, viewport)
 			{	
 				if(child.draggable)
 				{
+					if(child.onPointerDragEnd !== null)
+					{
+						child.onPointerDragEnd(pointer, viewport);
+					}
 					child.beingDragged = false;
 				}
 			}

+ 12 - 2
source/objects/node/NodeConnector.js

@@ -1,4 +1,6 @@
 import {BezierCurve} from "../BezierCurve";
+import {Box} from "../Box";
+import {Node} from "./Node";
 
 /**
  * Node connector is used to connect a output of a node to a input of another node.
@@ -16,16 +18,24 @@ function NodeConnector()
 	 *
 	 * @type {NodeHook}
 	 */
-	this.origin = null;
+	this.outputHook = null;
 
 	/**
 	 * Destination hook that is attached to a node.
 	 *
 	 * @type {NodeHook}
 	 */
-	this.destination = null;
+	this.inputHook = null;
 }
 
 NodeConnector.prototype = Object.create(BezierCurve.prototype);
 
+NodeConnector.prototype.draw = function(context, viewport, canvas)
+{
+	// TODO <SET POSITIONS>
+
+	BezierCurve.prototype.draw.call(this, context, viewport, canvas);
+};
+
+
 export {NodeConnector};

+ 27 - 4
source/objects/node/NodeHook.js

@@ -1,6 +1,7 @@
 import {Circle} from "../Circle";
 import {Node} from "./Node";
 import {NodeConnector} from "./NodeConnector";
+import {Object2D} from "../../Object2D";
 
 /**
  * Represents a node hook point. Is attached to the node element and represented visually.
@@ -15,6 +16,8 @@ function NodeHook(node, direction)
 {
 	Circle.call(this);
 
+	this.draggable = true;
+
 	this.radius = 6;
 	this.layer = 1;
 
@@ -90,22 +93,42 @@ NodeHook.prototype = Object.create(Circle.prototype);
 
 NodeHook.prototype.onButtonPressed = function()
 {
-	// Create new connector
 	if(this.connector === null)
 	{
-		var connector = new NodeConnector();
+		// TODO <REMOVE THIS>
+		console.log("Create a new connector.")
 
+		var connector = new NodeConnector();
 		if(this.direction === NodeHook.INPUT)
 		{
-			connector.destination = this;
+			connector.inputHook = this;
 		}
 		else if(this.direction === NodeHook.OUTPUT)
 		{
-			connector.origin = this;
+			connector.outputHook = this;
 		}
 
+		this.connector = connector;
 		this.node.parent.add(connector);
 	}
 };
 
+NodeHook.prototype.onPointerDrag = function(pointer, viewport, delta)
+{
+	if(this.connector !== null)
+	{
+		// TODO <REMOVE THIS>
+		console.log("Dragging around");
+	}
+};
+
+NodeHook.prototype.onPointerDragEnd = function(pointer, viewport)
+{
+	if(this.connector !== null)
+	{
+		// TODO <REMOVE THIS>
+		console.log("Finished drag.");
+	}
+};
+
 export {NodeHook};