-
Notifications
You must be signed in to change notification settings - Fork 2
/
WindowHeader.pde
111 lines (90 loc) · 2.54 KB
/
WindowHeader.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
public class WindowHeader extends Component {
private int headerWidth;
private int headerHeight;
private int buttonsY;
private int buttonsWidth;
private int buttonsHeight;
private int homeBtnX;
private int backBtnX;
private boolean overHomeBtn;
private boolean overBackBtn;
private String title;
public WindowHeader(String title) {
this.headerWidth = WINDOW_WIDTH;
this.headerHeight = 50;
this.buttonsWidth = 75;
this.buttonsHeight = 40;
this.homeBtnX = WINDOW_WIDTH - 180;
this.backBtnX = homeBtnX + buttonsWidth + 10;
this.buttonsY = 5;
this.overHomeBtn = false;
this.overBackBtn = false;
this.title = title;
}
public void setup() {
}
public void draw() {
noStroke();
this.mouseOverButtons();
fill(COLOR_NBA_RED);
rect(0, 0, WINDOW_WIDTH, headerHeight);
fill(COLOR_NBA_BLUE);
rect(0, 0, 75, headerHeight);
image(NBA_HEADER, 30, 0);
fill(255);
textAlign(LEFT);
textFont(FONT_BOLD_16);
text(this.title, 190, buttonsY+5+buttonsHeight/2);
pushMatrix();
this.drawButtons();
popMatrix();
}
public int getHeight() {
return this.headerHeight;
}
public int getWidth() {
return this.headerWidth;
}
public void mouseEvent(int eventType) {
if(eventType == MOUSE_CLICKED) {
if(overHomeBtn)
HOME_WINDOW();
else if(overBackBtn)
SWITCH_WINDOW(null);
}
}
private void mouseOverButtons() {
if (mouseX > homeBtnX && mouseX < homeBtnX+buttonsWidth &&
mouseY > buttonsY && mouseY < buttonsY+buttonsHeight)
overHomeBtn = true;
else
overHomeBtn = false;
if (mouseX > backBtnX && mouseX < backBtnX+buttonsWidth &&
mouseY > buttonsY && mouseY < buttonsY+buttonsHeight)
overBackBtn = true;
else
overBackBtn = false;
}
private void drawButtons() {
// Home button
if(!overHomeBtn)
fill(COLOR_NBA_RED_HIGHLIGHT);
else
fill(COLOR_NBA_RED_OVER);
rect(homeBtnX, buttonsY, buttonsWidth, buttonsHeight);
fill(255);
textFont(FONT_BOLD_14);
textAlign(CENTER);
text("Home", homeBtnX+buttonsWidth/2, buttonsY+5+buttonsHeight/2);
// Back button
if(!overBackBtn)
fill(COLOR_NBA_RED_HIGHLIGHT);
else
fill(COLOR_NBA_RED_OVER);
rect(backBtnX, buttonsY, buttonsWidth, buttonsHeight);
fill(255);
textFont(FONT_BOLD_14);
textAlign(CENTER);
text("Go Back", backBtnX+buttonsWidth/2, buttonsY+5+buttonsHeight/2);
}
}