forked from microsoft/microcode
-
Notifications
You must be signed in to change notification settings - Fork 0
/
screen.ts
84 lines (78 loc) · 2.35 KB
/
screen.ts
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
namespace microcode {
export class Screen {
private static image_: ImageG
public static WIDTH = screen.width
public static HEIGHT = screen.height
public static HALF_WIDTH = screen.width >> 1
public static HALF_HEIGHT = screen.height >> 1
public static LEFT_EDGE = -Screen.HALF_WIDTH
public static RIGHT_EDGE = Screen.HALF_WIDTH
public static TOP_EDGE = -Screen.HALF_HEIGHT
public static BOTTOM_EDGE = Screen.HALF_HEIGHT
public static BOUNDS = new Bounds({
left: Screen.LEFT_EDGE,
top: Screen.TOP_EDGE,
width: Screen.WIDTH,
height: Screen.HEIGHT,
})
public static x(v: number) {
return v + Screen.HALF_WIDTH
}
public static y(v: number) {
return v + Screen.HALF_HEIGHT
}
public static pos(v: Vec2) {
return new Vec2(Screen.x(v.x), Screen.y(v.y))
}
public static get image(): ImageG {
if (!Screen.image_) {
Screen.image_ = image.create(screen.width, screen.height)
}
return Screen.image_
}
public static drawTransparentImage(from: ImageG, x: number, y: number) {
Screen.image.drawTransparentImage(from, Screen.x(x), Screen.y(y))
}
public static drawLine(
x0: number,
y0: number,
x1: number,
y1: number,
c: number
) {
Screen.image.drawLine(
Screen.x(x0),
Screen.y(y0),
Screen.x(x1),
Screen.y(y1),
c
)
}
public static fillRect(
x: number,
y: number,
width: number,
height: number,
c: number
) {
Screen.image.fillRect(Screen.x(x), Screen.y(y), width, height, c)
}
public static print(
text: string,
x: number,
y: number,
color?: number,
font?: image.Font,
offsets?: texteffects.TextEffectState[]
) {
Screen.image.print(
text,
Screen.x(x),
Screen.y(y),
color,
font,
offsets
)
}
}
}