-
Notifications
You must be signed in to change notification settings - Fork 0
/
UIShape.pde
78 lines (63 loc) · 1.27 KB
/
UIShape.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
class UISprite extends UIShape {
PImage image;
boolean enabled = true;
UISprite (int pX, int pY, String imageFileName) {
super(round(pX * widthRatio), round(pY * heightRatio));
image = loadImage(imageFileName);
if (image != null) {
w = round(image.width * widthRatio);
h = round(image.height * heightRatio);
colliderW = w;
colliderH = h;
}
}
void display(float delta) {
if (enabled) {
c = (c & 0xffffff) | (alpha << 24);
tint(c);
pushMatrix();
translate(x, y);
imageMode(CORNER);
image(image, 0, 0, w, h);
popMatrix();
super.endDisplay();
}
}
}
abstract class UIShape {
color c = #FFFFFF;
color strokeColor = #111111;
int alpha = 255;
int x;
int y;
int w;
int h;
int colliderW;
int colliderH;
UIShape(int pX, int pY) {
x = pX;
y = pY;
}
UIShape(int pX, int pY, int pW, int pH) {
this(pX, pY);
w = pW;
h = pH;
colliderW = w;
colliderH = h;
}
abstract void display(float delta);
void endDisplay() {
}
}
class Rect {
float x;
float y;
float w;
float h;
Rect(float pX, float pY, float pW, float pH) {
x = pX * widthRatio;
y = pY * heightRatio;
w = pW * widthRatio;
h = pH * heightRatio;
}
}