-
Notifications
You must be signed in to change notification settings - Fork 0
/
Controls.pde
136 lines (119 loc) · 3.91 KB
/
Controls.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
import controlP5.*;
public static class Controls {
final static int colUp = 80;
final static int column = 530;
final static int row = 50;
final static int itmHeight = 22;
final static int itmWidth = 160;
public static void config(ControlP5 c, PFont f) {
//ControlFont.sharp();
ControlFont ff = new ControlFont(f, 12);
//ff.RENDER_2X = true;
c.setFont(ff);
// change the original colors
c.setColorForeground(0x0050E320);
c.setColorBackground(0xff224422);
c.setColorCaptionLabel(0xff00e300);
//c.setColor(new CColor());
c.setColorActive(0xff00e300);
}
public static RadioButton getRadioOptions(ControlP5 c, String name , String path, String ext, boolean withNew, String selected, int r) {
String [] items = getFileList(path, ext, withNew);
RadioButton ddl = c.addRadioButton (name)
.setPosition(column ,r*row)
//.addItems(items)
//.setSize(itmWidth, 200)
.setItemHeight(itmHeight-10)
.setNoneSelectedAllowed(false)
.toUpperCase(true)
//.setBarHeight(itmHeight)
//.setBarVisible(true)
//.setOpen(false)
;
for(int i = 0; i < items.length; i++) {
ddl.addItem(items[i], i);
}
try {
ddl.activate(selected);
} catch (Exception e) {
println("Cannot select default scene");
}
return ddl;
}
public static RadioButton getRadioFixedOptions(ControlP5 c, String name , String [] items, String selected, int col, int r, int offsetY) {
RadioButton ddl = c.addRadioButton (name)
.setPosition(col ,r*row+offsetY)
//.addItems(items)
.setSize(10,10)
.setItemHeight(itmHeight-10)
.setNoneSelectedAllowed(false)
.toUpperCase(true)
//.setBarHeight(itmHeight)
//.setBarVisible(true)
//.setOpen(false)
;
for(int i = 0; i < items.length; i++) {
ddl.addItem(items[i], i);
}
ddl.activate(selected);
return ddl;
}
public static Button getButton(ControlP5 c, String name, PImage def, PImage active, int col, int r, int offsetY) {
Button b = c.addButton(name)
.setPosition(col ,r*row+offsetY)
.setSize(25, 25)
.updateSize()
;
if (def != null){
b.setImage(def, Controller.DEFAULT);
b.setImage(active, Controller.ACTIVE);
}
return b;
}
public static Textfield getTextInput(ControlP5 c, String name, int r) {
Textfield t = c.addTextfield(name)
.setPosition(column, r*row)
.setSize(itmWidth, itmHeight)
;
return t;
}
public static Slider getSliderH(ControlP5 c, String name, float min, float max, int col, int r, int offsetY) {
Slider s = c.addSlider(name)
.setPosition(col, row*r+offsetY)
.setRange(min , max)
.setSize(itmWidth, itmHeight)
;
return s;
}
public static Toggle getSwitch(ControlP5 c, String name, int col, int r, int offsetY) {
Toggle ch = c.addToggle(name)
.setPosition(col, row*r+offsetY)
.setSize(15, 15)
.setValue(false)
//.isLabelVisible(false)
.setCaptionLabel("l")
;
return ch;
}
//----------------
//---------- utils
//----------------
public static String[] getFileList(String path, String ext, boolean withNew) {
java.io.File folder = new java.io.File(path);
String[] filenames = {};
if (withNew) {
filenames = append(filenames, "<NEW>");
}
try {
for (String file : folder.list()) {
// Check if string ends with extension
if (file.endsWith(ext)) {
filenames = append(filenames, file.replace(".tr", ""));
}
}
} catch (Exception e) {
println("Controls.getFileList : /traj folder doesn't exist or there are no files in it");
}
return filenames;
}
}