cc-mek-scada/graphics/core.lua

125 lines
2.9 KiB
Lua
Raw Normal View History

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
--
local events = require("graphics.events")
local flasher = require("graphics.flasher")
local core = {}
core.version = "1.1.3"
2023-06-18 04:40:01 +00:00
core.flasher = flasher
core.events = events
2023-05-07 01:27:36 +00:00
-- Core Types
2023-02-25 00:50:01 +00:00
---@enum TEXT_ALIGN
2023-05-07 01:27:36 +00:00
core.TEXT_ALIGN = {
LEFT = 1,
CENTER = 2,
RIGHT = 3
}
2022-06-08 16:27:28 +00:00
---@class graphics_border
---@field width integer
---@field color color
---@field even boolean
2022-06-08 16:27:28 +00:00
---@alias element_id string|integer
-- create a new border definition
2023-02-25 00:50:01 +00:00
---@nodiscard
---@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)
2023-08-31 01:11:57 +00:00
return { width = width, color = color, even = even or false }
2022-06-08 16:27:28 +00:00
end
---@class graphics_frame
---@field x integer
---@field y integer
---@field w integer
---@field h integer
-- create a new graphics frame definition
2023-02-25 00:50:01 +00:00
---@nodiscard
---@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)
2023-08-31 01:11:57 +00:00
return { x = x, y = y, w = w, h = h }
end
---@class cpair
---@field color_a color
---@field color_b color
---@field blit_a string
---@field blit_b string
---@field fgd color
---@field bkg color
---@field blit_fgd string
---@field blit_bkg string
-- create a new color pair definition
2023-02-25 00:50:01 +00:00
---@nodiscard
---@param a color
---@param b color
---@return cpair
2023-05-07 01:27:36 +00:00
function core.cpair(a, b)
return {
-- color pairs
color_a = a,
color_b = b,
blit_a = colors.toBlit(a),
blit_b = colors.toBlit(b),
-- aliases
fgd = a,
bkg = b,
blit_fgd = colors.toBlit(a),
blit_bkg = colors.toBlit(b)
}
end
---@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
---@field thin boolean true for 1 subpixel, false (default) for 2
---@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>
-- note: pipe coordinate origin is (0, 0)
2023-02-25 00:50:01 +00:00
---@nodiscard
---@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
---@param thin? boolean true for 1 subpixel, false (default) for 2
---@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)
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,
color = color,
thin = thin or false,
align_tr = align_tr or false
}
end
return core