mirror of
https://github.com/MikaylaFischler/cc-mek-scada.git
synced 2024-08-30 18:22:34 +00:00
pipenet indicator instead of pipe indicator
This commit is contained in:
parent
01caf3d914
commit
ef73c52417
@ -103,6 +103,42 @@ function graphics.cpair(a, 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 subpixels, false (default) for 2
|
||||
---@field align_tr boolean false to align bottom left (default), true to align top right
|
||||
|
||||
-- create a new pipe
|
||||
--
|
||||
-- note: pipe coordinate origin is (0, 0)
|
||||
---@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 subpixels, false (default) for 2
|
||||
---@param align_tr? boolean false to align bottom left (default), true to align top right
|
||||
---@return pipe
|
||||
function graphics.pipe(x1, y1, x2, y2, color, thin, align_tr)
|
||||
return {
|
||||
x1 = x1,
|
||||
y1 = y1,
|
||||
x2 = x2,
|
||||
y2 = y2,
|
||||
w = x2 - x1,
|
||||
h = y2 - y1,
|
||||
color = color,
|
||||
thin = thin or false,
|
||||
align_tr = align_tr or false
|
||||
}
|
||||
end
|
||||
|
||||
core.graphics = graphics
|
||||
|
||||
return core
|
||||
|
@ -1,110 +0,0 @@
|
||||
-- Pipe Graphics Element
|
||||
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local element = require("graphics.element")
|
||||
|
||||
---@class pipe_args
|
||||
---@field parent graphics_element
|
||||
---@field x? integer 1 if omitted
|
||||
---@field y? integer 1 if omitted
|
||||
---@field end_x integer end of pipe
|
||||
---@field end_y integer end of pipe
|
||||
---@field thin boolean true for 1 subpixels, false (default) for 2
|
||||
---@field align_tr? boolean false to align bottom left (default), true to align top right
|
||||
---@field fg_bg? cpair foreground/background colors
|
||||
|
||||
-- new pipe
|
||||
---@param args pipe_args
|
||||
local function pipe(args)
|
||||
assert(util.is_int(args.end_x), "graphics.elements.indicators.pipe: end_x is a required field")
|
||||
assert(util.is_int(args.end_y), "graphics.elements.indicators.pipe: end_y is a required field")
|
||||
|
||||
args.x = args.x or 1
|
||||
args.y = args.y or 1
|
||||
args.width = args.end_x - args.x
|
||||
args.height = args.end_y - args.y
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
||||
-- draw pipe
|
||||
|
||||
local align_tr = args.align_tr or false
|
||||
|
||||
local x = 1
|
||||
local y = 1
|
||||
|
||||
if align_tr then
|
||||
-- cross width then height
|
||||
for i = 1, args.width do
|
||||
if args.thin then
|
||||
if i == args.width then
|
||||
-- corner
|
||||
e.window.blit("\x93", e.fg_bg.blit_bkg, e.fg_bg.blit_fgd)
|
||||
else
|
||||
e.window.blit("\x8c", e.fg_bg.blit_fgd, e.fg_bg.blit_bkg)
|
||||
end
|
||||
else
|
||||
if i == args.width then
|
||||
-- corner
|
||||
e.window.blit(" ", e.fg_bg.blit_bkg, e.fg_bg.blit_fgd)
|
||||
else
|
||||
e.window.blit("\x8f", e.fg_bg.blit_fgd, e.fg_bg.blit_bkg)
|
||||
end
|
||||
end
|
||||
|
||||
x = x + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
end
|
||||
|
||||
-- back up one
|
||||
x = x - 1
|
||||
|
||||
for _ = 1, args.height do
|
||||
y = y + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
|
||||
if args.thin then
|
||||
e.window.blit("\x95", e.fg_bg.blit_bkg, e.fg_bg.blit_fgd)
|
||||
else
|
||||
e.window.blit(" ", e.fg_bg.blit_bkg, e.fg_bg.blit_fgd)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- cross height then width
|
||||
for i = 1, args.height do
|
||||
if args.thin then
|
||||
if i == args.height then
|
||||
-- corner
|
||||
e.window.blit("\x8d", e.fg_bg.blit_fgd, e.fg_bg.blit_bkg)
|
||||
else
|
||||
e.window.blit("\x95", e.fg_bg.blit_fgd, e.fg_bg.blit_bkg)
|
||||
end
|
||||
else
|
||||
e.window.blit(" ", e.fg_bg.blit_bkg, e.fg_bg.blit_fgd)
|
||||
end
|
||||
|
||||
y = y + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
end
|
||||
|
||||
-- back up one
|
||||
y = y - 1
|
||||
|
||||
for _ = 1, args.width do
|
||||
x = x + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
|
||||
if args.thin then
|
||||
e.window.blit("\x8c", e.fg_bg.blit_fgd, e.fg_bg.blit_bkg)
|
||||
else
|
||||
e.window.blit("\x83", e.fg_bg.blit_bkg, e.fg_bg.blit_fgd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
return e.get()
|
||||
end
|
||||
|
||||
return pipe
|
129
graphics/elements/indicators/pipenet.lua
Normal file
129
graphics/elements/indicators/pipenet.lua
Normal file
@ -0,0 +1,129 @@
|
||||
-- Pipe Graphics Element
|
||||
|
||||
local util = require("scada-common.util")
|
||||
|
||||
local core = require("graphics.core")
|
||||
local element = require("graphics.element")
|
||||
|
||||
---@class pipenet_args
|
||||
---@field parent graphics_element
|
||||
---@field x? integer 1 if omitted
|
||||
---@field y? integer 1 if omitted
|
||||
---@field pipes table pipe list
|
||||
---@field bg? color background color
|
||||
|
||||
-- new pipe network
|
||||
---@param args pipenet_args
|
||||
local function pipenet(args)
|
||||
assert(type(args.pipes) == "table", "graphics.elements.indicators.pipenet: pipes is a required field")
|
||||
|
||||
args.width = 0
|
||||
args.height = 0
|
||||
|
||||
-- determine width/height
|
||||
for i = 1, #args.pipes do
|
||||
local pipe = args.pipes[i] ---@type pipe
|
||||
|
||||
local true_w = pipe.w + pipe.x1
|
||||
local true_h = pipe.h + pipe.y1
|
||||
|
||||
if true_w > args.width then args.width = true_w end
|
||||
if true_h > args.height then args.height = true_h end
|
||||
end
|
||||
|
||||
args.x = args.x or 1
|
||||
args.y = args.y or 1
|
||||
|
||||
if args.bg ~= nil then
|
||||
args.fg_bg = core.graphics.cpair(args.bg, args.bg)
|
||||
end
|
||||
|
||||
-- create new graphics element base object
|
||||
local e = element.new(args)
|
||||
|
||||
-- draw all pipes
|
||||
for p = 1, #args.pipes do
|
||||
local pipe = args.pipes[p] ---@type pipe
|
||||
|
||||
local x = 1 + pipe.x1
|
||||
local y = 1 + pipe.y1
|
||||
|
||||
e.window.setCursorPos(x, y)
|
||||
|
||||
local c = core.graphics.cpair(pipe.color, e.fg_bg.bkg)
|
||||
|
||||
if pipe.align_tr then
|
||||
-- cross width then height
|
||||
for i = 1, pipe.w do
|
||||
if pipe.thin then
|
||||
if i == pipe.w then
|
||||
-- corner
|
||||
e.window.blit("\x93", c.blit_bkg, c.blit_fgd)
|
||||
else
|
||||
e.window.blit("\x8c", c.blit_fgd, c.blit_bkg)
|
||||
end
|
||||
else
|
||||
if i == pipe.w then
|
||||
-- corner
|
||||
e.window.blit(" ", c.blit_bkg, c.blit_fgd)
|
||||
else
|
||||
e.window.blit("\x8f", c.blit_fgd, c.blit_bkg)
|
||||
end
|
||||
end
|
||||
|
||||
x = x + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
end
|
||||
|
||||
-- back up one
|
||||
x = x - 1
|
||||
|
||||
for _ = 1, pipe.h do
|
||||
y = y + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
|
||||
if pipe.thin then
|
||||
e.window.blit("\x95", c.blit_bkg, c.blit_fgd)
|
||||
else
|
||||
e.window.blit(" ", c.blit_bkg, c.blit_fgd)
|
||||
end
|
||||
end
|
||||
else
|
||||
-- cross height then width
|
||||
for i = 1, pipe.h do
|
||||
if pipe.thin then
|
||||
if i == pipe.h then
|
||||
-- corner
|
||||
e.window.blit("\x8d", c.blit_fgd, c.blit_bkg)
|
||||
else
|
||||
e.window.blit("\x95", c.blit_fgd, c.blit_bkg)
|
||||
end
|
||||
else
|
||||
e.window.blit(" ", c.blit_bkg, c.blit_fgd)
|
||||
end
|
||||
|
||||
y = y + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
end
|
||||
|
||||
-- back up one
|
||||
y = y - 1
|
||||
|
||||
for _ = 1, pipe.w do
|
||||
x = x + 1
|
||||
e.window.setCursorPos(x, y)
|
||||
|
||||
if pipe.thin then
|
||||
e.window.blit("\x8c", c.blit_fgd, c.blit_bkg)
|
||||
else
|
||||
e.window.blit("\x83", c.blit_bkg, c.blit_fgd)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
return e.get()
|
||||
end
|
||||
|
||||
return pipenet
|
Loading…
Reference in New Issue
Block a user