-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.java
55 lines (43 loc) · 1.2 KB
/
Button.java
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
package model.menu;
import model.Position;
import model.region.RectangleRegion;
public class Button {
private boolean selected;
private final Position topLeft;
private final String title;
private final int width;
public static final int BUTTON_HEIGHT = 3;
public Button(Position position, String title) {
this(position, title, title.length() + 2);
}
public Button(Position position, String title, int width) {
this.topLeft = position;
this.title = title;
this.width = Math.max(width, title.length() + 2);
this.selected = false;
}
public boolean contains(Position position) {
return new RectangleRegion(this.topLeft, this.width, BUTTON_HEIGHT).contains(position);
}
public void select() {
this.selected = true;
}
public void unselect() {
this.selected = false;
}
public boolean isSelected() {
return this.selected;
}
public Position getTopLeft() {
return this.topLeft;
}
public String getTitle() {
return this.title;
}
public int getWidth() {
return this.width;
}
public int getHeight() {
return BUTTON_HEIGHT;
}
}