FXRuby: how do you capture a canvas resize?

Hi,
I’m building a small drawing application by hacking the Scribble example
included in FXRuby. But I can’t seem to figure out how you can respond to
resize events. Basically, whenever the window is resized (and therefore the
drawing canvas on it) I want to know about it, so I can store the canvas’s
new size in pixels.

Thanks,
Paul

Paul E.C. Melis wrote:

I’m building a small drawing application by hacking the Scribble example
included in FXRuby. But I can’t seem to figure out how you can respond to
resize events. Basically, whenever the window is resized (and therefore the
drawing canvas on it) I want to know about it, so I can store the canvas’s
new size in pixels.

You want to catch the SEL_CONFIGURE message:

 @canvas.connect(SEL_CONFIGURE) do |sender, sel, evt|
   puts "New canvas size: #{sender.width} x #{sender.height} pixels"
 end

Hope this helps,

Lyle

“Lyle Johnson” lyle@users.sourceforge.net wrote in message
news:3D481D18.1020402@users.sourceforge.net

Paul E.C. Melis wrote:

resize events. Basically, whenever the window is resized (and therefore
the

drawing canvas on it) I want to know about it, so I can store the
canvas’s

new size in pixels.

You want to catch the SEL_CONFIGURE message:

 @canvas.connect(SEL_CONFIGURE) do |sender, sel, evt|
   puts "New canvas size: #{sender.width} x #{sender.height} pixels"
 end

Hope this helps,

Almost perfect, except that after starting up (before doing any resizing
myself) the size reported is 1x1 pixel. Any way to get the initial size?

Paul

Paul E.C. Melis wrote:

Almost perfect, except that after starting up (before doing any resizing
myself) the size reported is 1x1 pixel. Any way to get the initial size?

If I add the lines I showed in my previous e-mail (i.e. catching the
SEL_CONFIGURE message from the FXCanvas widget) and then run
scribble.rb, it reports the correct initial size; it prints exactly one
message to the console (“New canvas size: 667 x 550 pixels”). I am
currently testing this under Linux and so I guess it’s possible that the
behavior is inconsistent under Windows. Which OS are you running? If
you’re running Linux too, could you maybe send me a copy of your program
to see if I can reproduce the results here?

“Lyle Johnson” lyle@users.sourceforge.net wrote in message
news:3D484A97.9020804@users.sourceforge.net

Paul E.C. Melis wrote:

Almost perfect, except that after starting up (before doing any resizing
myself) the size reported is 1x1 pixel. Any way to get the initial size?

If I add the lines I showed in my previous e-mail (i.e. catching the
SEL_CONFIGURE message from the FXCanvas widget) and then run
scribble.rb, it reports the correct initial size; it prints exactly one
message to the console (“New canvas size: 667 x 550 pixels”). I am
currently testing this under Linux and so I guess it’s possible that the
behavior is inconsistent under Windows.

Did the same here on windows, it looks like it is a windows-only quirk: I
get four times that line, saying the canvas is 1x1 pixel…

Paul

“Paul E.C. Melis” paul@floorball.nl wrote in message
news:ai9i7h$qpp$1@ares.cs.utwente.nl

Did the same here on windows, it looks like it is a windows-only quirk: I
get four times that line, saying the canvas is 1x1 pixel…

OK, I’m seeing the same behavior here under Windows. Looks like you might
want to use a combination of the following:

To get the initial canvas size, record the values for @canvas.width and
@canvas.height after you’ve called FXCanvas#create but before actually
entering the main event loop. For the scribble application, you’d want to
add some lines to ScribbleWindow#create (which indirectly causes
FXCanvas#create to be called):

class ScribbleWindow < FXMainWindow
    def create
        super
        show(PLACEMENT_SCREEN)
        @canvasWidth = @canvas.width
        @canvasHeight = @canvas.height
    end
end

This is in addition to the event handler you added earlier, to catch
SEL_CONFIGURE messages sent from the canvas:

@canvas.connect(SEL_CONFIGURE) do |sender, sel, evt|
    if @canvas.width > 1 && @canvas.height > 1
        @canvasWidth = @canvas.width
        @canvasHeight = @canvas.height
    end
end

Note the added check on reported canvas width and height, to avoid the bogus
values you were getting before the window has actually been realized
onscreen.

Hope this helps,

Lyle

“Lyle Johnson” lyle@knology.net wrote in message
news:ukh590eoh2jj18@corp.supernews.com

“Paul E.C. Melis” paul@floorball.nl wrote in message
news:ai9i7h$qpp$1@ares.cs.utwente.nl

Did the same here on windows, it looks like it is a windows-only quirk:
I

get four times that line, saying the canvas is 1x1 pixel…

OK, I’m seeing the same behavior here under Windows. Looks like you might
want to use a combination of the following:
[…]
Hope this helps,

Excellent, that worked, thanks!

Paul