initial
This commit is contained in:
60
build/application.linux-arm64/source/links.pde
Normal file
60
build/application.linux-arm64/source/links.pde
Normal file
@@ -0,0 +1,60 @@
|
||||
int linkCount;
|
||||
|
||||
boolean dragLink; //state of dragging a link
|
||||
int dragOriginLet = 0; //dragging from inlet: -1. dragging from outlet: 1.
|
||||
int dragOriginId = -1; //which nodes out- / inlet did user click on?
|
||||
|
||||
void Link(int parentNode, int targetNode) {
|
||||
/**
|
||||
* Check if user is adding or removing a link
|
||||
*/
|
||||
int exists = -1;
|
||||
for (int i = 0; i < linkCount; i++) {
|
||||
if (links[i].parentNode == parentNode && links[i].targetNode == targetNode) {
|
||||
exists = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (exists != -1) {
|
||||
/**
|
||||
* !active state is pretty much the same as deleted state that the node-class comes with
|
||||
*/
|
||||
links[exists].active = !links[exists].active;
|
||||
} else {
|
||||
links[linkCount] = new Link(parentNode, targetNode);
|
||||
linkCount++;
|
||||
}
|
||||
}
|
||||
|
||||
class Link {
|
||||
int parentNode, targetNode;
|
||||
boolean active;
|
||||
PVector link = new PVector(0, 0);
|
||||
|
||||
Link(int parentNode_, int targetNode_) {
|
||||
parentNode = parentNode_;
|
||||
targetNode = targetNode_;
|
||||
active = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* This could be an event that only gets called when nodes are moved or resized.
|
||||
*/
|
||||
void update() {
|
||||
link.x = nodes[targetNode].inletCenter.x - nodes[parentNode].outletCenter.x;
|
||||
link.y = nodes[targetNode].inletCenter.y - nodes[parentNode].outletCenter.y;
|
||||
}
|
||||
|
||||
void display() {
|
||||
stroke(darkMode? 255 : 0);
|
||||
strokeWeight(2);
|
||||
pushMatrix();
|
||||
translate(nodes[parentNode].outletCenter.x, nodes[parentNode].outletCenter.y);
|
||||
line(0, 0, link.x, link.y);
|
||||
translate(-nodes[parentNode].outletCenter.x+(nodes[parentNode].outletCenter.x+nodes[targetNode].inletCenter.x)/2, -nodes[parentNode].outletCenter.y+(nodes[parentNode].outletCenter.y+nodes[targetNode].inletCenter.y)/2);
|
||||
rotate(link.heading());
|
||||
fill(darkMode? 0 : 255);
|
||||
triangle(0, textSize/2, textSize, 0, 0, -textSize/2);
|
||||
popMatrix();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user