-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathControlbuttons.pde
executable file
·77 lines (64 loc) · 2.05 KB
/
Controlbuttons.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
class Controlbutton {
FB_Button[] buttons;
int
B_Radius, // button radius
current = 0, // current pressed button
currentH = -1, // current hovered button
bottomBorder; // Define the button border
PVector button; // Center of first button
color
TOP_COLOR = 0xccffffff; //color for the background of the row
boolean buttonHovered = false;
//CONSTRUCTOR
Controlbutton (int buttonsNumber,int oX,int oY,int Radius,int maxValue,int[] vals,String[] texts) {
button = new PVector(oX,oY); // make button Vector
B_Radius = Radius; // get the radius
buttons = new FB_Button[buttonsNumber]; //
int sepV = 0;
for (int i=0;i<buttons.length;i++) {
float button_size = map(vals[i],0,maxValue,0,B_Radius); //size of button
int sepH = (B_Radius+10)*2; //Horozontal sepration between buttons
sepV = int(textAscent()+textDescent()+B_Radius+5); //separation between buttons and text
buttons[i] = new FB_Button(button.x,button.y+(i*sepH),button.y+sepV,button_size,texts[i]);
}
bottomBorder = oX+sepV+20;
}
//METHODS
void display(){
noStroke();
fill(TOP_COLOR);
for (int i=0;i<buttons.length;i++) {
if (current==i) {
buttons[i].display(true);
}else{
buttons[i].display(false);
}
}
}
void select_button(int button_number){
current = button_number;
}
void hover (int mX,int mY){
for (int i=0;i<buttons.length;i++){
if(buttons[i].hover(mX,mY)){
currentH=i;
buttonHovered = true;
break;
}
buttonHovered = false;
}
}
int getBorder(){
return bottomBorder;
}
boolean isHovered(){
return buttonHovered;
}
void hoverIs(boolean what){
buttonHovered=what;
}
int setCurrent(){
current = currentH;
return current;
}
}