[fxruby-users] newbe questions

brotman at excite.com brotman at excite.com
Wed Jun 8 10:52:39 EDT 2005


 



Sander, Thanks for your reply!  I'm sure the info will prove useful.   Assuming I follow your advice re classes, etc.  Where would I find the approprate messages to send to do the actual drawing.  I'm thinking of things like draw_circle, draw square, etc.  I'm looking for documentaion this minute more than anything.  Would you be willing to send me the source code for your chess program (or just the graphics related part, anyway)??  Anyone out there done something like this in FXruby?Thanks again,Chuck --- On Wed 06/08, Sander Jansen < sander at knology.net > wrote:
From: Sander Jansen [mailto: sander at knology.net]To: brotman at excite.com, fxruby-users at rubyforge.orgDate: Tue, 7 Jun 2005 21:13:03 -0700Subject: Re: [fxruby-users] (no subject)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 capabilityb) FXFrame, if the widget doesn't need to scroll but needs a optional borderc) FXWindow: no border, no scrollingAlso 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:FLAG_ENABLED, FLAG_SHOWN- 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,SanderOn 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

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/fxruby-users/attachments/20050608/6382ce06/attachment-0001.htm


More information about the fxruby-users mailing list