|
@@ -15,7 +15,7 @@
|
|
|
<div style="position:absolute; width:60px; height:50px; top:50px; left:10px; text-align:center; z-index:10; cursor: pointer;" onclick="window.addOperatorBlock('-');">-</div>
|
|
|
<div style="position:absolute; width:60px; height:50px; top:100px; left:10px; text-align:center; z-index:10; cursor: pointer;" onclick="window.addOperatorBlock('*');">x</div>
|
|
|
<div style="position:absolute; width:60px; height:50px; top:150px; left:10px; text-align:center; z-index:10; cursor: pointer;" onclick="window.addOperatorBlock('/');">/</div>
|
|
|
- <div style="position:absolute; width:60px; height:50px; top:200px; left:10px; text-align:center; z-index:10; cursor: pointer;" onclick="window.addConstantBlock(prompt('Input value'));">Num</div>
|
|
|
+ <div style="position:absolute; width:60px; height:50px; top:200px; left:10px; text-align:center; z-index:10; cursor: pointer;" onclick="window.addInputBlock();">Num</div>
|
|
|
</div>
|
|
|
|
|
|
<!-- Code -->
|
|
@@ -42,35 +42,71 @@
|
|
|
|
|
|
window.addOperatorBlock = function(symbol)
|
|
|
{
|
|
|
- // Box
|
|
|
- var node = new Escher.Node();
|
|
|
- node.position.set(100, 100);
|
|
|
- node.draggable = true;
|
|
|
- group.add(node);
|
|
|
-
|
|
|
- // DOM
|
|
|
- var div = new Escher.DOM(canvas.parentElement);
|
|
|
- div.size.set(100, 50);
|
|
|
- div.origin.set(50, 25);
|
|
|
- node.add(div);
|
|
|
-
|
|
|
- var text = document.createElement("div");
|
|
|
- text.style.fontFamily = "Arial";
|
|
|
- text.style.textAlign = "center";
|
|
|
- text.innerHTML = symbol;
|
|
|
- div.element.appendChild(text);
|
|
|
+ graph.addNode(new OperationNode(symbol));
|
|
|
};
|
|
|
|
|
|
|
|
|
+ window.addInputBlock = function(symbol)
|
|
|
+ {
|
|
|
+ graph.addNode(new NumberInputNode());
|
|
|
+ };
|
|
|
+
|
|
|
+ class OperationNode extends Escher.Node
|
|
|
+ {
|
|
|
+ constructor(operation)
|
|
|
+ {
|
|
|
+ super();
|
|
|
+
|
|
|
+ this.operation = operation;
|
|
|
+
|
|
|
+ this.text = new Escher.Text();
|
|
|
+ this.text.text = operation;
|
|
|
+ this.text.font = "35px Arial";
|
|
|
+ this.text.layer = 2;
|
|
|
+
|
|
|
+ this.add(this.text);
|
|
|
+ }
|
|
|
+
|
|
|
+ registerSockets()
|
|
|
+ {
|
|
|
+ this.addInput("number", "a");
|
|
|
+ this.addInput("number", "b");
|
|
|
+ this.addOutput("number", "r");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ class NumberInputNode extends Escher.Node
|
|
|
+ {
|
|
|
+ constructor()
|
|
|
+ {
|
|
|
+ super();
|
|
|
+
|
|
|
+ this.div = new Escher.DOM(canvas.parentElement);
|
|
|
+ this.div.size.set(100, 50);
|
|
|
+ this.div.origin.set(50, 25);
|
|
|
+ this.add(this.div);
|
|
|
+
|
|
|
+ this.input = document.createElement("input");
|
|
|
+ this.input.type = "number";
|
|
|
+ this.input.style.fontFamily = "Arial";
|
|
|
+ this.input.style.textAlign = "center";
|
|
|
+ this.div.element.appendChild(this.input);
|
|
|
+ }
|
|
|
+
|
|
|
+ registerSockets()
|
|
|
+ {
|
|
|
+ this.addOutput("number", "v");
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
// Group to store other objects
|
|
|
var graph = new Escher.NodeGraph();
|
|
|
|
|
|
- var a = graph.createNode(Escher.Node);
|
|
|
+ var a = graph.addNode(new Escher.Node());
|
|
|
a.addInput("test", "a");
|
|
|
var aa = a.addOutput("test", "a");
|
|
|
|
|
|
- var b = graph.createNode(Escher.Node);
|
|
|
+ var b = graph.addNode(new Escher.Node());
|
|
|
var bb = b.addInput("test", "a");
|
|
|
b.addInput("test", "b");
|
|
|
b.addInput("test", "c");
|