Why do my gadgets redraw slowly?

BlitzMax Forums/MaxGUI Module/Why do my gadgets redraw slowly?

sswift(Posted 2009) [#1]
I have around 26 sliders/textboxes down one side of my window, and when I minimize and then restore I can actually see it redrawing the checkboxes first, and then the sliders. It takes around half a second to do this.

Why would it even draw the textboxes first anyway? Shouldn't gadgets be drawn in the order they are created? I didn't create all the textboxes first. I created one with each slider.

Also, on a related note, why are my sliders not being redrawn until I stop moving the mouse when I'm resizing the window? The regular sliders are redrawn.

Here's my code:




sswift(Posted 2009) [#2]
Okay I've noticed that if I remove the event hook that redraws the canvas when the gadgetpaint event is triggered, that things speed up quite a bit. It's still not instant though, and I still get the sliders not redrawing when I am resizing the window.


Grisu(Posted 2009) [#3]
You could place all your sliders etc on a panel and hide it when you're are resizing / maximising the window. Doesn't look great, but it should be faster.

Also, you could try to disable "double buffering" (not sure what the exact command was) for MaxGUI.


SebHoll(Posted 2009) [#4]
Also, you could try to disable "double buffering" (not sure what the exact command was) for MaxGUI.

Double buffering should be disabled automatically as soon as a canvas is created, or if you are Windows XP or lower.

I'll have a look into this for you. This is definitely redrawing quite slowly, and I'm guessing this is due to all the transparency hacks needed to get sliders to show their background panel's color/images properly.

The problem is that group panels, sliders and buttons all recreate new GDI brushes from their parents every time they are drawn, and the particular combination of them you are using is highlighting this overhead.

As I say, I'll look into this for you and post back. ;-)


SebHoll(Posted 2009) [#5]
Cool! Right, I think I've managed to optimise this a little. If you could try it out, and let me know, that would be awesome.

SSwift Sample

Also, I saw the following line was commmented out in your EVENT_GADGETPAINT handler:
'RedrawGadget CANVAS_Preview
I know it's commented out, but I just wanted to point out that this is likely to cause an infinite loop of redraws.

Finally, in answer to your inline comment:

BUG? Is 0 the first index of tabber gadget, or 1?

All item based gadgets are base '0' - i.e. the first item has index '0'.


Grisu(Posted 2009) [#6]
The sample works fine here on Win 7.


sswift(Posted 2009) [#7]
Seb:
The new version is much faster. What did you change?


I know it's commented out, but I just wanted to point out that this is likely to cause an infinite loop of redraws.


Yeah, I figured as much. I was working with some example code I didn't really understand. That's gone now. I only redraw the canvas once after it's been created, (because otherwise it's left filled with garbage) and the rest of the updates for it occur only on the gadgetpaint event like so:

			Case EVENT_GADGETPAINT 
			
				SetGraphics CanvasGraphics(CANVAS_Preview)
				SetViewport 0, 0, GadgetWidth(CANVAS_Preview), GadgetHeight(CANVAS_Preview)
				Cls
				Flip 0
				
				Return Null



Not sure why gadgetpaint doesn't occur when the canvas is first created. Maybe it has something to do with my code to hide the window until all the gadgets are created... code which I had added to try to make the app seem faster.



All item based gadgets are base '0' - i.e. the first item has index '0'.



Thanks. :-)


SebHoll(Posted 2009) [#8]
What did you change?

Hehe! I didn't think you'd want to know, but it basically involved caching system brushes so they don't have to be recreated every time the gadgets are redrawn. Rest assured that this will be implemented in the next MaxGUI release.

Not sure why gadgetpaint doesn't occur when the canvas is first created.

I'm guessing this is because you only set-up your event hook after you initialize all the gadgets, and so there is nothing to handle the EVENT_GADGETPAINT message when it is first created and drawn by the system.

This is hard to handle properly, as at the moment the gadget is created the reference hasn't even been returned and stored in your global variable. The method you're using (i.e. calling RedrawGadget()) after the event hook is set-up is what I use, works perfectly, and avoids all the headache. ;-)


SebHoll(Posted 2009) [#9]
sswift:

Does MaxGUI v1.34 improve redrawing speed for you?


sswift(Posted 2009) [#10]
I just installed MaxGUI 1.34 and it is redrawing a lot faster now. Thanks!


SebHoll(Posted 2009) [#11]
No problem. Glad it's fixed. :-)