Thread: [Fxruby-users] hard time using images
Status: Inactive
Brought to you by:
lyle
From: Andre' W. <an...@sy...> - 2004-07-07 14:06:46
|
Hello folks, I think I'm failing to understand how do I manipulate a image widget in my application. I putted the FXImage in my app - and it appears ok - but if I try to setPixel in it then I get a segfault. I peeked into the examples, and I see they use a FXDCWindow and a FXCanvas, but I can't understand it very well. I looked into the tutorial and the docs but I haven't found anything that cleared my mind. Is there a image tutorial for FXRuby or something like that on the net? Or might someone give me a few pointers here? Thank you in advance, Andr=E9 --=20 =A9 Andre' Wagner - 2004 - All rights reserved |
From: rich l. <fx...@gm...> - 2004-07-07 14:36:28
|
Are you wanting to draw an image (graph, chart) or import and manipulate an image (bmp, jpg)? -Rich On Wed, 7 Jul 2004 11:08:50 -0300, Andre' Wagner <an...@sy...> wr= ote: > Hello folks, >=20 > I think I'm failing to understand how do I manipulate a image widget > in my application. I putted the FXImage in my app - and it appears ok > - but if I try to setPixel in it then I get a segfault. >=20 > I peeked into the examples, and I see they use a FXDCWindow and a > FXCanvas, but I can't understand it very well. I looked into the > tutorial and the docs but I haven't found anything that cleared my > mind. >=20 > Is there a image tutorial for FXRuby or something like that on the > net? Or might someone give me a few pointers here? >=20 > Thank you in advance, >=20 > Andr=E9 >=20 > -- > =A9 Andre' Wagner - 2004 - All rights reserved >=20 > ------------------------------------------------------- > 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 > |
From: Andre' W. <an...@sy...> - 2004-07-07 14:43:32
|
I'm writing a emulator, so basicly what I'm gonna do is draw single pixels in a image. (as fast as possible) Andr=E9 In Wednesday, July 7, 2004 you wrote: > Are you wanting to draw an image (graph, chart) or import and > manipulate an image (bmp, jpg)? > -Rich > On Wed, 7 Jul 2004 11:08:50 -0300, Andre' Wagner <an...@sy...= > wrote: >> Hello folks, >>=20 >> I think I'm failing to understand how do I manipulate a image widget >> in my application. I putted the FXImage in my app - and it appears ok >> - but if I try to setPixel in it then I get a segfault. >>=20 >> I peeked into the examples, and I see they use a FXDCWindow and a >> FXCanvas, but I can't understand it very well. I looked into the >> tutorial and the docs but I haven't found anything that cleared my >> mind. >>=20 >> Is there a image tutorial for FXRuby or something like that on the >> net? Or might someone give me a few pointers here? >>=20 >> Thank you in advance, >>=20 >> Andr=E9 >>=20 >> -- >> =A9 Andre' Wagner - 2004 - All rights reserved >>=20 >> ------------------------------------------------------- >> 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 >> > ------------------------------------------------------- > This SF.Net email sponsored by Black Hat Briefings & Training. > Attend Black Hat Briefings & Training, Las Vegas July 24-29 -=20 > digital self defense, top technical experts, no vendor pitches,=20 > unmatched networking opportunities. Visit www.blackhat.com > _______________________________________________ > Fxruby-users mailing list > Fxr...@li... > https://lists.sourceforge.net/lists/listinfo/fxruby-users --=20 =A9 Andre' Wagner - 2004 - All rights reserved |
From: rich l. <fx...@gm...> - 2004-07-07 15:04:00
|
I'd use FXGLCanvas - but I really don't have experience with anything else. I've used FXGLViewer I think... and that wasn't that bad... If you're looking for a tutorial, I might be able to write one for you on FXGLCanvas... At: http://fox-toolkit.net/cgi-bin/wiki.pl?Documentation there is a link: [Developing GUIs with FOX and Ruby] That has a bit of a tutorial on FXGLCanvas I think... -Rich On Wed, 7 Jul 2004 11:45:35 -0300, Andre' Wagner <an...@sy...> wr= ote: > I'm writing a emulator, so basicly what I'm gonna do is draw single > pixels in a image. (as fast as possible) >=20 > Andr=E9 >=20 >=20 >=20 > In Wednesday, July 7, 2004 you wrote: >=20 > > Are you wanting to draw an image (graph, chart) or import and > > manipulate an image (bmp, jpg)? >=20 > > -Rich >=20 > > On Wed, 7 Jul 2004 11:08:50 -0300, Andre' Wagner <an...@sy...= > wrote: > >> Hello folks, > >> > >> I think I'm failing to understand how do I manipulate a image widget > >> in my application. I putted the FXImage in my app - and it appears ok > >> - but if I try to setPixel in it then I get a segfault. > >> > >> I peeked into the examples, and I see they use a FXDCWindow and a > >> FXCanvas, but I can't understand it very well. I looked into the > >> tutorial and the docs but I haven't found anything that cleared my > >> mind. > >> > >> Is there a image tutorial for FXRuby or something like that on the > >> net? Or might someone give me a few pointers here? > >> > >> Thank you in advance, > >> > >> Andr=E9 > >> > >> -- > >> =A9 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 > >> >=20 > > ------------------------------------------------------- > > 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 >=20 > -- > =A9 Andre' Wagner - 2004 - All rights reserved >=20 > ------------------------------------------------------- > 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 > |
From: Jeroen v. d. Z. <je...@fo...> - 2004-07-07 14:37:22
|
On Wednesday 07 July 2004 10:08 am, Andre' Wagner wrote: > Hello folks, > > I think I'm failing to understand how do I manipulate a image widget > in my application. I putted the FXImage in my app - and it appears ok > - but if I try to setPixel in it then I get a segfault. > > I peeked into the examples, and I see they use a FXDCWindow and a > FXCanvas, but I can't understand it very well. I looked into the > tutorial and the docs but I haven't found anything that cleared my > mind. > > Is there a image tutorial for FXRuby or something like that on the > net? Or might someone give me a few pointers here? > > Thank you in advance, > > Andr=E9 The think to keep in mind is that there's two sides to FXImage: the array of pixels which is kept in your program and the device-specific bitmap which is kept in the display server. Now, to keep memory down, by default FXImage ditches the pixel array in the program, since USING the image in drawing operations normally requires only the bitmap in the display server. Of course, sometimes you need the local pixel array, and there's a way to hang on to that, by passing the IMAGE_KEEP option. Also, there is a way to regenerate the server-side bitmap from the local pixel array, which you can do by calling render(). Finally, since you can use drawing commands to draw things into the bitmap that is kept in the server, you can read back the bitmap into the local image pixel array by calling restore(). The API setPixel() works on the local image pixel array, and you must make sure that the pixel array is kept around for that to work properly. Note also that the local pixel array is only deleted after the server-side bitmap has been populated, which means basically that prior to create() you still have full access to the local pixel array. Hope this helps, - Jeroen |
From: Andre' W. <an...@sy...> - 2004-07-07 17:08:28
|
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 =3D FXApp.new main_window =3D FXMainWindow.new(app, "test", nil, nil, D= ECOR_ALL, 500, 330, 540, 370) # Image image =3D FXImage.new(app, nil, 0, 30, 30) imageview =3D FXImageView.new(main_window, image) # Set a pixel image.setPixel(10, 10, FXRGB(255, 255, 255)) =20 app.create main_window.show app.run end end t =3D Test.new When the code gets into the setPixel, I get a segfault. What am I missing? Thank you in advance, Andr=E9 --=20 =A9 Andre' Wagner - 2004 - All rights reserved |
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 |
From: Andre' W. <an...@sy...> - 2004-07-07 20:59:08
|
Thank you so much for everyone's help, I couldn't do without you! Someday someone has to write a tutorial on that. (maybe I will, if ever got some experience) So here is my final code. Any hints on optimization would be appreciated. require 'fox' include Fox class Test def initialize app =3D FXApp.new main_window =3D FXMainWindow.new(app, "test", nil, nil, D= ECOR_ALL, 500, 330, 540, 370) # Canvas & image canvas =3D FXCanvas.new(main_window, nil, 0, LAYOUT_FIX_W= IDTH|LAYOUT_FIX_HEIGHT, 0, 0, 30, 30) @buffer =3D FXImage.new(app, nil, IMAGE_KEEP) @buffer.create canvas.connect(SEL_PAINT) { |sender, sel, evt|=20 FXDCWindow.new(sender, evt) { |dc| dc.drawImage(@buffer, 0, 0) } } canvas.connect(SEL_CONFIGURE) { |sender, sel, evt| @buffer.create unless @buffer.created? @buffer.resize(sender.width, sender.height) draw } app.create main_window.show # sets the pixel setPixel(10, 10, FXRGB(0,0,0)) =20 app.run =20 end def draw FXDCWindow.new(@buffer) { |dc| dc.setForeground(FXRGB(255, 255, 255)) dc.fillRectangle(0, 0, @buffer.width, @buffer.hei= ght) } end def setPixel(x, y, color) FXDCWindow.new(@buffer) { |dc| dc.foreground =3D color dc.drawPoint(x, y) } end end t =3D Test.new Regards to all, Andr=E9 --=20 =A9 Andre' Wagner - 2004 - All rights reserved |