-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.pde
132 lines (116 loc) · 2.89 KB
/
Button.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
class Button extends View
{
color myColor = color(255,255,255,0);
boolean myFlag = false;
PImage myImage;
boolean hasImage = false;
String myLabel;
boolean hasText = false;
PFont fontA;
Object myElement;
int myFontSize;
boolean myVertical = false;
boolean isDirectional = false;
boolean hasDirection;
boolean selectButton = false;
boolean hasSelect;
Button(float x_, float y_, float w_, float h_, Object element)
{
super(x_,y_,w_,h_);
}
Button(float x_, float y_, float w_, float h_, Object element, PImage theImage, boolean isDirectional)
{
super(x_,y_,w_,h_);
hasImage = true;
myImage = theImage;
if(!isDirectional){
theImage.resize(50, 50);
}
else if(isDirectional){
theImage.resize(14,14);
}
myElement = element;
hasDirection = isDirectional;
}
Button(float x_, float y_, float w_, float h_, Object element, int fontSize, boolean vertical, String theLabel, boolean selectButton)
{
super(x_,y_,w_,h_);
hasText = true;
myLabel = theLabel;
myFontSize = fontSize;
fontA = loadFont("Helvetica-Light-"+myFontSize+".vlw");
myElement = element;
myVertical = vertical;
hasSelect = selectButton;
}
boolean selected()
{
return myFlag;
}
void drawContent()
{
if (hasImage && !hasDirection && !hasSelect) {
if (selected()) tint(0, 153, 204, 126);
else noTint();
image(myImage,0,0);
}
else if (hasImage && hasDirection && !hasSelect) {
noTint();
fill(0);
stroke(1);
// bounding box for the directional buttons
// makes it pop out a bit easier
rect(0-1,0-1,w+1,h+1);
image(myImage,0,0);
}
if (hasText){
textFont(fontA, myFontSize);
fill(selected() ? shipRed : shipLight);
noStroke();
rect(0,0,w,h);
fill(selected() ? 255 : shipRedDark);
if (myVertical) {
textAlign(LEFT, TOP);
pushMatrix();
translate(0,h);
rotate(3*HALF_PI);
text(myLabel, 0, 0);
popMatrix();
}
if(hasText && !myVertical){
text(myLabel,0,0);
}
}
}
boolean contentClicked(float lx, float ly)
{
if(hasDirection){
tint(0, 130,109,200);
image(myImage,x,y);
}
buttonClicked(myElement);
return true;
}
}
class CharacterButton extends Button {
final int highlightWidth = 4;
CharacterButton(float x_, float y_, float w_, float h_, Character character)
{
super(x_,y_,w_,h_, character, character.img, false);
}
boolean selected()
{
Character character = (Character)myElement;
return character.active;
}
void drawContent()
{
Character character = (Character)myElement;
if (selected()) {
fill(character.keyColor);
noStroke();
rect(-highlightWidth, -highlightWidth, w+highlightWidth*2, h+highlightWidth*2);
}
image(myImage,0,0);
}
}