improvements to rectangle graphics element even rendering
This commit is contained in:
parent
27038f64f7
commit
9bd2229e27
@ -48,7 +48,6 @@ local function hbar(args)
|
|||||||
|
|
||||||
-- compute number of bars
|
-- compute number of bars
|
||||||
local num_bars = util.round(fraction * (bar_width * 2))
|
local num_bars = util.round(fraction * (bar_width * 2))
|
||||||
util.print(num_bars)
|
|
||||||
|
|
||||||
-- redraw bar if changed
|
-- redraw bar if changed
|
||||||
if num_bars ~= last_num_bars then
|
if num_bars ~= last_num_bars then
|
||||||
|
|||||||
@ -25,27 +25,33 @@ local function rectangle(args)
|
|||||||
if args.border ~= nil then
|
if args.border ~= nil then
|
||||||
e.window.setCursorPos(1, 1)
|
e.window.setCursorPos(1, 1)
|
||||||
|
|
||||||
local border_width_v = args.border.width
|
local border_width = args.border.width
|
||||||
local border_width_h = util.trinary(args.border.even, args.border.width * 2, args.border.width)
|
|
||||||
local border_blit = colors.toBlit(args.border.color)
|
local border_blit = colors.toBlit(args.border.color)
|
||||||
local spaces = ""
|
local width_x2 = border_width * 2
|
||||||
local blit_fg = ""
|
local inner_width = e.frame.w - width_x2
|
||||||
local blit_bg_top_bot = ""
|
|
||||||
local blit_bg_sides = ""
|
|
||||||
|
|
||||||
-- check dimensions
|
-- check dimensions
|
||||||
assert(border_width_v * 2 <= e.frame.w, "graphics.elements.rectangle: border too thick for width")
|
assert(width_x2 <= e.frame.w, "graphics.elements.rectangle: border too thick for width")
|
||||||
assert(border_width_h * 2 <= e.frame.h, "graphics.elements.rectangle: border too thick for height")
|
assert(width_x2 <= e.frame.h, "graphics.elements.rectangle: border too thick for height")
|
||||||
|
|
||||||
-- form the basic and top/bottom blit strings
|
-- form the basic line strings and top/bottom blit strings
|
||||||
spaces = util.spaces(e.frame.w)
|
local spaces = util.spaces(e.frame.w)
|
||||||
blit_fg = util.strrep(e.fg_bg.blit_fgd, e.frame.w)
|
local blit_fg = util.strrep(e.fg_bg.blit_fgd, e.frame.w)
|
||||||
blit_bg_top_bot = util.strrep(border_blit, e.frame.w)
|
local blit_bg_sides = ""
|
||||||
|
local blit_bg_top_bot = util.strrep(border_blit, e.frame.w)
|
||||||
|
|
||||||
|
-- partial bars
|
||||||
|
local p_a = util.spaces(border_width) .. util.strrep("\x8f", inner_width) .. util.spaces(border_width)
|
||||||
|
local p_b = util.spaces(border_width) .. util.strrep("\x83", inner_width) .. util.spaces(border_width)
|
||||||
|
local p_inv_fg = util.strrep(border_blit, border_width) .. util.strrep(e.fg_bg.blit_bkg, inner_width) ..
|
||||||
|
util.strrep(border_blit, border_width)
|
||||||
|
local p_inv_bg = util.strrep(e.fg_bg.blit_bkg, border_width) .. util.strrep(border_blit, inner_width) ..
|
||||||
|
util.strrep(e.fg_bg.blit_bkg, border_width)
|
||||||
|
|
||||||
-- form the body blit strings (sides are border, inside is normal)
|
-- form the body blit strings (sides are border, inside is normal)
|
||||||
for x = 1, e.frame.w do
|
for x = 1, e.frame.w do
|
||||||
-- edges get border color, center gets normal
|
-- edges get border color, center gets normal
|
||||||
if x <= border_width_h or x > (e.frame.w - border_width_h) then
|
if x <= border_width or x > (e.frame.w - border_width) then
|
||||||
blit_bg_sides = blit_bg_sides .. border_blit
|
blit_bg_sides = blit_bg_sides .. border_blit
|
||||||
else
|
else
|
||||||
blit_bg_sides = blit_bg_sides .. e.fg_bg.blit_bkg
|
blit_bg_sides = blit_bg_sides .. e.fg_bg.blit_bkg
|
||||||
@ -55,8 +61,34 @@ local function rectangle(args)
|
|||||||
-- draw rectangle with borders
|
-- draw rectangle with borders
|
||||||
for y = 1, e.frame.h do
|
for y = 1, e.frame.h do
|
||||||
e.window.setCursorPos(1, y)
|
e.window.setCursorPos(1, y)
|
||||||
if y <= border_width_v or y > (e.frame.h - border_width_v) then
|
if y <= border_width then
|
||||||
|
-- partial pixel fill
|
||||||
|
if args.border.even and y == border_width then
|
||||||
|
if width_x2 % 3 == 1 then
|
||||||
|
e.window.blit(p_b, p_inv_bg, p_inv_fg)
|
||||||
|
elseif width_x2 % 3 == 2 then
|
||||||
|
e.window.blit(p_a, p_inv_bg, p_inv_fg)
|
||||||
|
else
|
||||||
|
-- skip line
|
||||||
|
e.window.blit(spaces, blit_fg, blit_bg_sides)
|
||||||
|
end
|
||||||
|
else
|
||||||
e.window.blit(spaces, blit_fg, blit_bg_top_bot)
|
e.window.blit(spaces, blit_fg, blit_bg_top_bot)
|
||||||
|
end
|
||||||
|
elseif y > (e.frame.h - border_width) then
|
||||||
|
-- partial pixel fill
|
||||||
|
if args.border.even and y == ((e.frame.h - border_width) + 1) then
|
||||||
|
if width_x2 % 3 == 1 then
|
||||||
|
e.window.blit(p_a, p_inv_fg, blit_bg_top_bot)
|
||||||
|
elseif width_x2 % 3 == 2 then
|
||||||
|
e.window.blit(p_b, p_inv_fg, blit_bg_top_bot)
|
||||||
|
else
|
||||||
|
-- skip line
|
||||||
|
e.window.blit(spaces, blit_fg, blit_bg_sides)
|
||||||
|
end
|
||||||
|
else
|
||||||
|
e.window.blit(spaces, blit_fg, blit_bg_top_bot)
|
||||||
|
end
|
||||||
else
|
else
|
||||||
e.window.blit(spaces, blit_fg, blit_bg_sides)
|
e.window.blit(spaces, blit_fg, blit_bg_sides)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user