2022-06-14 16:02:42 +00:00
|
|
|
--
|
2023-05-07 01:27:36 +00:00
|
|
|
-- Graphics Core Types, Checks, and Constructors
|
2022-06-14 16:02:42 +00:00
|
|
|
--
|
|
|
|
|
2023-05-10 00:29:07 +00:00
|
|
|
local events = require("graphics.events")
|
|
|
|
local flasher = require("graphics.flasher")
|
2023-04-09 01:33:54 +00:00
|
|
|
|
2023-05-10 00:29:07 +00:00
|
|
|
local core = {}
|
2022-06-06 19:42:39 +00:00
|
|
|
|
2023-08-10 03:26:06 +00:00
|
|
|
core.version = "1.0.3"
|
2023-06-18 04:40:01 +00:00
|
|
|
|
2023-05-10 00:29:07 +00:00
|
|
|
core.flasher = flasher
|
2022-06-06 19:42:39 +00:00
|
|
|
core.events = events
|
|
|
|
|
2023-05-07 01:27:36 +00:00
|
|
|
-- Core Types
|
2022-06-06 19:42:39 +00:00
|
|
|
|
2023-02-25 00:50:01 +00:00
|
|
|
---@enum TEXT_ALIGN
|
2023-05-07 01:27:36 +00:00
|
|
|
core.TEXT_ALIGN = {
|
2022-06-06 19:42:39 +00:00
|
|
|
LEFT = 1,
|
|
|
|
CENTER = 2,
|
|
|
|
RIGHT = 3
|
|
|
|
}
|
|
|
|
|
2022-06-08 16:27:28 +00:00
|
|
|
---@class graphics_border
|
|
|
|
---@field width integer
|
|
|
|
---@field color color
|
2022-06-08 17:08:48 +00:00
|
|
|
---@field even boolean
|
2022-06-08 16:27:28 +00:00
|
|
|
|
2022-07-28 14:09:34 +00:00
|
|
|
---@alias element_id string|integer
|
|
|
|
|
2022-06-08 17:08:48 +00:00
|
|
|
-- create a new border definition
|
2023-02-25 00:50:01 +00:00
|
|
|
---@nodiscard
|
2022-06-08 17:08:48 +00:00
|
|
|
---@param width integer border width
|
|
|
|
---@param color color border color
|
2022-06-16 15:31:52 +00:00
|
|
|
---@param even? boolean whether to pad width extra to account for rectangular pixels, defaults to false
|
2022-06-08 16:27:28 +00:00
|
|
|
---@return graphics_border
|
2023-05-07 01:27:36 +00:00
|
|
|
function core.border(width, color, even)
|
2022-06-08 16:27:28 +00:00
|
|
|
return {
|
|
|
|
width = width,
|
2022-06-08 17:08:48 +00:00
|
|
|
color = color,
|
2022-06-16 15:31:52 +00:00
|
|
|
even = even or false -- convert nil to false
|
2022-06-08 16:27:28 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-06-06 19:42:39 +00:00
|
|
|
---@class graphics_frame
|
|
|
|
---@field x integer
|
|
|
|
---@field y integer
|
|
|
|
---@field w integer
|
|
|
|
---@field h integer
|
|
|
|
|
2022-06-08 17:08:48 +00:00
|
|
|
-- create a new graphics frame definition
|
2023-02-25 00:50:01 +00:00
|
|
|
---@nodiscard
|
2022-06-06 19:42:39 +00:00
|
|
|
---@param x integer
|
|
|
|
---@param y integer
|
|
|
|
---@param w integer
|
|
|
|
---@param h integer
|
|
|
|
---@return graphics_frame
|
2023-05-07 01:27:36 +00:00
|
|
|
function core.gframe(x, y, w, h)
|
2022-06-06 19:42:39 +00:00
|
|
|
return {
|
|
|
|
x = x,
|
|
|
|
y = y,
|
|
|
|
w = w,
|
|
|
|
h = h
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
---@class cpair
|
2022-06-08 17:08:48 +00:00
|
|
|
---@field color_a color
|
|
|
|
---@field color_b color
|
|
|
|
---@field blit_a string
|
|
|
|
---@field blit_b string
|
2022-06-06 19:42:39 +00:00
|
|
|
---@field fgd color
|
|
|
|
---@field bkg color
|
|
|
|
---@field blit_fgd string
|
|
|
|
---@field blit_bkg string
|
|
|
|
|
2022-06-08 17:08:48 +00:00
|
|
|
-- create a new color pair definition
|
2023-02-25 00:50:01 +00:00
|
|
|
---@nodiscard
|
2022-06-08 17:08:48 +00:00
|
|
|
---@param a color
|
|
|
|
---@param b color
|
2022-06-06 19:42:39 +00:00
|
|
|
---@return cpair
|
2023-05-07 01:27:36 +00:00
|
|
|
function core.cpair(a, b)
|
2022-06-06 19:42:39 +00:00
|
|
|
return {
|
2022-06-08 17:08:48 +00:00
|
|
|
-- color pairs
|
|
|
|
color_a = a,
|
|
|
|
color_b = b,
|
2022-07-14 17:45:40 +00:00
|
|
|
blit_a = colors.toBlit(a),
|
|
|
|
blit_b = colors.toBlit(b),
|
2022-06-08 17:08:48 +00:00
|
|
|
-- aliases
|
|
|
|
fgd = a,
|
|
|
|
bkg = b,
|
|
|
|
blit_fgd = colors.toBlit(a),
|
|
|
|
blit_bkg = colors.toBlit(b)
|
2022-06-06 19:42:39 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-06-29 21:40:08 +00:00
|
|
|
---@class pipe
|
|
|
|
---@field x1 integer starting x, origin is 0
|
|
|
|
---@field y1 integer starting y, origin is 0
|
|
|
|
---@field x2 integer ending x, origin is 0
|
|
|
|
---@field y2 integer ending y, origin is 0
|
|
|
|
---@field w integer width
|
|
|
|
---@field h integer height
|
|
|
|
---@field color color pipe color
|
2022-07-28 14:09:34 +00:00
|
|
|
---@field thin boolean true for 1 subpixel, false (default) for 2
|
2022-06-29 21:40:08 +00:00
|
|
|
---@field align_tr boolean false to align bottom left (default), true to align top right
|
|
|
|
|
2023-02-25 00:50:01 +00:00
|
|
|
-- create a new pipe<br>
|
2022-06-29 21:40:08 +00:00
|
|
|
-- note: pipe coordinate origin is (0, 0)
|
2023-02-25 00:50:01 +00:00
|
|
|
---@nodiscard
|
2022-06-29 21:40:08 +00:00
|
|
|
---@param x1 integer starting x, origin is 0
|
|
|
|
---@param y1 integer starting y, origin is 0
|
|
|
|
---@param x2 integer ending x, origin is 0
|
|
|
|
---@param y2 integer ending y, origin is 0
|
|
|
|
---@param color color pipe color
|
2022-07-28 14:09:34 +00:00
|
|
|
---@param thin? boolean true for 1 subpixel, false (default) for 2
|
2022-06-29 21:40:08 +00:00
|
|
|
---@param align_tr? boolean false to align bottom left (default), true to align top right
|
|
|
|
---@return pipe
|
2023-05-07 01:27:36 +00:00
|
|
|
function core.pipe(x1, y1, x2, y2, color, thin, align_tr)
|
2022-06-29 21:40:08 +00:00
|
|
|
return {
|
|
|
|
x1 = x1,
|
|
|
|
y1 = y1,
|
|
|
|
x2 = x2,
|
|
|
|
y2 = y2,
|
2022-07-02 19:08:24 +00:00
|
|
|
w = math.abs(x2 - x1) + 1,
|
|
|
|
h = math.abs(y2 - y1) + 1,
|
2022-06-29 21:40:08 +00:00
|
|
|
color = color,
|
|
|
|
thin = thin or false,
|
|
|
|
align_tr = align_tr or false
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2022-06-06 19:42:39 +00:00
|
|
|
return core
|