-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLight_Class.pde
150 lines (129 loc) · 3.81 KB
/
Light_Class.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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
Button butts[];
CColor[] color1;
class Light {
int x, y, w, h;
int buttI;
String name;
color col;
Light(int xIn, int yIn, int wIn, int hIn, String nameIn, color inCol, int inButtI) {
println ("---> new Light(nameIn: "+nameIn);
x = xIn;
y = yIn;
w = wIn;
h = hIn;
name = nameIn;
col = inCol;
buttI = inButtI;
}
CColor MakeCColor() {
CColor col = new CColor();
//col.setActive(color(0, 0, 100));
//col.setForeground(color(cPick));
//col.setBackground(color(0, 30));
col.setCaptionLabel(color(100));
return col;
}
void Program(Boolean state, int buttI) { //clicked while in setcolor mode
println("<##--Program(state, buttI "+state+" "+buttI);
if (state) { // ready to program
butts[buttI].setLabel("assign color");
println();
butts[buttI].setOff(); // during setcolor programing, there is no need to toggle the button on or off/ stay off.
} else {
butts[buttI].setLabel(lights[buttI].name);
butts[buttI].setColorForeground(butts[buttI].getColor().getActive());
}
}
void MakeButtons() {
//println("*******************MAKE BUTTONS ---"+buttI);
String hColor = "#"+(hex(color(cPick)).substring(2));
//println("hColor = "+hColor);
CColor col = new CColor();
col.setActive(color(cPick));
col.setForeground(color(cPick));
col.setBackground(color(offBlack));
col.setCaptionLabel(color(100));
if (!initTF)
{
//cp5.getController(butts[buttI].getName()).remove();
}
butts[buttI] = cp5.addButton(name).setPosition(x+buttCush, y+buttCush)
.setBroadcast(false)
.setSize(w-buttCush*3/2, h-buttCush*3/2)
.setColor(col)
.setSwitch(true)
.setStringValue(hColor)
.setFont(createFont("calibri light bold", 13))
.setOff()
.setBroadcast(true);
;
butts[buttI].addCallback(new CallbackListener() {
public void controlEvent(CallbackEvent theEvent) {
switch(theEvent.getAction()) {
case(ControlP5.ACTION_RELEASE):
println("button listener captured ACTION_RELEASE");
SetLight(buttI);//this, name, buttI);
break;
}
}
}
);
//butts[buttI].addCallback(new CallbackListener() {
// public void controlEvent(CallbackEvent theEvent) {
// switch(theEvent.getAction()) {
// case(ControlP5.ACTION_ENTER):
// println("button listener captured ACTION_ENTER");
// //SetLight(buttI);//this, name, buttI);
// break;
// }
// }
//}
//);
}
void Display() { // draw edges around buttons. do this every frame with call from Draw()
color sCol = butts[buttI].getColor().getActive();
//fill(0, 0, 0, 50);
if (SETBUTTS) {
}
strokeWeight(10);
stroke (sCol);
noFill();
rect(x+5, y+5, w-10, h-10);
stroke (color (100, 70));
strokeWeight(2);
line(x-1, y+h+1, x+w+1, y+h+1);
line(x+w+1, y+h+1, x+w+1, y-1);
stroke (0, 0, 0, 70);
line(x-1, y+h+1, x-1, y-1);
line(x-1, y-1, x+w+1, y-1);
}
}
String LightMsg(int bi) {
Boolean power = butts[bi].getBooleanValue();
String lColor = butts[bi].getStringValue();
String smsg;
if (power) {
smsg = "<+"+bi+"*"+lColor+">";
} else {
smsg = "<-"+bi+">";
}
return smsg;
}
void SetLight(int bi) { //CallbackListener bang, String bName, int bi) {
println ("<--SetLight(bi)");//listener, bname, bi)");
String hColor = "#"+(hex(color(cPick)).substring(2));
println(hColor);
//println(power); //toggle on or off?
String smsg = LightMsg(bi);
//println(smsg);
if (SETBUTTS) {
butts[bi].setColorActive(cPick);
//butts[bi].setColorForeground(cPick);
butts[bi].setStringValue(hColor);
butts[bi].setOff();
} else {
Router("out", smsg);
}
}
void ProgramLights() {
}