Created
December 18, 2009 21:50
-
-
Save ghostandthemachine/259783 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BaseObject{ | |
int cx; | |
int cy; | |
int px; | |
int py; | |
int x; | |
int y; | |
int xOffset = 0; | |
int yOffset = 0; | |
int w; | |
int bw; | |
int h; | |
int value; | |
int outputs; | |
int inputs; | |
int outLockedID; | |
int inOrOut; | |
int currentConnectionIDout = -1; | |
int currentConnectionIDin = -1; | |
//for interaction | |
boolean press = false; | |
boolean scaleable = true; | |
boolean rollover; | |
boolean locked; | |
boolean over; | |
boolean highLight = false; | |
boolean selected = false; | |
boolean connecting = false; | |
boolean scaleLocked = false; | |
boolean wideSelectionOnly = true; | |
boolean currentObject = false; | |
//for connections | |
boolean[] outRollover; | |
boolean[] outLocked; | |
boolean[] outOver; | |
boolean[] inRollover; | |
boolean[] inLocked; | |
boolean[] inOver; | |
int[][] outLocation; | |
int[][] inLocation; | |
String title; | |
color fillColor = color(0xFFFFFF); | |
color borderColor = color(0xA5A5A5); | |
color highlightColor = color(205,255,240); | |
color cfillColor = color(0xFFFFFF); | |
color cborderColor = color(0xA5A5A5); | |
color cHighlightColor = color(0xB9FFEB); | |
Connection[] connections; | |
BaseObject(String tTitle, int ins, int outs, int tx, int ty){ | |
inputs = ins; | |
outputs = outs; | |
title = tTitle; | |
rollover = false; | |
locked = false; | |
over = false; | |
x = tx; | |
y = ty; | |
h = 23; | |
bw = title.length() * 6; | |
w = constrain(title.length() * 8 + 8, bw, 1000); | |
inLocation = new int [inputs][2]; | |
outLocation = new int [outputs][2]; | |
outRollover = new boolean[outputs]; | |
outLocked = new boolean[outputs]; | |
outOver = new boolean[outputs]; | |
inRollover = new boolean[inputs]; | |
inLocked = new boolean[inputs]; | |
inOver = new boolean[inputs]; | |
connections = new Connection[outputs]; | |
for(int i = 0; i < inputs; i++){ | |
inRollover[i] = false; | |
inLocked[i] = false; | |
inOver[i] = false; | |
inLocation[i][0] = x + (i * (w / inputs)) + 5; | |
inLocation[i][1] = y; | |
} | |
for(int i = 0; i < outputs; i++){ | |
outRollover[i] = false; | |
outLocked[i] = false; | |
outOver[i] = false; | |
outLocation[i][0] = x + (i * (w / outputs)) + 5; | |
outLocation[i][1] = y + h; | |
connections[i] = new Connection(); | |
} | |
} | |
void display(){ | |
for(int i = 0; i < outputs; i++){ | |
stroke(0); | |
connections[i].display(); | |
} | |
pushStyle(); | |
strokeWeight(3); | |
stroke(175); | |
if(selected == true){ | |
fill(cfillColor); | |
} | |
else{ | |
fill(fillColor); | |
} | |
rect(x , y , w, h); | |
popStyle(); | |
update(); | |
fill(0); | |
textFont(font); | |
text(title,x + 6, y + 16); | |
} | |
void move(int mx, int my){ | |
if(over(mx,my)){ | |
currentObject = true; | |
} | |
else if(over(mx,my) != true){ | |
currentObject = false; | |
} | |
if(locked == true && currentConnectionIDout < 0 && currentConnectionIDin < 0){ | |
x = mouseX - px; | |
y = mouseY - py; | |
} | |
if(scaleable){ | |
if(scaleLocked == true){ | |
if(wideSelectionOnly){ | |
w = constrain(mx - x + xOffset, bw + 25, 1000); | |
} | |
else if(wideSelectionOnly != true){ | |
h = constrain(my - y - yOffset, 23, 1000); | |
w = constrain(mx - x + xOffset, bw + 25, 1000); | |
} | |
} | |
} | |
for(int i = 0; i < inputs; i++){ | |
inLocation[i][0] = x + xOffset + (i * (w / inputs)) + 5; | |
inLocation[i][1] = y - yOffset; | |
} | |
for(int i = 0; i < outputs; i++){ | |
outLocation[i][0] = x - xOffset + (i * (w / outputs)) + 5; | |
outLocation[i][1] = y + h - yOffset; | |
if(outLocked[i] == true){ | |
connections[i].update(mx,my); | |
} | |
} | |
cx = mouseX; | |
cy = mouseY; | |
} | |
void update(){ | |
if(editMode == true) { | |
for(int i = 0; i < inputs; i++){ | |
pushStyle(); | |
strokeWeight(3); | |
stroke(0); | |
line(inLocation[i][0], y, inLocation[i][0] + 6, y); | |
popStyle(); | |
if(inRollover[i] == true || inLocked[i] == true ){ | |
pushStyle(); | |
stroke(255,0,0,100); | |
connectionHighLight(inLocation[i][0],inLocation[i][1],inputs); | |
popStyle(); | |
} | |
} | |
for(int i = 0; i < outputs; i++){ | |
pushStyle(); | |
stroke(0); | |
strokeWeight(3); | |
line(outLocation[i][0], y + h, outLocation[i][0] + 6, y + h); | |
popStyle(); | |
if(outLocked[i] == true || outRollover[i] == true){ | |
pushStyle(); | |
stroke(0,0,255,100); | |
connectionHighLight(outLocation[i][0],outLocation[i][1], outputs); | |
connectionLine(mouseX, mouseY); | |
popStyle(); | |
} | |
else if(outRollover[i] == true && outLocked[i] == false) { | |
} | |
} | |
} | |
} | |
void setOver(int mx, int my){ | |
inRollover(mx, my); | |
outRollover(mx, my); | |
} | |
int getCX() { | |
return cx; | |
} | |
int getCY() { | |
return cy; | |
} | |
void press(int mx, int my) { | |
if(editMode == true){ //edit mode use | |
for(int j = 0; j < outputs; j++){ | |
if (outRollover[j] == true) { | |
outLocked[j] = true; //turn on lock for current output | |
outLockedID = j; | |
connecting = true; | |
connections[j].add(outLocation[j][0],outLocation[j][1]); | |
} | |
else { | |
outLocked[j] = false; | |
} | |
} | |
{ //for actual object use | |
if (over(mx,my)) { | |
locked = true; | |
selected = true; | |
cfillColor = highlightColor; | |
px = mx - x; | |
py = my - y; | |
} | |
else if(scaleOver(mx,my)){ | |
scaleLocked = true; | |
} | |
else { | |
locked = false; | |
cfillColor = fillColor; | |
} | |
} | |
} | |
if(over(mx,my)){ | |
press = true; | |
} | |
} | |
void release() { | |
if(editMode == true){ | |
if(connecting){ | |
BaseObject temp = (BaseObject) objects.get(currentInputID); | |
connections[outLockedID].release(temp.inLocation[currentInputID][0],temp.inLocation[currentInputID][1]); | |
} | |
else if(connecting != true){ | |
// connections[outLockedID].drop(); | |
} | |
for(int i = 0; i < outputs; i++){ | |
outLocked[i] = false; | |
if(outLockedID > 0){ | |
connections[i].release(mouseX,mouseY); | |
} | |
} | |
for(int i = 0; i < inputs; i++){ | |
inLocked[i] = false; | |
inRollover[i] = false; | |
} | |
outLockedID = -1; | |
locked = false; | |
currentConnectionIDout = -1; | |
currentConnectionIDin = -1; | |
} | |
connecting = false; | |
scaleLocked = false; | |
press = false; | |
} | |
void outRollover(int mx, int my) { | |
for(int i = 0; i < outputs; i++){ | |
if (dist(outLocation[i][0] + 3 + xOffset, y + h - yOffset, mx, my) < 4) { | |
outRollover[i] = true; | |
currentConnectionIDout = i; | |
inOrOut = 0; | |
} | |
else { | |
outRollover[i] = false; | |
currentConnectionIDout = -1; | |
} | |
} | |
} | |
void inRollover(int mx, int my) { | |
for(int i = 0; i < inputs; i++){ | |
if (dist(inLocation[i][0] + 3 + xOffset, y - yOffset, mx, my) < 4) { | |
inRollover[i] = true; | |
currentConnectionIDin = i; | |
inOrOut = 1; | |
pushStyle(); | |
stroke(255,0,0,100); | |
connectionHighLight(inLocation[i][0],inLocation[i][1],inputs); | |
popStyle(); | |
input = true; | |
currentInputID = i; | |
} | |
else { | |
inRollover[i] = false; | |
currentConnectionIDin = -1; | |
input = false; | |
} | |
} | |
} | |
boolean scaleOver(int mx, int my) { //main object use mouse over | |
if ((mx > x + xOffset + w - 10) && (mx < x + xOffset + w) && (my > y - yOffset) && (my < y + h - yOffset)) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
boolean over(int mx, int my) { //main object use mouse over | |
if ((mx > x + xOffset) && (mx < x + xOffset + w - 10) && (my > y - yOffset) && (my < y + h - yOffset)) { | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
boolean isOver(){ | |
if(rollover == true){ | |
return true; | |
} | |
else { | |
return false; | |
} | |
} | |
void connectionHighLight(int mx, int my, int ti){ | |
if(editMode){ | |
pushStyle(); | |
ellipseMode(CENTER); | |
noFill(); | |
strokeWeight(2.5); | |
ellipse(mx + 3, my, 14, 14); | |
strokeWeight(1); | |
popStyle(); | |
} | |
} | |
void connectionLine(int mx, int my){ | |
pushStyle(); | |
stroke(0); | |
strokeWeight(1); | |
for(int i = 0; i < outputs; i++){ | |
if(outLocked[i] == true){ | |
line(outLocation[i][0] + 3, y + h, mx, my); | |
} | |
} | |
popStyle(); | |
} | |
void drag(int mx, int my){ | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment