Drawing children widgets in a Gtk::Layout

Hello ! I’m dealing with a problem that I can’t find any solution on the
net.
I got a Gtk::Layout where I load multiples Gtk::Image created with .png
images files.
I stock each of those Image in a Gtk::EventBox to capture mouse clicks
and drag them everywhere on the Layout, and use
event_box.set_visble_window(false) cause I need the background of images
to be transparent.
Until there, all works fine. The problems comes when I want to implement
a system of rubberbanding selection of the images. As soon as I use
Cairo to draw my dashed rectangle unvisible windowed images aren’t drawn
anymore (although, there are if i set their window visible, but that’s
not what I want). I assume I have to add in my ‘draw’ method line(s)
that tell the program to (re)draw children widget of the layout. But I
can’t find in the documentation (even in other languages than Ruby) how
to achieve that.

Can someone help me, please ?

NB : I’m using cairo1.12.6, gtk2-2.0.2 and Ruby1.9.3 on Windows7 if that
could be of some help

EDIT : Found a way to achieve that :
while dealing with the expose_event of the layout, I used
img.event_box.send_expose(event) to propagate the expose_event.
That works quite well.
Next step, would be to show when an Image is selected. For that, i
implement two methods select and unselect to switch the visibility of
their even_box.window.
I then get another problem, not really important but still…; When the
rubberband selection rectangle moves fast in and out of images, it
causes sometimes a little glitch where the image is visible in the
upper-left corner of the Gtk::Layout instead of its x, y position for a
fraction of second.

So if someone can figure a way to improve that, it will be great.

Hi,

In [email protected]
“[ruby-gnome2-devel-en] drawing children widgets in a Gtk::Layout” on
Thu, 05 Dec 2013 16:10:24 +0100,
“67Daidalos …” [email protected] wrote:

Cairo to draw my dashed rectangle unvisible windowed images aren’t drawn
anymore (although, there are if i set their window visible, but that’s
not what I want). I assume I have to add in my ‘draw’ method line(s)
that tell the program to (re)draw children widget of the layout. But I
can’t find in the documentation (even in other languages than Ruby) how
to achieve that.

Can someone help me, please ?

Could you show a sample program that can be ran by us? If
you provide it, we can try to tackle your problem easily. :slight_smile:

Thanks,

kou

Here you have a sample program showing the problem, and two PNG I used
to do this little test.

I commented the main aspects, especially those related to the two
problem I mentioned above.
If you run it and move the rubberband fast in and out of the two images,
you should occasionnaly see them appear for a split second in the
upper-left corner of the layout

Hi,

In [email protected]
“Re: [ruby-gnome2-devel-en] drawing children widgets in a Gtk::Layout”
on Fri, 06 Dec 2013 15:59:19 +0100,
“67Daidalos …” [email protected] wrote:

Here you have a sample program showing the problem, and two PNG I used
to do this little test.

Thanks!

You don’t need to call send_expose. You just return “false”
from expose-event callback. If you don’t return not “false”
value, other expose callbacks are not called. They will be
have image draw callbacks.

See also:
https://developer.gnome.org/gtk2/2.24/GtkWidget.html#GtkWidget-expose-event

— essai2.0.rb.orig 2013-12-06 23:52:54.000000000 +0900
+++ essai2.0.rb 2013-12-07 12:11:49.902475686 +0900
@@ -146,14 +146,14 @@
cr = widget.bin_window.create_cairo_context
draw(cr, widget, select_rect)
[@spr1, @spr2].each do |spr|

  • spr.e_box.send_expose(event) #before posting yesterday, I didn’t
    have thought to add this line… as people say, sleep on first ! That
    resolve
  •                # the visibility problem I had.
    
    if select_rect.intersect(spr.rectangle)
    spr.select
    else
    spr.unselect
    end
    end
  • stop_propagation = false
  • stop_propagation
    end

scwin = ScrolledWindow.new

I commented the main aspects, especially those related to the two
problem I mentioned above.
If you run it and move the rubberband fast in and out of the two images,
you should occasionnaly see them appear for a split second in the
upper-left corner of the layout

It is reproduced on my environment too.
Umm, why…

Thanks,

kou

Can you post the fixed, working version of your program?

It looks like it works to me.

Thanks,
Eric

Thank you Kou-san, I didn’t knew about the return value for signals.

Kouhei S. wrote in post #1129960:

I commented the main aspects, especially those related to the two
problem I mentioned above.
If you run it and move the rubberband fast in and out of the two images,
you should occasionnaly see them appear for a split second in the
upper-left corner of the layout

It is reproduced on my environment too.
Umm, why…

I thought I have a beginning of explanation. As I tried to start
dragging a rubberbanding rectangle from inside one of the images, I saw
it draws on the upper-left corner too… I assume the events that
occurs in EventBoxes are passed somehow to the parent container (i.e.
the Gtk::Layout) but with coordinates relative to the EventBox.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs