-
Notifications
You must be signed in to change notification settings - Fork 7
/
borderBox.lua
45 lines (44 loc) · 1.73 KB
/
borderBox.lua
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
local PrimeUI = require "util" -- DO NOT COPY THIS LINE
local expect = require "cc.expect".expect -- DO NOT COPY THIS LINE
-- Start copying below this line. --
--- Draws a thin border around a screen region.
---@param win window The window to draw on
---@param x number The X coordinate of the inside of the box
---@param y number The Y coordinate of the inside of the box
---@param width number The width of the inner box
---@param height number The height of the inner box
---@param fgColor color|nil The color of the border (defaults to white)
---@param bgColor color|nil The color of the background (defaults to black)
function PrimeUI.borderBox(win, x, y, width, height, fgColor, bgColor)
expect(1, win, "table")
expect(2, x, "number")
expect(3, y, "number")
expect(4, width, "number")
expect(5, height, "number")
fgColor = expect(6, fgColor, "number", "nil") or colors.white
bgColor = expect(7, bgColor, "number", "nil") or colors.black
-- Draw the top-left corner & top border.
win.setBackgroundColor(bgColor)
win.setTextColor(fgColor)
win.setCursorPos(x - 1, y - 1)
win.write("\x9C" .. ("\x8C"):rep(width))
-- Draw the top-right corner.
win.setBackgroundColor(fgColor)
win.setTextColor(bgColor)
win.write("\x93")
-- Draw the right border.
for i = 1, height do
win.setCursorPos(win.getCursorPos() - 1, y + i - 1)
win.write("\x95")
end
-- Draw the left border.
win.setBackgroundColor(bgColor)
win.setTextColor(fgColor)
for i = 1, height do
win.setCursorPos(x - 1, y + i - 1)
win.write("\x95")
end
-- Draw the bottom border and corners.
win.setCursorPos(x - 1, y + height)
win.write("\x8D" .. ("\x8C"):rep(width) .. "\x8E")
end