|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- int nodeCount;
- int i_selectedNode = -1;
- int padding = textSize/3*2; //Padding between text and surrounding box
- int letTolerance = 10; //Widens the clickable areas of in/outlets a bit
-
- void addNode(int x, int y, String title) {
- nodes[nodeCount] = new Node(x, y, title);
- nodeCount++;
- }
-
- void deselect() {
- i_selectedNode = -1;
- }
-
- void deleteSelectedNode() { //Seperate from class for garbage collector reasons
- if (i_selectedNode != -1) {
- for (int i = 0; i < linkCount; i++) {
- if (links[i].targetNode == i_selectedNode || links[i].parentNode == i_selectedNode) {
- links[i].active = false;
- }
- }
- nodes[i_selectedNode].deleted = true;
- i_selectedNode = -1;
- }
- }
-
- class Node {
- String title;
- int id;
- int inlets = 2;
- int outlets = 2;
- int x, y;
- int h = textSize+2*padding;
- int w = textSize+2*padding;
- PVector dragMouseStartPoint = new PVector(0, 0);
- PVector outletCenter = new PVector(0, 0);
- PVector inletCenter = new PVector(0, 0);
- boolean deleted;
- boolean drag;
- boolean hover() {
- if (mouseX > x-w/2 && mouseX < x+w/2 && mouseY > y-h/2 && mouseY < y+h/2) {
- return true;
- } else {
- return false;
- }
- }
- boolean hoverOutlet() {
- if (mouseX > x-(textSize+padding)/2-letTolerance && mouseX < x+(textSize+padding)/2+letTolerance && mouseY > y-padding-textSize/2-(textSize+padding)/2-letTolerance && mouseY < y-padding-textSize/2) {
- return true;
- } else {
- return false;
- }
- }
- boolean hoverInlet() {
- if (mouseX > x-(textSize+padding)/2-letTolerance && mouseX < x+(textSize+padding)/2+letTolerance && mouseY > y+padding+textSize/2 && mouseY < y+padding+textSize/2+(textSize+padding)/2+letTolerance) {
- return true;
- } else {
- return false;
- }
- }
-
- Node(int x_, int y_, String title_) {
- id = nodeCount;
- title = title_;
- x = x_;
- y = y_;
- setVectors();
- refreshSize();
- }
-
- void setVectors() {
- outletCenter.x = x;
- outletCenter.y = y-(padding+textSize/2)*1.3;
- inletCenter.x = x;
- inletCenter.y = y+(padding+textSize/2)*1.3;
- }
-
- /**
- * Called when changing nodes title or when zooming via mouse-wheel
- */
- void refreshSize() {
- w = int(textWidth(title))+2*padding;
- h = textSize+2*padding;
- }
-
- /**
- * Update-function is really only necessary when dragging the node
- */
- void update() {
- if (drag) {
- x -= dragMouseStartPoint.x - mouseX;
- dragMouseStartPoint.x = mouseX;
- y -= dragMouseStartPoint.y - mouseY;
- dragMouseStartPoint.y = mouseY;
- setVectors();
- }
- }
-
- void display() {
- /**
- * Selected nodes border
- */
- if (i_selectedNode == id) {
- noStroke();
- fill(150, 100);
- rect(x, y, w+20, h+20, 4);
- }
-
- /**
- * Inlet & Outlet
- */
- stroke(255, darkMode? 255 : 0);
- strokeWeight(1);
- fill(255, 0, 0);
- ellipse(x, y-padding-textSize/2, textSize+padding, textSize+padding);
- fill(0);
- ellipse(x, y+padding+textSize/2, textSize+padding, textSize+padding);
-
- /**
- * Box & Title
- */
- stroke(127);
- strokeWeight(2);
- fill(50);
- rect(x, y, w, h, 4);
- fill(255);
- text(title, x, y+textSize/3);
- }
- }
|