-
Notifications
You must be signed in to change notification settings - Fork 0
/
TriangleButton.pde
73 lines (61 loc) · 1.95 KB
/
TriangleButton.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
/**
*Petri Dish Simulation - TriangleButton Object
* Author: Tanmay Patel
* Description: Creates each system of up/down buttons, with text, and detects clicks
*/
class TriangleButton {
// Properties same as above object
float m_fXPos; // Right-most point on button system
float m_fYPos; // Lower-most point on button system
float m_fGap; // Vertical gap between upper and lower buttons
float m_fHgt;
float m_fWdt;
color m_cColour;
String m_sButtonName;
// Constructor: Sets up button with bottom-right x and y coordinates
TriangleButton(float x, float y, float w, float h, float gap, color c, String n) {
m_fXPos = x;
m_fYPos = y;
m_fGap = gap;
m_fWdt = w;
m_fHgt = h;
m_cColour = c;
m_sButtonName = n;
}
// Methods: Following 4 methods return the max and min x/y values necessary for a button click on lower button
float getLowerMinX() {
return m_fXPos;
}
float getLowerMinY() {
return m_fYPos - m_fHgt;
}
float getLowerMaxX() {
return m_fXPos + m_fWdt;
}
float getLowerMaxY() {
return m_fYPos;
}
// Methods: Following 4 methods return the max and min x/y values necessary for a button click on upper button
float getUpperMinX() {
return m_fXPos;
}
float getUpperMinY() {
return m_fYPos - 2*m_fHgt - m_fGap;
}
float getUpperMaxX() {
return m_fXPos + m_fWdt;
}
float getUpperMaxY() {
return m_fYPos - m_fHgt - m_fGap;
}
// Method: Renders upper and lower buttons with text in between
void renderButtons() {
noStroke();
fill(m_cColour);
triangle(m_fXPos, m_fYPos - m_fHgt - m_fGap, m_fXPos + m_fWdt, m_fYPos - m_fHgt - m_fGap, m_fXPos + m_fWdt/2, m_fYPos - 2*m_fHgt - m_fGap);
triangle(m_fXPos, m_fYPos - m_fHgt, m_fXPos + m_fWdt, m_fYPos - m_fHgt, m_fXPos + m_fWdt/2, m_fYPos);
fill(255);
textAlign(CENTER, CENTER);
text(m_sButtonName, m_fXPos + m_fWdt/2, m_fYPos - m_fHgt - m_fGap/2);
}
}