Trouble with "erasing" text

Posted by Boris_Bee on Fri 12 Oct 2012 03:12 AM — 3 posts, 14,479 views.

#0
I have 1 miniwindow that I am attempted to write text to. I have two functions that draw text to the window, and one of them is working fine. It draws text, and when it's time to change the text it draws a rectangle to "erase" the text, then writes more text on top. The second function does the same thing except this one draws text to the right of the first text area. The problem lies here, as the text is written fine, but the rectangle it draws to cover up the text is draw on top of the text. The text is never seen. I'v fiddled with this for quite a while and I just cannot get it working. Why does my first function work correctly and the second function does not?

function draw_conc (name, line, wildcards, styles)

local left = 0

	for _, v in ipairs (styles) do

		local width = WindowTextWidth (win, "f", v.text)
		local right = left + width
      		WindowRectOp (win, miniwin.rect_fill, left, 0, 344, 0, v.backcolour)  -- draw background
	   	WindowText(win, "f", v.text, left, 3, 0, 0, v.textcolour, false)
		left = left + width
	end -- for each style run
	WindowShow(win, true)
end

function draw_aura (name, line, wildcards, styles)

local left = 344 + 20

	for _, v in ipairs (styles) do

		local width = WindowTextWidth (win, "f", v.text)
		local right = left + width
      		WindowRectOp (win, miniwin.rect_fill, left, 0, 344, 0, ColourNameToRGB("black"))  -- draw background
	   	WindowText(win, "f", v.text, left, 3, 0, 0, v.textcolour, false)
		left = left + width
	end -- for each style run
	WindowShow(win, true)
end
USA Global Moderator #1
FYI, WindowText returns the number of pixels the text took horizontally. By adding that to the "Left" parameter, you can draw some more text to the right of what was just written, so you don't need to keep calling the Width function like you do.

Quote:
Why does my first function work correctly and the second function does not?

"344"
#2
Thanks that solved it, although I'm still not quite sure why heh.