[Gambas-user] Best control for a game
Benoit Minisini
gambas at ...1...
Fri Sep 5 11:59:03 CEST 2008
On vendredi 05 septembre 2008, Doriano Blengino wrote:
> 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,
You cannot draw directly on a DrawingArea if it is not cached (even if it
actually allowed at the moment).
Drawing must be done inside the Draw event only.
If you need to refresh the DrawingArea, you must call its Refresh() method.
When the DrawingArea is cached, it maintain a pixmap cache (like a Picture
object), so you can draw inside it whenever you want.
Regards,
--
Benoit Minisini
More information about the User
mailing list