# Drawing children widgets in a Gtk::Layout

**URL:** <https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906>\
**Category:** Ruby-Gnome 2\
**Created:** [December 5, 2013, 4:10pm UTC](https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906 "2013-12-05T16:10:24Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![musicdenotation](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/ea666f/32.png) [@musicdenotation](https://www.ruby-forum.com/u/musicdenotation)\
**Post date:** [December 5, 2013, 4:10pm UTC](https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906/1 "2013-12-05T16:10:24Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![67daidalos\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/6/7ba0ec/32.png) [@67daidalos\_S](https://www.ruby-forum.com/u/67daidalos_S)\
**Post date:** [December 6, 2013, 1:25pm UTC](https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906/2 "2013-12-06T13:25:11Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“[ruby-gnome2-devel-en] drawing children widgets in a Gtk::Layout” on  
Thu, 05 Dec 2013 16:10:24 +0100,  
“67Daidalos ..” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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. 🙂

## Thanks,

kou

---

<div class="post-metadata">

**Author:** ![67daidalos\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/6/7ba0ec/32.png) [@67daidalos\_S](https://www.ruby-forum.com/u/67daidalos_S)\
**Post date:** [December 6, 2013, 3:59pm UTC](https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906/3 "2013-12-06T15:59:19Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![67daidalos\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/6/7ba0ec/32.png) [@67daidalos\_S](https://www.ruby-forum.com/u/67daidalos_S)\
**Post date:** [December 7, 2013, 4:16am UTC](https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906/4 "2013-12-07T04:16:11Z")

</div>

Hi,

In [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
“Re: [ruby-gnome2-devel-en] drawing children widgets in a Gtk::Layout”  
on Fri, 06 Dec 2013 15:59:19 +0100,  
“67Daidalos ..” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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](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

---

<div class="post-metadata">

**Author:** ![67daidalos\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/6/7ba0ec/32.png) [@67daidalos\_S](https://www.ruby-forum.com/u/67daidalos_S)\
**Post date:** [December 10, 2013, 8:01pm UTC](https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906/5 "2013-12-10T20:01:01Z")

</div>

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

It looks like it works to me.

Thanks,  
Eric

---

<div class="post-metadata">

**Author:** ![67daidalos\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/6/7ba0ec/32.png) [@67daidalos\_S](https://www.ruby-forum.com/u/67daidalos_S)\
**Post date:** [December 7, 2013, 9:53pm UTC](https://www.ruby-forum.com/t/drawing-children-widgets-in-a-gtk-layout/237906/6 "2013-12-07T21:53:03Z")

</div>

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.
