[Gambas-user] Best control for a game

Tomas Eroles i Forner tomas.eroles at ...277...
Sat Sep 6 10:13:50 CEST 2008


Ok, it seems to work fine.
I can draw all the board without problems, but I have yet some
questions:

I'm drawing the board after a menu command. If after the drawing the
board I click on Maximize button, the board is erased and I have to draw
it another time. How can I solve that?

Other question: the board is a 15x15 matrix, drawn by rectangles, and I
would like to work with each rectangle, because I would like to paint
some of them depending on their position (it will be stored on a file or
on a database). Is possible to refer to a rectangle after it has been
drawn? That is, may I draw all the rectangles and after that, while
reading a file (or a table) put some colour on them (background property
perhaps)? 

Thanks in advance for your answers, guys


El dv 05 de 09 del 2008 a les 11:59 +0200, en/na Benoit Minisini va
escriure:
> 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,
> 





More information about the User mailing list