[MaxGUI] How does RedrawGadget() work with Flip()?

BlitzMax Forums/BlitzMax Programming/[MaxGUI] How does RedrawGadget() work with Flip()?

ImaginaryHuman(Posted 2006) [#1]
When you do a Flip() with a canvas, and you have to call RedrawGadget() to get it to be displayed, does that mean that the backbuffer is being copied twice, or does RedrawGadget() do the only copying? What's the point of having a backbuffer if when you flip you don't see anything anyway and have to call RedrawGadget()? Would a single-buffered graphics object be faster? is RedrawGadget() going to produce tearing?


Grisu(Posted 2006) [#2]
RedrawGadget is some kind of windows internal command to tell the system that it needs redrawing. But this does not mean that the system instantly redraws it.

Don't know for the buffer stuff. In general you should not call redrawgadget yourself. It may cause flickering and tearing from my experience, yes.


ImaginaryHuman(Posted 2006) [#3]
I thought you had to call redrawgadget() after calling flip()? That's what the example program for CreateCanvas() does every frame. Also it seemed when I took out the redrawgadget() the flip had no visible effect (ie you never see anything).


TomToad(Posted 2006) [#4]
What ReDrawGadget does is puts an EVENT_GADGETPAINT event in Window's event queue. When Windows is first run, it sends an EVENT_GADGETPAINT to your program so it knows when to draw the canvas. Windows will also send it when the canvas is covered, or minimized, then restored. If your canvas doesn't get obscured at all, then Windows will not send any more EVENT_GADGETPAINT events. If your canvas needs to be updated, like if you're running an animation or something like that, then your program will need to put an EVEN_GADGETPAINT event on the queue itself. It does that through the RedrawGadget() function.
There are a few ways that your program can determine when one needs to be sent. You can send it after the Flip command, so that way your canvas will be redrawn every time through the event loop. Or you can create a timer, and do RedrawGadget() on each tick. Or if there's no animations, you could just simply wait until something actually changes, like a mouse click or a keyhit before calling RedrawGadget().


skidracer(Posted 2006) [#5]

I thought you had to call redrawgadget() after calling flip()? That's what the example program for CreateCanvas() does every frame.


It does no such thing.


ImaginaryHuman(Posted 2006) [#6]
Skid, well it does it the other way around, it calls RedrawGadget() in the TIMERTICK event and then calls Flip, but what I was saying was I personally found this slightly confusing and by the name of the command being "redraw" gadget, it sort of suggests something gets drawn. Thanks for the clarification, though.

How would one go about detecting that the gadgetpaint request came from the o/s and not from out own TIMERTICK trigger? And how can you check if something is minimized/maximized?

TomToad, that's a nice explaination, thanks. I guess I thought RedrawGadget() actually DID some kind of redrawing, but it's more indirect. I can see how it's a good way to have the same piece of code being called for the refreshes rather than duplicating code.

I took out a bunch of unneeded extra Flip() calls - I was doing both Flip() and RedrawGadget(), doh, even though GADGETPAINT was doing a flip as well.

Could you just do a Flip() on each TIMERTICK event though, right, rather than put an event in the queue only to have the code executed under a different event?