-
Notifications
You must be signed in to change notification settings - Fork 0
/
Label.pde
163 lines (160 loc) · 3.83 KB
/
Label.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
interface LabelInterface{
void onLeftClick(Label l,int x, int y);
void onRightClick(Label l,int x, int y);
}
public class Label implements Comparable<Label>{
public Label(int x,int y, int w, int h, String text, int textSize){
this.x= x;
this.y= y;
this.w= w;
this.h= h;
this.text = text;
this.textSize = textSize;
this.r = this.tr = 255;
this.g = this.tg = 255;
this.b = this.tb = 255;
filled= true;
highlight = false;
labelInterface = null;
}
@Override public boolean equals(Object o) {
return (o instanceof Label) && ( this.text == ((Label)o).getText());
}
@Override public int compareTo(Label o) {
if(o instanceof Vertex)
return ((Vertex)this).compareTo(((Vertex)o));
else if(o instanceof Button)
return ((Button)this).compareTo(((Button)o));
else if(o instanceof Edge)
return ((Edge)this).compareTo(((Edge)o));
else
return -1;
}
public Label(Label other){
this.x= other.x;
this.y= other.y;
this.w= other.w;
this.h= other.h;
this.text = other.text;
this.textSize = other.textSize;
this.highlight = other.highlight;
this.r = other.r;
this.tr = other.tr;
this.g = other.g;
this.tg = other.tg;
this.b = other.b;
this.tb = other.tb;
this.filled = other.filled;
labelInterface = other.labelInterface;
}
public String getText(){
return text;
}
public float getTextSize(){
return textSize;
}
public float getX(){
return x;
}
public float getY(){
return y;
}
public float getW(){
return w;
}
public float getH(){
return h;
}
public void setText(String text){
if(text != null)
this.text= text;
}
public void setFilled(boolean isFilled){
filled = isFilled;
}
public void setPosition(int x, int y){
setX(x);
setY(y);
}
public void setX(float x ){
this.x = x;
}
public void setY(float y){
this.y = y;
}
public void setW(float w){
this.w = w;
}
public void setH(float h){
this.h = h;
}
public boolean isHighlighted(){
return highlight;
}
public boolean intersects(float x, float y){
//Let P(x,y), and rectangle A(x1,y1),B(x2,y2),C(x3,y3),D(x4,y4)
//Calculate the sum of areas of △APD,△DPC,△CPB,△PBA△APD,△DPC,△CPB,△PBA.
if(x < this.x || y < this.y){
return false;
}else if(x > this.x+w || y > this.y+h){
return false;
}
return true;
}
public void setHighlight(boolean isHighlighted){
highlight= isHighlighted;
}
public void setRGB(float r,float g,float b){
this.r = r;
this.g = g;
this.b = b;
}
public void setTextRGB(float tr,float tg,float tb){
this.tr = tr;
this.tg = tg;
this.tb = tb;
}
public void setInterface(LabelInterface labelInterface){
this.labelInterface = labelInterface;
}
public LabelInterface getInterface(){
return labelInterface;
}
public void leftClick(int x, int y){
if(labelInterface != null)
labelInterface.onLeftClick(this,x,y);
}
public void rightClick(int x, int y){
if(labelInterface != null)
labelInterface.onRightClick(this,x,y);
else
print("\nLabel Interface NULL\n");
}
public void draw(){
pushMatrix();
//render pos in eucledian space
if(filled){
stroke(0,0,0); //pen stroke color black to outline button
if(highlight){
fill(255,255,0); //file rect with yellow to highlight
}else{
fill(r,g,b);
}
}
else{
noStroke();
noFill();
}
rect(x,y,w,h);
//render label on top
textSize(textSize);
fill(tr,tg,tb);
text(text, x+w*0.20,y+h*0.80);
popMatrix();
}
float x,y,w,h,r,g,b, t,tr,tb,tg;
String text;
float textSize;
boolean highlight, filled;
LabelInterface labelInterface;
}