forked from euphy/polargraphcontroller
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Panel.pde
236 lines (201 loc) · 6.15 KB
/
Panel.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/**
Polargraph controller
Copyright Sandy Noble 2012.
This file is part of Polargraph Controller.
Polargraph Controller is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Polargraph Controller is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Polargraph Controller. If not, see <http://www.gnu.org/licenses/>.
Requires the excellent ControlP5 GUI library available from http://www.sojamo.de/libraries/controlP5/.
Requires the excellent Geomerative library available from http://www.ricardmarxer.com/geomerative/.
This is an application for controlling a polargraph machine, communicating using ASCII command language over a serial link.
sandy.noble@gmail.com
http://www.polargraph.co.uk/
https://github.com/euphy/polargraphcontroller
*/
class Panel
{
private Rectangle outline = null;
private String name = null;
private List<Controller> controls = null;
private Map<String, PVector> controlPositions = null;
private Map<String, PVector> controlSizes = null;
private boolean resizable = true;
private float minimumHeight = DEFAULT_CONTROL_SIZE.y+4;
private color outlineColour = color(255);
public final color CONTROL_COL_BG_DEFAULT = color(0,54,82);
public final color CONTROL_COL_BG_DISABLED = color(20,44,62);
public final color CONTROL_COL_LABEL_DEFAULT = color(255);
public final color CONTROL_COL_LABEL_DISABLED = color(200);
public Panel(String name, Rectangle outline)
{
this.name = name;
this.outline = outline;
}
public Rectangle getOutline()
{
return this.outline;
}
public void setOutline(Rectangle r)
{
this.outline = r;
}
public String getName()
{
return this.name;
}
public void setName(String name)
{
this.name = name;
}
public List<Controller> getControls()
{
if (this.controls == null)
this.controls = new ArrayList<Controller>(0);
return this.controls;
}
public void setControls(List<Controller> c)
{
this.controls = c;
}
public Map<String, PVector> getControlPositions()
{
return this.controlPositions;
}
public void setControlPositions(Map<String, PVector> cp)
{
this.controlPositions = cp;
}
public Map<String, PVector> getControlSizes()
{
return this.controlSizes;
}
public void setControlSizes(Map<String, PVector> cs)
{
this.controlSizes = cs;
}
void setOutlineColour(color c)
{
this.outlineColour = c;
}
void setResizable(boolean r)
{
this.resizable = r;
}
boolean isResizable()
{
return this.resizable;
}
void setMinimumHeight(float h)
{
this.minimumHeight = h;
}
float getMinimumHeight()
{
return this.minimumHeight;
}
public void draw()
{
if (debugPanels) {
stroke(outlineColour);
strokeWeight(2);
rect(getOutline().getLeft(), getOutline().getTop(), getOutline().getWidth(), getOutline().getHeight());
}
drawControls();
}
public void drawControls()
{
for (Controller c : this.getControls())
{
PVector pos = getControlPositions().get(c.getName());
float x = pos.x+getOutline().getLeft();
float y = pos.y+getOutline().getTop();
c.setPosition(x, y);
PVector cSize = getControlSizes().get(c.getName());
c.setSize((int)cSize.x, (int)cSize.y);
boolean locked = false;
// theres a few cases here where the controls are locked (disabled)
// any drawing / extracting controls are disabled if there is no selec
// box specified.
if (getControlsToLockIfBoxNotSpecified().contains(c.getName()) && !isBoxSpecified())
{
locked = true;
}
// if there is no vector shape loaded then lock the "draw vector"
// control.
if (c.getName().equals(MODE_RENDER_VECTORS) && getVectorShape() == null)
{
locked = true;
}
// if there's no image loaded, then hide resizing/moving
if (getControlsToLockIfImageNotLoaded().contains(c.getName()) && getDisplayMachine().getImage() == null)
{
locked = true;
}
// if there's no vector loaded, then hide vector controls
if (getControlsToLockIfVectorNotLoaded().contains(c.getName()) && vectorFilename == null)
{
locked = true;
}
if (c.getName().equals(MODE_LOAD_VECTOR_FILE))
{
if (getVectorShape() != null)
c.setLabel("Clear vector");
else
c.setLabel("Load vector");
}
else if (c.getName().equals(MODE_LOAD_IMAGE))
{
if (getDisplayMachine().getImage() != null)
c.setLabel("Clear image");
else
c.setLabel("Load image file");
}
int col = c.getColor().getBackground();
setLock(c, locked);
}
}
void setLock(Controller c, boolean locked)
{
c.setLock(locked);
if (locked)
{
c.setColorBackground(CONTROL_COL_BG_DISABLED);
c.setColorLabel(CONTROL_COL_LABEL_DISABLED);
}
else
{
c.setColorBackground(CONTROL_COL_BG_DEFAULT);
c.setColorLabel(CONTROL_COL_LABEL_DEFAULT);
}
}
void setSizeByHeight(float h)
{
// println("Setting size for " + this.getName());
if (this.isResizable())
{
if (h <= getMinimumHeight())
this.getOutline().setHeight(getMinimumHeight());
else
this.getOutline().setHeight(h);
setControlPositions(buildControlPositionsForPanel(this));
float left = 0.0;
for (String key : getControlPositions().keySet())
{
PVector pos = getControlPositions().get(key);
if (pos.x > left)
{
left = pos.x;
}
}
float right = left + DEFAULT_CONTROL_SIZE.x;
this.getOutline().setWidth(right);
}
}
}