forked from ranenbg/Arduino-FFB-gui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
xycals.pde
113 lines (110 loc) · 2.67 KB
/
xycals.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
class xyCal {
float x, y, sx, sy;
float[] limits = new float [4];
boolean active, changing, locked;
int orn;
String t;
xyCal(float posx, float posy, float xsize, float ysize, int orientation, String text) {
x = posx;
y = posy;
sx = xsize;
sy = ysize;
t = text;
active = true;
changing = false;
locked = false;
orn = orientation; // 0-top, 1-right, 2-bottom, 3-left
}
void updateColors(int i) {
if (active) {
if (mouseX >= x-sx/2 && mouseX <= x+sx/2 && mouseY >= y-sy/2 && mouseY <= y+sy/2) {
controlb[i] = true;
} else {
controlb[i] = false;
}
if (controlb[i] && mousePressed) { // green with black text (activated)
col[0] = 96;
col[1] = 200;
col[2] = 150;
thue = 0;
changing = true;
} else if (controlb[i] && !mousePressed) { // yellow with white text (howered)
col[0] = 40;
col[1] = 200;
col[2] = 180;
thue = 255;
changing = false;
} else if (!controlb[i]) { // red with white text (deactivated)
col[0] = 0;
col[1] = 200;
col[2] = 150;
thue = 255;
changing = false;
}
} else {
col[0] = 0;
col[1] = 0;
col[2] = 100;
thue = 255;
}
}
void showPointer(float dx, float dy) {
float yoffs = sy+2; // pointer y offset
pushMatrix();
fill(col[0], col[1], col[2]);
strokeWeight(1);
stroke(255);
if (orn == 0) {
translate(x, y);
} else if (orn == 1) {
translate(x, y);
} else if (orn == 2) {
translate(x, y);
} else if (orn == 3) {
translate(x, y);
}
rotate(float(orn)/2.0*PI);
beginShape();
vertex(-sx/2, -sy/2);
vertex(sx/2, -sy/2);
vertex(sx/2, sy/2);
vertex(0, sy);
vertex(-sx/2, sy/2);
vertex(-sx/2, -sy/2);
endShape();
textSize(font_size);
if (sx < font_size) textSize(sx);
fill(thue);
stroke(150);
if (orn == 0) {
text(t, -sx/2, sy/2);
pushMatrix();
translate(0, yoffs);
line(0, 1, 0, dy-1);
popMatrix();
} else if (orn == 1) {
pushMatrix();
rotate(-float(orn)/2.0*PI);
translate(-yoffs, 0);
text(t, sx, sy/2);
line(-dx+1, 0, -1, 0);
popMatrix();
} else if (orn == 2) {
pushMatrix();
translate(0, yoffs);
line(0, 1, 0, dy-1);
rotate(-float(orn)/2.0*PI);
text(t, -sx/2, 1.5*sy);
popMatrix();
} else if (orn == 3) {
pushMatrix();
rotate(-float(orn)/2.0*PI);
text(t, -sx/2, 0.35*sy);
translate(dx+yoffs, 0);
line(-dx+1, 0, -1, 0);
popMatrix();
}
popMatrix();
textSize(font_size);
}
}