WindowText background color possible?

Posted by Sondayga on Sun 09 Dec 2018 05:13 PM — 3 posts, 13,893 views.

#0
I'm working on redirecting a 'wilderness' like map to a window. The redirecting is going fine as is but I really need a way to draw the background color from the styles table as well. Wondering if anyone has worked something like this out before. I might just need to go about it a different way?

Games map output for reference
https://ada-young.appspot.com/pastebin/46soiKKM


local win = "test_window"
local font = "test_font"
test_map = {}
lines = 0
function test_map_start(name, line, wildcards, styles)
test_map = {}
lines = 0
EnableTrigger("test_map_capture", true)
	if not WindowInfo(win, 1) then
		WindowCreate(win, 0, 0, 0, 0, 6, 0, 0)
		WindowFont(win, font, "Droid Sans Mono", 9)
	end
end

function test_map_capture(name, line, wildcards, styles)
lines = lines + 1

if lines <= 17 then
	table.insert(test_map, styles)
end
if lines == 17 then
test_map_show()
EnableTrigger("test_map_capture", false)
end

end

function test_map_show()
WindowCreate(win, 0, 0, 300, 300, 4, 0, ColourNameToRGB("black"))
WindowRectOp(win, 1, 0, 0, 0, 0, ColourNameToRGB("red"))
WindowShow(win, true)
local font_height = WindowFontInfo(win, font, 1)
local y = font_height * 2 + 5
for i, styles in ipairs(test_map) do
 local x = 5
 for _, style in ipairs(styles) do
  x = x+WindowText(win, font, style.text, x, y, 0, 0, style.textcolour)
end
  y = y + font_height
end
end
#1
I took some time to think about this more and came up with a solution. If someone has a better one please let me know. Following along with drawing the text, I'm also going to draw a rectangle behind it/before it to get the effect.


function test_map_show()
WindowCreate(win, 0, 0, 300, 300, 4, 0, ColourNameToRGB("black"))
WindowFont(win, font, "Lucidia Console", 9, false, false, false, false, 1, 48)
WindowRectOp(win, 1, 0, 0, 0, 0, ColourNameToRGB("red"))
WindowShow(win, true)
local font_height = WindowFontInfo(win, font, 1)
local y = font_height * 2 + 5
	for i, styles in ipairs(test_map) do
	local x = 5
 	local n = 5
 	for _, style in ipairs(styles) do
  	x = x+WindowRectOp(win, 2, x, y, 0, 0, style.backcolour) 
  	x = x+WindowText(win, font, style.text, x, y, 0, 0, style.textcolour)

	end
  	y = y + font_height
	end
end
Australia Forum Administrator #2

That is the correct approach. A background is just where text isn’t so it is not really logical for text drawing to also draw a background. After all, how much space around the text would the background take?

Normally I would draw a background rectangle first, and then the text on top. You can find out the text dimensions using WindowTextWidth and WindowFontInfo if you want to know exactly how high, and wide, a particular piece of text is.