Gtk2/cairo transparency question

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

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

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

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

“Dobai-Pataky Bálint” [email protected] 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

hi balint -

works like a charm… thanks!

  • j