Forum: Ruby-Gnome 2 Gtk::DrawingArea and Icons

Posted by Marc Heiler (shevegen)
on 2008-11-11 12:54
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
Posted by Guillaume Cottenceau (Guest)
on 2008-11-11 14:43
(Received via mailing list)
On Tue, Nov 11, 2008 at 12:54 PM, Marc Heiler
<ruby-forum-incoming@andreas-s.net> 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 Cottenceau - http://zarb.org/~gc/
Posted by Marc Heiler (shevegen)
on 2008-11-11 17:22
Thanks a lot Guillaume.

Customized Interfaces, here I come! :-)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.