WindowResize causing flicker

Posted by Apriebe on Sun 18 Sep 2011 11:04 AM — 7 posts, 23,323 views.

#0
Hi everyone,

My MUD recently implemented MSDP so I have been fiddling around with miniwindows over the past few weeks. I have encountered some strange behavior in one of my plugins using the 'WindowResize' function. The plugin's job is basically t show spell timers counting down using the MSDP information from the MUD. The problem occurs whenever my character becomes affected by a spell or whenever the spell wears off, thus the change in window size. If I comment out the call to WindowResize, the flicker disappears. (When I say flicker, I mean the entire window disappears for about ~1 second).

If someone could take a look at the draw function and let me know if they spot any problems, it would be much appreciated!


function draw_affect_timers()
	if is_dragging == true then return else end						
	
	local title_width = WindowText(win,
									default_font,
									"[AffectTimers]",
									padding,
									padding,
									125,
									default_font_height+padding,
									ColourNameToRGB("blue"),
									false)
	WindowAddHotspot(win,
						"drag_hotspot",
						padding,
						padding,
						title_width+padding,
						default_font_height+padding,
						"",
						"",
						"", -- mousedown
						"",
						"",
						"",
						miniwin.cursor_hand,
						0)
	-- add a window drag handler so the window can be moved
	WindowDragHandler(win,
						"drag_hotspot",
						"window_move",
						"window_release",
						0)
						
	WindowRectOp(win, 
					miniwin.rect_fill,
					padding,
					(default_font_height * 2),
					window_width,
					WindowInfo(win, 4),
					ColourNameToRGB("black"))
	WindowRectOp(win,
					miniwin.rect_frame,
					0,
					0,
					0,
					0,
					ColourNameToRGB("gray"))
				
	local line_count = 2
	for k,v in orderedPairs(affect_name) do
		local timer_string = affect_timer[k]
		while string.len(timer_string) < 4 do
			timer_string = string.gsub(timer_string, "([%d]+)", " %1")
		end
		local duration = table.concat({"(", timer_string, ")"}, "")

		local offset = WindowText(win,
									default_font,
									duration,
									padding,
									(default_font_height * line_count),
									window_width,
									(default_font_height * line_count) + default_font_height,
									ColourNameToRGB("yellow"),
									false)
		if offset < 60 then
			offset = 60
		else end
		
		local spell_name_color
		local spell_name_font
		if tonumber(affect_timer[k]) <= timer_warning and tonumber(affect_timer[k]) > timer_critical then
			spell_name_color = "gray"
			spell_name_font = warning_font
		elseif tonumber(affect_timer[k]) <= timer_critical then
			spell_name_color = "gray"
			spell_name_font = critical_font
		else
			spell_name_color = "white"
			spell_name_font = default_font
		end
		WindowText(win,
					spell_name_font,
					v,
					offset,
					(default_font_height * line_count),
					window_width,
					(default_font_height * line_count) + default_font_height,
					ColourNameToRGB(spell_name_color),
					false)
		line_count = line_count + 1
	end
	WindowResize(win,
					window_width,
					tonumber((default_font_height * line_count-1) + padding),
					ColourNameToRGB("black"))

	WindowShow(win, true)
end -- function

--- and below is the last part of my 'OnTelnetSubnegotiation'

local msdp_affects = msdp["AFFECTS"]
	if not msdp_affects then return end
	update_affects(msdp_affects)
	draw_affect_timers()
#1
I should also note that I am using MUSHclient 4.73 and that I cannot repeat this behavior on my other plugins that use WindowResize, which is to say that using that function in my other plugins does not result in any noticeable flicker.
Australia Forum Administrator #2
Can you clarify, when you say the window "disappears" do you mean it is replaced by whatever is underneath it, or it becomes some solid colour, such as black?
#3
The window goes entirely black, however I just changed my the colour value passed to WindowResize to white, and now whenever I become affected by a spell or a spell wears off, the entire miniwindow goes white until the text is drawn again.

Thanks for the quick response!
Australia Forum Administrator #4
Without checking your code in detail, you might want to resize first, and then draw stuff (like rectangles etc.).
Australia Forum Administrator #5
Drawing is clipped to the output window size. Resizing last is too late.
#6
I've moved the WindowResize call to the beginning of the function and that fixes the flicker. Thanks for the help Nick!