chore: re-added have_a_coffee discussion, fixed text readability, fixed centering of texts, new system.ui functions for drawing in contour, fixed ddr types, fixed meter drawing
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed

This commit is contained in:
Zoltan Timar
2026-04-09 16:36:19 +02:00
parent 8921f02821
commit 9d56ca2e7a
18 changed files with 296 additions and 127 deletions

View File

@@ -14,6 +14,28 @@ function Print.text(text, x, y, color, fixed, scale)
print(text, x, y, color, fixed, scale)
end
--- Prints text with a contour (outline) instead of shadow.
--- @within Print
--- @param text string The text to print.<br/>
--- @param x number The x-coordinate.<br/>
--- @param y number The y-coordinate.<br/>
--- @param color number The color of the text.<br/>
--- @param[opt] fixed boolean If true, uses fixed-width font.<br/>
--- @param[opt] scale number The scaling factor (also used for outline thickness).<br/>
--- @param[opt] contour_color number Outline color; defaults to black; if equal to text color, uses white.<br/>
function Print.text_contour(text, x, y, color, fixed, scale, contour_color)
scale = scale or 1
local cc = contour_color
if cc == nil then cc = Config.colors.black end
if color == cc then cc = Config.colors.white end
local ox = { -scale, scale, 0, 0, -scale, scale, -scale, scale }
local oy = { 0, 0, -scale, scale, -scale, -scale, scale, scale }
for i = 1, 8 do
print(text, x + ox[i], y + oy[i], cc, fixed, scale)
end
print(text, x, y, color, fixed, scale)
end
--- Prints centered text with shadow.
--- @within Print
--- @param text string The text to print.<br/>
@@ -28,3 +50,19 @@ function Print.text_center(text, x, y, color, fixed, scale)
local centered_x = x - (text_width / 2)
Print.text(text, centered_x, y, color, fixed, scale)
end
--- Prints centered text with contour instead of shadow.
--- @within Print
--- @param text string The text to print.<br/>
--- @param x number The x-coordinate for centering.<br/>
--- @param y number The y-coordinate.<br/>
--- @param color number The color of the text.<br/>
--- @param[opt] fixed boolean If true, uses fixed-width font.<br/>
--- @param[opt] scale number The scaling factor.<br/>
--- @param[opt] contour_color number Outline color; defaults to black; if equal to text color, uses white.<br/>
function Print.text_center_contour(text, x, y, color, fixed, scale, contour_color)
scale = scale or 1
local text_width = print(text, 0, -6 * scale, 0, fixed, scale)
local centered_x = x - (text_width / 2)
Print.text_contour(text, centered_x, y, color, fixed, scale, contour_color)
end

View File

@@ -90,12 +90,54 @@ end
--- @param[opt] bg_color number The background fill color (default: Config.colors.dark_grey).<br/>
--- @param[opt] border_color number The border color (default: Config.colors.white).<br/>
--- @param[opt] center_text boolean Whether to center each line inside the box. Defaults to false.<br/>
local function draw_rounded_rect_fill(x, y, w, h, radius, color)
local inner_w = w - radius * 2
local inner_h = h - radius * 2
if inner_w > 0 and inner_h > 0 then
rect(x + radius, y + radius, inner_w, inner_h, color)
end
if inner_w > 0 and radius > 0 then
rect(x + radius, y, inner_w, radius, color)
rect(x + radius, y + h - radius, inner_w, radius, color)
end
if radius > 0 and inner_h > 0 then
rect(x, y + radius, radius, inner_h, color)
rect(x + w - radius, y + radius, radius, inner_h, color)
end
for row = 0, radius - 1 do
for col = 0, radius - 1 do
if col + row >= radius - 1 then
pix(x + radius - 1 - col, y + radius - 1 - row, color)
pix(x + w - radius + col, y + radius - 1 - row, color)
pix(x + radius - 1 - col, y + h - radius + row, color)
pix(x + w - radius + col, y + h - radius + row, color)
end
end
end
end
local function draw_rounded_rect_border(x, y, w, h, radius, color)
line(x + radius, y, x + w - radius - 1, y, color)
line(x + radius, y + h - 1, x + w - radius - 1, y + h - 1, color)
line(x, y + radius, x, y + h - radius - 1, color)
line(x + w - 1, y + radius, x + w - 1, y + h - radius - 1, color)
pix(x + radius - 1, y + 1, color)
pix(x + 1, y + radius - 1, color)
pix(x + w - radius, y + 1, color)
pix(x + w - 2, y + radius - 1, color)
pix(x + radius - 1, y + h - 2, color)
pix(x + 1, y + h - radius, color)
pix(x + w - radius, y + h - 2, color)
pix(x + w - 2, y + h - radius, color)
end
function UI.draw_textbox(text, box_x, box_y, box_w, box_h, scroll_y, color, bg_color, border_color, center_text)
color = color or Config.colors.white
bg_color = bg_color or Config.colors.dark_grey
bg_color = bg_color or Config.colors.black
border_color = border_color or Config.colors.white
center_text = center_text or false
local r = 3
local padding = 4
local line_height = 8
local inner_x = box_x + padding
@@ -110,7 +152,7 @@ function UI.draw_textbox(text, box_x, box_y, box_w, box_h, scroll_y, color, bg_c
base_y = inner_y + math.floor((visible_height - text_height) / 2)
end
rect(box_x, box_y, box_w, box_h, bg_color)
draw_rounded_rect_fill(box_x, box_y, box_w, box_h, r, bg_color)
for i, line in ipairs(lines) do
local ly = base_y + (i - 1) * line_height - scroll_y
@@ -123,7 +165,7 @@ function UI.draw_textbox(text, box_x, box_y, box_w, box_h, scroll_y, color, bg_c
end
end
rectb(box_x, box_y, box_w, box_h, border_color)
draw_rounded_rect_border(box_x, box_y, box_w, box_h, r, border_color)
end
--- Wraps text.