Forum: Ruby-Gnome 2 gtk2/cairo transparency question

7f28f9db46bfe8e9b8b5fcd90b2f1302?d=identicon&s=25 J. K. (j_k)
on 2011-02-13 05:30
hello folks -
  so i'm out of one problem and into another...  first, thanks for
replies to the last post, second -
  i've got a Gtk::Layout, in which i put a background image, and a
Gtk::EventBox with a DrawingArea inside it.  in the DrawingArea, i
create a cairo context to draw (and redraw) a Pixbuf rotated relative to
the time.  thanks (again) to help from this forum, i've got everything
working alright, but i can't seem to make the EventBox (or maybe the
DrawingArea?) transparent.  the Pixbuf is from a .png, and responds
"true" to #.has_alpha?.
  here's the code...
#################################

require 'gtk2'

class Spinner < Gtk::EventBox

def initialize
  super
  @file = "/home/jk/ruby/arm.png"
  @da = Gtk::DrawingArea.new
  @da.signal_connect("expose-event"){|w, e| self.draw(w, e)}
  self.add(@da)
  self.set_size_request(600, 500)
  self.set_visible_window(false)  # this doesn't work...
end  #initialize

def draw(w, e)
  w.window.set_opacity(0.1)    # this doesn't work either...
  cc = w.window.create_cairo_context
  time = Time.new
  angle = time.sec * 6
  cc.translate(250, 250)
  cc.rotate(angle * Math::PI / 180)
  pixbuf = Gdk::Pixbuf.new(@file)
  cc.set_source_pixbuf(pixbuf, -48, -46)
  cc.paint
end  #draw

def update
  @da.queue_draw
end  #update

end  #Spinner

spinner = Spinner.new
win = Gtk::Window.new
win.signal_connect("destroy"){Gtk.main_quit}
win.set_size_request(600, 600)
layout = Gtk::Layout.new
bgf = ("/home/jk/ruby/TradyBlix.png")
bg = Gtk::Image.new(bgf)
layout.put(bg, 100, 100)
layout.put(spinner, 200, 200)
layout.set_size(600, 500)
box = Gtk::VBox.new(false,0)
btn = Gtk::Button.new("update")
btn.signal_connect("clicked"){spinner.update}
box.pack_start(layout, true, true, 0)
box.pack_start(btn, false, false, 0)
win.add(box)
win.show_all

Gtk.main
###############################

  any ideas?  been searching, but haven't come up with anything...

  thanks -

  j
8e6374c0ef7b66942f34798e31edf014?d=identicon&s=25 "Dobai-Pataky Bálint" <dpblnt@gmail.com> (Guest)
on 2011-02-13 09:28
(Received via mailing list)
Hi,
It's not the image is not transparent, i'v put a smaller image in, and i
see the large Gtk::Layout with my background-color on the larger image.
So i guess what is really needed to tell the Gtk::Layout to have
transparent background, or use something else for it.

Balint
8e6374c0ef7b66942f34798e31edf014?d=identicon&s=25 "Dobai-Pataky Bálint" <dpblnt@gmail.com> (Guest)
on 2011-02-13 09:54
(Received via mailing list)
I'm resending this,
Look what I've found:
Note that "no window" widgets (which have the GTK_NO_WINDOW flag set)
draw on their parent container's window and thus may not draw any
background themselves. This is the case for e.g. GtkLabel.
(source http://library.gnome.org/devel/gtk/unstable/GtkWidget.html )
So i replaced the Gtk::DrawingArea in your code to Gtk::Label, and my
image is rendered with transparent background.

Balint
8e6374c0ef7b66942f34798e31edf014?d=identicon&s=25 "Dobai-Pataky Bálint" <dpblnt@gmail.com> (Guest)
on 2011-02-13 09:58
(Received via mailing list)
Look what I've found:
Note that "no window" widgets (which have the GTK_NO_WINDOW flag set)
draw on their parent container's window and thus may not draw any
background themselves. This is the case for e.g. GtkLabel.
(source http://library.gnome.org/devel/gtk/unstable/GtkWidget.html )
So i replaced the Gtk::DrawingArea in your code to Gtk::Label, and my
image is rendered with transparent background.

Balint
7f28f9db46bfe8e9b8b5fcd90b2f1302?d=identicon&s=25 J. K. (j_k)
on 2011-02-13 14:28
"Dobai-Pataky Bálint" <dpblnt@gmail.com> wrote in post #981366:
> So i replaced the Gtk::DrawingArea in your code to Gtk::Label, and my
> image is rendered with transparent background.
>
> Balint

hi Balint -
  very interesting - going to fool around with this some this afternoon,
and i'll get back to you.
  thanks for the idea...

  -j
7f28f9db46bfe8e9b8b5fcd90b2f1302?d=identicon&s=25 J. K. (j_k)
on 2011-02-13 15:19
hi balint -

  works like a charm...  thanks!

 - j
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.