SHOW:
|
|
- or go back to the newest paste.
1 | local gui = {} | |
2 | local gpu = require("component").gpu | |
3 | local unicode = require("unicode") | |
4 | author_name = "subr72" | |
5 | function gui.resolution(x, y) | |
6 | if x < 45 then | |
7 | x = 45 | |
8 | elseif y < 15 then | |
9 | y = 15 | |
10 | end | |
11 | gpu.setResolution(x, y) | |
12 | end | |
13 | ||
14 | function gui.draw(color, w, h, text) | |
15 | gpu.setForeground(color) | |
16 | gpu.set(1, 1, "╔") | |
17 | gpu.set(1, h, "╚") | |
18 | gpu.set(w, 1, "╗") | |
19 | gpu.set(w, h, "╝") | |
20 | gpu.fill(1, 2, 1, h - 2, "║") | |
21 | gpu.fill(2, 1, w - 2, 1, "═") | |
22 | gpu.fill(w, 2, 1, h - 2, "║") | |
23 | gpu.fill(2, h, w - 2, 1, "═") | |
24 | gpu.set(w / 2 - (unicode.len(text) / 2) - 2, 1, "["..text.."]") | |
25 | end | |
26 | function gui.button(x, y, color1, color2, text, double) | |
27 | gpu.setForeground(color1) | |
28 | h = 2 | |
29 | w = 3 + unicode.len(text) | |
30 | if duble == true then | |
31 | gpu.set(x, y, "╔") | |
32 | gpu.set(x, y + h, "╚") | |
33 | gpu.set(x + w, y, "╗") | |
34 | gpu.set(x + w, y + h, "╝") | |
35 | gpu.fill(x + 1, y, w - 1, 1, "═") | |
36 | gpu.fill(x + 1, y + h, w - 1, 1, "═") | |
37 | gpu.fill(x, y + 1, 1, h - 1, "║") | |
38 | gpu.fill(x + w, y + 1, 1, h - 1, "║") | |
39 | else | |
40 | gpu.set(x, y, "┌") | |
41 | gpu.set(x, y + h, "└") | |
42 | gpu.set(x + w, y, "┐") | |
43 | gpu.set(x + w, y + h, "┘") | |
44 | gpu.fill(x + 1, y, w - 1, 1, "─") | |
45 | gpu.fill(x + 1, y + h, w - 1, 1, "─") | |
46 | gpu.fill(x, y + 1, 1, h - 1, "┃") | |
47 | gpu.fill(x + w, y + 1, 1, h - 1, "┃") | |
48 | end | |
49 | gpu.setForeground(color2) | |
50 | gpu.set(x + 2, y + 1, text) | |
51 | end | |
52 | function gui.drawcube(x, y, w, h, color) | |
53 | gpu.setForeground(color) | |
54 | gpu.set(x, y, "╔") | |
55 | gpu.set(x, y + h, "╚") | |
56 | gpu.set(x + w, y, "╗") | |
57 | gpu.set(x + w, y + h, "╝") | |
58 | gpu.fill(x + 1, y, w - 1, 1, "═") | |
59 | gpu.fill(x + 1, y + h, w - 1, 1, "═") | |
60 | gpu.fill(x, y + 1, 1, h - 1, "║") | |
61 | gpu.fill(x + w, y + 1, 1, h - 1, "║") | |
62 | end | |
63 | function gui.drawline(type, x, y, h, color) | |
64 | gpu.setForeground(color) | |
65 | if type == "y" then | |
66 | gpu.set(x, y, "╦") | |
67 | gpu.set(x, y + h - 1, "╩") | |
68 | gpu.fill(x, y + 1, 1, h - 2, "║" ) | |
69 | end | |
70 | if type == "x" then | |
71 | gpu.set(x, y, "╠") | |
72 | gpu.set(x + h - 1, y, "╣") | |
73 | gpu.fill(x + 1, y, h - 2, 1, "═") | |
74 | end | |
75 | end | |
76 | function gui.text(text, color, x, y) | |
77 | gpu.setForeground(color) | |
78 | gpu.set(x, y, text) | |
79 | end | |
80 | return gui | |
81 |