Forum: Ruby-Gnome 2 drawing children widgets in a Gtk::Layout

59504b1b262cc1637b52b1c147112b62?d=identicon&s=25 67Daidalos .. (67daidalos_)
on 2013-12-05 16:10
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.
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2013-12-06 13:25
(Received via mailing list)
Hi,

In <df5e62b3b8df787f08b1eaba08c0d543@ruby-forum.com>
  "[ruby-gnome2-devel-en] drawing children widgets in a Gtk::Layout" on
Thu, 05 Dec 2013 16:10:24 +0100,
  "67Daidalos .." <ruby-forum-incoming@andreas-s.net> 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
59504b1b262cc1637b52b1c147112b62?d=identicon&s=25 67Daidalos .. (67daidalos_)
on 2013-12-06 15:59
Attachment: essai2.0.rb (5 KB)
Attachment: 001-Fighter01.png (8 KB)
Attachment: 002-Fighter02.png (6 KB)
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
Ee6ffca720cc428d70247dcd7377dd48?d=identicon&s=25 Kouhei Sutou (Guest)
on 2013-12-07 04:16
(Received via mailing list)
Hi,

In <b4b6df73a855a2cd9c4a844bac6d5c96@ruby-forum.com>
  "Re: [ruby-gnome2-devel-en] drawing children widgets in a Gtk::Layout"
on Fri, 06 Dec 2013 15:59:19 +0100,
  "67Daidalos .." <ruby-forum-incoming@andreas-s.net> 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.ht...

--- 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
59504b1b262cc1637b52b1c147112b62?d=identicon&s=25 67Daidalos .. (67daidalos_)
on 2013-12-07 21:53
Thank you Kou-san, I didn't knew about the return value for signals.

Kouhei Sutou 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.
D9ba13de4e62fcabffa4403731434e42?d=identicon&s=25 Eric C. (eric_c65)
on 2013-12-10 20:01
Can you post the fixed, working version of your program?

It looks like it works to me.

Thanks,
Eric
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.