[fxruby-users] (no subject)

Sander Jansen sander at knology.net
Wed Jun 8 00:13:03 EDT 2005

here are some pointers, since I just wrote a liitle chessboard/tile engine 
myself (note I did it in C++, so it may be a little bit different from Ruby, 
so Lyle, if you have any notes,  please do so now)...:

- First of all, probably handiest if you create your own widget instead of 
using FXCanvas., so  either derive from 

	a) FXScrollArea, if widget needs scroll capability
	b) FXFrame, if the widget doesn't need to scroll but needs a optional border

	c) FXWindow: no border, no scrolling

Also for the widget itself:

	 - override getDefaultWidth and getDefaultHeight: this sets the minimal size 
of the widget

	- Since the widget needs to receive mouse events and want it visible right 
away, you need to set the following flags in the constructor:


	- implement SEL_PAINT message: this will paint your widget. Make sure you 
only draw what is needed. Besides setting the clip rectangle in the FXDC, 
also only draw things that are currently dirty. The less drawing commands you 
send, the faster it is. You can also do double buffering. One optimized way 
of doing this (in case of a tile engine) is to double buffer one tile at a 
time. Basically draw one tile in the backbuffer, then blit the tile to the 
widget. This is memory efficient and also you can take advantage of the 
FXScrollArea's optimized scroll code.

	- you probably want catch the raw mouse messages in your widget yourself and 
send a processed messages to the target of the widget. Ie. the widgets 
determines which field was pressed and send the target this information.

- if you need to refresh the widget, make sure you know which area is affected 
and call "update(x,y,w,h)" instead of "update()".  "update()" will mark  the 
whole widget for repainting while "update(x,y,w,h)" only the affected area. 

So in essence: Drawing is expensive. Even more expensive than calculating what 
needs to be drawn.

Hope this helps,


On Tuesday 07 June 2005 19:31, brotman at excite.com wrote:
> Hello,
> Oops, last note was inadvertantly sent as html.. sorry, resending plaintext
> My name is chuck and I’m trying to get up to speed on ruby/fxruby.  For my
> first project I want to write a simple “board game”.  I’ll need to output 
> a simple 2d drawing,  a 4x4 square of 1x1quares. On top of thiis I’ll need
> to draw filled circles, or maybe place a bitmap image, to represent pieces.
> For input, mostly mouse actions, but I’ll defer that to later.  I’m afraid
> I really don’t know where to start, I’ll appreciate any guidance pointing
> me in the right direction.
> Thanks,
> Chuck Brotman
> Brotman at excite.com
> _______________________________________________
> Join Excite! - http://www.excite.com
> The most personalized portal on the Web!
> _______________________________________________
> fxruby-users mailing list
> fxruby-users at rubyforge.org
> http://rubyforge.org/mailman/listinfo/fxruby-users

More information about the fxruby-users mailing list