-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCustomGate.pde
118 lines (111 loc) · 5.12 KB
/
CustomGate.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
class CustomGate extends Gate{
ArrayList<Gate> localGates = new ArrayList<Gate>();
Boolean locked = false;
PVector blueprintSize;
Boolean minimized = false;
ArrayList<Shape> holderShapes = new ArrayList<Shape>();
String name = "enter name";
CustomGate(PVector _position, PVector size){
super("custom",_position);
this.shapes.add(new Shape(new PVector[]{new PVector(0,0),new PVector(size.x/globalScale,0),new PVector(size.x/globalScale,size.y/globalScale),new PVector(0,size.y/globalScale)}));
this.position = _position;
this.blueprintSize = size;
}
void show(){
stroke(255);
strokeWeight(1*globalScale);
fill(20,140,250,50);
beginShape();
for (PVector point : shapes.get(0).points) {
vertex(this.position.x*globalScale + point.x*globalScale, this.position.y*globalScale + point.y*globalScale);
}
endShape(CLOSE);
textSize(14*globalScale);
fill(255);
textAlign(LEFT);
text(this.name,this.position.x*globalScale,this.position.y*globalScale);
}
void setupGate(){
for(Gate g : localGates){
if(g.type == "INPUT"){
g.type = "INPUTbp";
g.shapes = new ArrayList<Shape>();
g.shapes.add(new Shape(new PVector[]{new PVector(0, 0), new PVector(0, 20),new PVector(20,20), new PVector(20, 0)}));
g.inputs.add(new PVector(0, 10));
g.position = new PVector(this.position.x,g.position.y);
g.connections_in = new Connection[1];
g.size = new PVector(20,20);
} else if(g.type == "OUTPUT"){
g.type = "OUTPUTbp";
g.position = new PVector(this.position.x + (blueprintSize.x)/globalScale - 20,g.position.y);
g.shapes = new ArrayList<Shape>();
g.shapes.add(new Shape(new PVector[]{new PVector(0, 0), new PVector(0, 20),new PVector(20,20), new PVector(20, 0)}));
g.outputs.add(new PVector(20, 10));
g.size = new PVector(20,20);
} else if(g.inputsNullCheck() && g.connections_out.size() != 0){
g.position = new PVector(this.position.x-g.inputs.get(0).x,g.position.y);
g.blueprint_input = true;
} else if(g.connections_out.size() == 0 && !g.inputsNullCheck()){
g.position = new PVector(this.position.x + (blueprintSize.x)/globalScale - g.outputs.get(0).x,g.position.y);
g.blueprint_output = true;
}
}
}
void minimize(){
this.minimized = !this.minimized;
for(Gate g : localGates){
g.hidden = this.minimized;
}
if(this.minimized){
this.holderShapes = this.shapes;
this.shapes = new ArrayList<Shape>();
this.shapes.add(new Shape(new PVector[]{new PVector(0, 0), new PVector(0, 50),new PVector(50,50), new PVector(50, 0)}));
for(Gate g : localGates){
if (g.type == "INPUTbp" || g.type == "OUTPUTbp" || g.blueprint_input || g.blueprint_output){
g.position.x = map(g.position.x,this.position.x,this.position.x + blueprintSize.x-g.size.x,this.position.x,this.position.x+(50-g.size.x));
g.position.y = map(g.position.y,this.position.y,this.position.y+this.blueprintSize.y-g.size.y,this.position.y,this.position.y+(50-g.size.y));
}
}
} else if(!this.minimized){
this.shapes = holderShapes;
for(Gate g : localGates){
if (g.type == "INPUTbp" || g.type == "OUTPUTbp" || g.blueprint_input || g.blueprint_output){
g.position.x = map(g.position.x,this.position.x,this.position.x+(50-g.size.x),this.position.x,this.position.x + blueprintSize.x-g.size.x);
g.position.y = map(g.position.y,this.position.y,this.position.y+(50-g.size.y),this.position.y,this.position.y+this.blueprintSize.y-g.size.y);
}
}
}
}
void delete(Boolean full){
if(full){
for(Gate g: localGates){
gates.remove(g);
}
}
for(Gate g : localGates){
if(g.type == "INPUTbp"){
g.type = "INPUT";
g.shapes = new ArrayList<Shape>();
g.shapes.add(new Shape(new PVector[]{new PVector(0, 0), new PVector(0, 20),new PVector(20,20), new PVector(20, 0)}));
g.inputs = new ArrayList<PVector>();
g.position = new PVector(this.position.x,g.position.y);
g.connections_in = new Connection[1];
} else if(g.type == "OUTPUTbp"){
g.type = "OUTPUT";
g.position = new PVector(this.position.x + (blueprintSize.x)/globalScale,g.position.y);
g.shapes = new ArrayList<Shape>();
g.shapes.add(new Shape(new PVector[]{new PVector(0, 10), new PVector(20, 0), new PVector(20, 20)}));
g.outputs = new ArrayList<PVector>();
}
g.blueprint_input = g.blueprint_output = false;
}
customGates.remove(this);
}
void checkGates(){
for(int i = localGates.size()-1; i >= 0; i --){
if(localGates.get(i).inputs.size() > 0 && !(localGates.get(i).position.x >= this.position.x-localGates.get(i).inputs.get(0).x && localGates.get(i).position.x <= this.position.x + blueprintSize.x && localGates.get(i).position.y >= this.position.y && localGates.get(i).position.y <= this.position.y + blueprintSize.y)){
localGates.remove(localGates.get(i));
}
}
}
}