Redraw canvas

BlitzPlus Forums/BlitzPlus Beginners Area/Redraw canvas

Tiger(Posted 2011) [#1]
How do i check when its time to redraw canvas?


Gladclef - Ben B(Posted 2011) [#2]
The way I do it is with a global variable redrawCanvas, as such:

global redrawCanvas = 1
...
if (redrawCanvas)
    drawUpdateCanvas(canvasHandle)
    redrawCanvas = 0
endif
...
function invalidateCanvas()
    redrawCanvas = 1
end function



Tiger(Posted 2011) [#3]
well that I understand, but how do I know that the canvas is trashed by
windows?
Is it any event I can check for when my canvas need to be redrawed?


Yeshu777(Posted 2011) [#4]
Are you asking is if app the focus has changed.?


Tiger(Posted 2011) [#5]
don't know if focus events helps, the problem is that when for some reason the resolution on the screen is changed, or a screen-saver is started all the canvas graphics is trashed. (looks like crap)
I try to use a timer to draw the canvas every 5 sec, it works..almost.
if windows(XP) is logging out the user, it do so at my work where my code is running.. it craps out my timer too.

so, got 2 options... find a event for it, or draw the canvas every frame.


Gladclef - Ben B(Posted 2011) [#6]
I don't know of any commands that can directly tell you if anything has changed on the OS's part (such as screen resolution). What you might be able to do is cache the screen's dimensions as something like desktopWidth/desktopHeight/desktopDepth and then access them every x millisecs with GadgetWidth(Desktop()) to see if they've changed.
As far as a screen saver, I don't even know if windows has any environmental variable that is switched when a screen saver comes on (since screen savers are .exe's renamed to .scr's and moved to system32). For that I guess, like you said, just do a redraw every few seconds.

The other option for the screen saver problem (that I can think of) is finding a list of all screen saver files in system32 and checking their last read times through this api (http://msdn.microsoft.com/en-us/library/aa364946(v=VS.85).aspx).
Now that I take a second look at it, even this is fairly useless since last access times can be accurate to between 1 hour and 1 day. So, my vote says go with the draw every few seconds method, which if the image is cached shouldn't be too CPU intensive.

Sorry if I'm not giving you any ideas you haven't already thought of, or if just really don't want to deal with api's.