-
Notifications
You must be signed in to change notification settings - Fork 0
/
CButton.pde
59 lines (52 loc) · 980 Bytes
/
CButton.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
public class CButton
{
private String text;
float x, y;
float w, h;
public CButton(String text,PVector pos, float w, float h)
{
this.text = text;
x = pos.x;
y = pos.y;
this.w = w;
this.h = h;
}
public void display()
{
pushMatrix();
rectMode(CENTER);
noStroke();
fill(255);
rect(x, y, w, h, 5);
fill(0);
textAlign(CENTER);
text(text, x, y+5);
popMatrix();
}
public void buttonWasPressed(float mX, float mY)
{
if (contains(mX, mY))
{
println(text+" button was pressed.");
drawNextCommit();
}
}
public boolean contains(float mX, float mY)
{
float left = x - w/2;
float right = x + w/2;
float top = y - h/2;
float bottom = y + h/2;
if ((mX > left) && (mX < right) && (mY > top) && (mY < bottom))
{
return true;
}
else
{
return false;
}
}
/*
** Getters and Setters for private variables.
*/
}