Gtk::DrawingArea and Icons

Hi,

is it possible to put up images/icons within a Gtk::DrawingArea?

I.e. if i have the image of a little cat, can this be displayed on it?

Right now I only saw examples with custom elements, things like

cairo_context = widget.window.create_cairo_context
cairo_context.scale(*widget.window.size)

Thanks

On Tue, Nov 11, 2008 at 12:54 PM, Marc H.
[email protected] wrote:

Hi,

is it possible to put up images/icons within a Gtk::DrawingArea?

I.e. if i have the image of a little cat, can this be displayed on it?

Generally, it’s easy to work with pixbufs.

require ‘gtk2’

class MainView < Gtk::DrawingArea

def initialize
    super()
    signal_connect('expose-event') { draw }
    signal_connect('configure-event') { update_shown }
end

def update_shown
    w, h = window.size
    puts "my size: #{w}x#{h}"
    #- normally you could create a pixbuf related to w,h (scaling

images, drawing…)
@pixbuf = Gtk::Image.new(‘/tmp/foo.png’).pixbuf
return true
end

def draw
    window.draw_pixbuf(nil, @pixbuf, 0, 0, 10, 10, -1, -1,

Gdk::RGB::DITHER_NONE, -1, -1)
end
end

Gtk.init

w = Gtk::Window.new
w.add(MainView.new)
w.show_all

Gtk.main


Guillaume C. - Guillaume Cottenceau

Thanks a lot Guillaume.

Customized Interfaces, here I come! :slight_smile: