-
Notifications
You must be signed in to change notification settings - Fork 4
/
gui_subclasses.pde
215 lines (181 loc) · 5.73 KB
/
gui_subclasses.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
/**
* Petter - vector-graphic-based pattern generator.
* http://www.lafkon.net/petter/
* Copyright (C) 2015 LAFKON/Benjamin Stephan
*
* This program 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 2 of the License, or (at your option) any later
* version.
*
* This program 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.
*/
// ---------------------------------------------------------------------------
// DROPTARGETSVG - ADD/REPLACE/NFO
// ---------------------------------------------------------------------------
static int ADDSVG = 0;
static int REPLACESVG = 1;
static int NFOSVG = 2;
class DropTargetSVG extends DropListener {
PApplet app;
ControlP5 cp5;
boolean over = false;
int mode = -1;
int margin = 20;
int cw, ch;
int x, y, w, h;
int col;
int colTile = color(16, 181, 198, 150);
int colNfo = color(60, 105, 97, 180);
Textlabel label;
DropTargetSVG(PApplet app, ControlP5 cp5, int mode) {
this.app = app;
this.cp5 = cp5;
this.mode = mode;
setTargetRect(viewwidth, viewheight, mode);
}
void draw(PGraphics g) {
if (over) {
g.fill(col);
g.rectMode(CORNER);
g.rect(x, y, w, h);
label.draw(g);
}
}
void updateTargetRect(int newwidth, int newheight) {
setTargetRect(newwidth, newheight, mode);
}
private void setTargetRect(int ww, int hh, int mode) {
cw = ww;
ch = hh;
if (mode == ADDSVG) {
x = margin;
y = margin;
w = cw-(2*margin);
h = ((ch-(margin*2))/7)*3;
label = new Textlabel(cp5, "ADD", cw/2-5, h/2, 400, 200);
col = colTile;
} else if (mode == REPLACESVG) {
x = margin;
w = cw-(2*margin);
h = ((ch-(margin*2))/7)*3;
y = h+margin;
label = new Textlabel(cp5, "REPLACEALL", cw/2-20, (h/2)+h, 400, 200);
col = colTile;
} else if (mode == NFOSVG) {
x = margin;
h = (ch-(margin*2))/7;
y = ch-h-margin;
w = cw-(2*margin);
label = new Textlabel(cp5, "NFO", cw/2-20, (h/2)+y-10, 400, 200);
col = colNfo;
}
setTargetRect(x, y, w, h);
}
void dropEnter() {
over = true;
}
void dropLeave() {
over = false;
}
void dropEvent(DropEvent theDropEvent) {
ArrayList<PShape> tmpsvg = new ArrayList<PShape>();
ArrayList<String> tmppath = new ArrayList<String>();
String path = theDropEvent.toString();
if (path.toLowerCase().endsWith(".svg")) {
PShape sh = new TileSVG(path);
if (mode == ADDSVG || mode == REPLACESVG) {
tmpsvg.add(sh);
tmppath.add(path);
}
if (mode == ADDSVG) {
svg.addAll(tmpsvg);
svgpath.addAll(tmppath);
print("ADDSVG: ");
} else if (mode == REPLACESVG) {
print("RPLSVG: ");
if (over) {
svg = tmpsvg;
svgpath = tmppath;
} else {
svg.addAll(tmpsvg);
svgpath.addAll(tmppath);
}
} else if (mode == NFOSVG) {
print("NFOSVG: ");
((TileSVG)sh).useGlobalStyle(false);
nfo = sh;
showNfoToggle.setState(true);
}
if (tileEditor != null) {
int tmpmode = mode;
if (mode == REPLACESVG && !over) {
tmpmode = ADDSVG;
}
tileEditor.updateTileList(svg, tmpmode);
tileEditor.lastTile();
}
println(path);
}
}
}//class DropTargetSVG
// ---------------------------------------------------------------------------
// ColorBangView
// ---------------------------------------------------------------------------
class ColorBangView implements ControllerView<Bang> {
public void display( PGraphics g , Bang c ) {
//draw checkerboard
g.fill(64);
g.rect(0, 0, 10, 10);
g.rect(10, 10, 10, 10);
g.fill(192);
g.rect(10, 0, 10, 10);
g.rect(0, 10, 10, 10);
if (c.isActive()) {
g.fill(c.getColor().getActive());
} else {
g.fill(c.getColor().getForeground());
}
g.rect(0, 0, c.getWidth(), c.getHeight());
if (c.isLabelVisible()) {
int x = c.getWidth()/2 - c.getCaptionLabel().getWidth()/2;
int y = c.getHeight()/2 - c.getCaptionLabel().getHeight()/2 - 1;
translate(x, y);
if(brightness(c.getColor().getForeground()) < 175) { c.getCaptionLabel().setColor(255); }
else { c.getCaptionLabel().setColor(0); }
c.getCaptionLabel().draw(g);
}
}
}
// ---------------------------------------------------------------------------
// ScrollableListPlus - temporarily till controlP5-lib makes itemHover in ScrollableList visible
// ---------------------------------------------------------------------------
class ScrollableListPlus extends ScrollableList {
CColor activeColor = new CColor().setBackground(c1);
CColor passiveColor = new CColor().setBackground(bg);
Map< String, Object > newselected = null;
Map< String, Object > oldselected = null;
public ScrollableListPlus( ControlP5 theControlP5, String theName ) {
super(theControlP5, theName);
registerProperty( "value" );
}
public ScrollableListPlus setValue( float theValue ) {
super.setValue(theValue);
return this;
}
public void updateHighlight(Map< String, Object > item) {
newselected = item;
if (!newselected.equals(oldselected)) {
newselected.put("color", activeColor);
if (oldselected != null) {
oldselected.put("color", passiveColor);
}
}
oldselected = newselected;
}
public int getItemHover() {
return itemHover;
}
}//class ScrollableListPlus