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

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert 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
C838db9af1d90a87a828ecad8556b804?d=identicon&s=25 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/
4828d528e2e46f7c8160c336eb332836?d=identicon&s=25 Robert Heiler (shevegen)
on 2008-11-11 17:22
Thanks a lot Guillaume.

Customized Interfaces, here I come! :-)
This topic is locked and can not be replied to.