123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 |
- /**
- * Keys only get caught for changing a nodes title.
- * Previous title is remembered in savedTitle and restored when hitting Escape
- */
- String savedTitle;
-
- void keyPressed() {
- if (key == ESC) {
- key = 0;
- }
- if (i_selectedNode != -1) {
- if (keyCode == BACKSPACE) {
- if (nodes[i_selectedNode].title.length() > 0) {
- nodes[i_selectedNode].title = nodes[i_selectedNode].title.substring(0, nodes[i_selectedNode].title.length()-1);
- nodes[i_selectedNode].refreshSize();
- }
- } else if (keyCode == DELETE) {
- deleteSelectedNode();
- } else if (keyCode == ESC) {
- nodes[i_selectedNode].title = savedTitle;
- nodes[i_selectedNode].refreshSize();
- deselect();
- } else if (keyCode == RETURN || keyCode == ENTER) {
- deselect();
- } else if (keyCode != SHIFT && keyCode != RETURN && keyCode != ENTER && keyCode != CONTROL) {
- nodes[i_selectedNode].title = nodes[i_selectedNode].title + key;
- nodes[i_selectedNode].refreshSize();
- }
- }
- }
-
-
- void mousePressed() {
- if (mouseButton == LEFT) {
- /**
- * Either press a button...
- */
- boolean buttonClicked = false;
- for (int i = 0; i < buttons.length; i++) {
- if (buttons[i].hover()) {
- buttons[i].click();
- //Not able to break out of here without using a flag
- buttonClicked = true;
- }
- }
-
- if (!buttonClicked) {
- for (int i = 0; i < nodeCount; i++) {
- /**
- * ...or select / drag a node...
- */
- if (nodes[i].hover()) {
- i_selectedNode = i;
- savedTitle = nodes[i].title;
- nodes[i].drag = true;
- nodes[i].dragMouseStartPoint.x = mouseX;
- nodes[i].dragMouseStartPoint.y = mouseY;
- break;
- }
- /**
- * ...or pull a new link out of an inlet or outlet.
- */
- else if (nodes[i].hoverInlet()) {
- dragLink = true;
- dragOriginLet = -1;
- dragOriginId = i;
- } else if (nodes[i].hoverOutlet()) {
- dragLink = true;
- dragOriginLet = 1;
- dragOriginId = i;
- }
-
- //deselecting the shit out of this for reasons I don't remember, no care to improve right now
- deselect();
- }
- }
- }
- }
-
- /**
- * Create links
- */
- void mouseReleased() {
- for (int i = 0; i < nodeCount; i++) {
- nodes[i].drag = false;
- if (dragLink && dragOriginId != i) {
- if (nodes[i].hoverInlet() && dragOriginLet == 1) {
-
- Link(dragOriginId, i);
- }
- if (nodes[i].hoverOutlet() && dragOriginLet == -1) {
-
- Link(i, dragOriginId);
- }
- }
- }
-
- /**
- * Reset drag&drop states
- */
- dragLink = false;
- dragOriginLet = 0;
- dragOriginId = -1;
- }
-
-
- /**
- * Scaling is tied to textSize. Having the UI on a seperate PGraphics would be better, but it's good enough for now
- */
- int zoomDelta = 3;
- void mouseWheel(MouseEvent event) {
- float zoom = event.getAmount();
- if (zoom < 0) {
- textSize += zoomDelta;
- } else if (zoom > 0) {
- if (textSize - zoomDelta > 0) {
- textSize -= zoomDelta;
- }
- }
- padding = textSize/3*2;
- for (int i = 0; i < nodeCount; i++) {
- nodes[i].refreshSize();
- nodes[i].setVectors();
- }
- }
|