[Home] [Downloads] [Search] [Help/forum]


Register forum user name Search FAQ

Gammon Forum

[Folder]  Entire forum
-> [Folder]  MUSHclient
. -> [Folder]  Miniwindows
. . -> [Subject]  WindowText background color possible?

WindowText background color possible?

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page


Posted by Sondayga   (8 posts)  [Biography] bio
Date Sun 09 Dec 2018 05:13 PM (UTC)
Message
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
[Go to top] top

Posted by Sondayga   (8 posts)  [Biography] bio
Date Reply #1 on Sun 09 Dec 2018 08:45 PM (UTC)
Message
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
[Go to top] top

Posted by Nick Gammon   Australia  (22,982 posts)  [Biography] bio   Forum Administrator
Date Reply #2 on Sun 09 Dec 2018 08:57 PM (UTC)
Message

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.


- Nick Gammon

www.gammon.com.au, www.mushclient.com
[Go to top] top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


9,084 views.

It is now over 60 days since the last post. This thread is closed.     [Refresh] Refresh page

Go to topic:           Search the forum


[Go to top] top

Quick links: MUSHclient. MUSHclient help. Forum shortcuts. Posting templates. Lua modules. Lua documentation.

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.

[Home]


Written by Nick Gammon - 5K   profile for Nick Gammon on Stack Exchange, a network of free, community-driven Q&A sites   Marriage equality

Comments to: Gammon Software support
[RH click to get RSS URL] Forum RSS feed ( https://gammon.com.au/rss/forum.xml )

[Best viewed with any browser - 2K]    [Hosted at HostDash]