RE: [Fxruby-users] hard time using images
Status: Inactive
Brought to you by:
lyle
From: Oliver S. <ol...@mo...> - 2004-07-07 17:59:50
|
Hi, I'll give this a shot... I think what you want is the canvas/dc paradigm. An FXImageView is usually for displaying static image files such as .bmp or .jpg. Since you want to create an image from scratch, the right way to do it is to replace your FXImageView with an FXCanvas and forget about the FXImage for now. It's kind of complicated to explain briefly, but think of an FXDCWindow (which contains an FXDC) as an artist. You give the artist a brush and some paint and a canvas and tell him to draw lines and pixels. So something like this untested code: @canvas = FXCanvas.new(...) @canvas.connect(SEL_PAINT) { FXDCWindow.new(@canvas) { |dc| dc.foreground = "white" dc.fillRectangle(0, 0, @canvas.width, @canvas.height) dc.foreground = "black" dc.drawPoint(20, 20) # draw a pixel } } But it gets more complicated. Note that you should paint on the canvas during the SEL_PAINT handler. This ensures that FOX knows to display the changes on the screen. You can tell FOX to send a new SEL_PAINT message by calling @canvas.update when you need it. Now, while that method works, the problem with drawing on an FXCanvas is that the user can see you draw. So during slow operations the user will see flicker as you update the painting. That's where the FXImage comes in. The FXImage is an off-screen buffer that you can paint on just like an FXCanvas. Look at the bounce.rbw example - it uses the FXCanvas to display the scene to the user, but all actual drawing is done on the FXImage "behind the scenes". When the FXImage has been changed, the program calls @canvas.update. Then, when SEL_PAINT arrives, it uses dc.drawImage to throw the entire FXImage onto the canvas at once. Thus, less chance of flicker. This technique is called 'double buffering'. Actually, bounce.rbw is a great place to start. You can see how it creates the FXImage - first by calling the constructor, but then in SEL_CONFIGURE (sent when the window is created or resized) the buffer is actually created (i.e. memory for it is allocated) and given a size. Drawing to the buffer before it's created may be the source of your crash, although I'm not sure. So, to summarize, you can draw to an FXImage anytime after it's created and sized, but when you're done call @canvas.update and wait for the SEL_PAINT to flip the image onto the FXCanvas the user will see. Or, just draw to the FXCanvas directly from SEL_PAINT if you don't care about flicker or only need to draw once. Read the help for FXDC for a list of drawing methods and operations. Drawing an entire screen of individual pixels is going to be pretty slow, by the way... :| Hope some of this is helpful, Oliver > -----Original Message----- > From: fxr...@li... > [mailto:fxr...@li...]On Behalf Of Andre' > Wagner > Sent: Wednesday, July 07, 2004 10:10 AM > To: fxr...@li... > Subject: Re: [Fxruby-users] hard time using images > > > Thank you so much for the very complete info! However, I still can't > draw :-( So let us speak ruby. I wrote this small class: > > require 'fox' > include Fox > > class Test > > def initialize > app = FXApp.new > main_window = FXMainWindow.new(app, "test", nil, > nil, DECOR_ALL, 500, 330, > 540, 370) > > # Image > image = FXImage.new(app, nil, 0, 30, 30) > imageview = FXImageView.new(main_window, image) > > # Set a pixel > image.setPixel(10, 10, FXRGB(255, 255, 255)) > > app.create > main_window.show > app.run > end > > end > t = Test.new > > When the code gets into the setPixel, I get a segfault. What am I > missing? > > Thank you in advance, > > André > > -- > © Andre' Wagner - 2004 - All rights reserved > > > > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 - > digital self defense, top technical experts, no vendor pitches, > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Fxruby-users mailing list > Fxr...@li... > https://lists.sourceforge.net/lists/listinfo/fxruby-users |