[Gambas-user] Best control for a game

Doriano Blengino doriano.blengino at ...1909...
Fri Sep 5 08:01:39 CEST 2008


Werner ha scritto:
> Tomas Eroles i Forner wrote:
>   
>> commands in a Draw.Begin(DrawingArea)...Draw.End group of code.
>>
>> It seems to work, but, I see that you can start drawing if you put a
>> command button, or a menu or something like this, but it does not work
>> in a Form_Open event.
>>
>> Is it like this?
>>     
> However, it is much more practical to use the drawing area's draw event
> http://gambasdoc.org/help/comp/gb.qt/drawingarea/.draw
>
> because it will also deal with needs to redraw that come from outside the application i.e.other applications' windows that were partially overlapping. Have a look at the "Analog Watch" example.
>   
Werner is right but, perhaps, you can still get what you want if you set 
the "Cached" property of the DrawingArea.
By setting that property, the DrawingArea repaints automatically itself 
when needed; whether to go this way or the other depends on several 
factors: dimension of the drawing, complexity of the drawing, complexity 
of the code needed to remember what to draw...

I suppose that the main difference between the two methods is this. If 
you use the Cached property, your code can update the drawing when it 
wants; the result is a cached bitmap that can consume a lot of memory, 
but still is a simple bitmap. This is the easiest way. If you don't use 
the Cached property, your code to update the drawing is called every 
time the DrawingArea "unveals". If this code is fast, then this method 
is better. However, this second method is a little more complicated to 
understand: when the program, asynchronously, wants to change the 
appearance, it can Draw() directly, but it must also remember the 
sequence of operations needed to refresh the entire drawing, so a double 
job is needed. And this is the harder way...

Cheers,
Doriano Blengino





More information about the User mailing list