[gtkmm] Re: help using gtkmm



"Pedro A. Castillo Valdivieso" <pedro geneura ugr es> writes:

> I'm new on using gtkmm. I would like to try the following:
>     an application that includes a canvas (drawingarea) and reads
> pixmaps from files to show them on the canvas
> I found a program, however it uses Gdk_Pixmap object and I can't make
> it compile.
> Is there a way to use a pixmap or something like that to paint (used
> as buffer) and once the image is ready, it is shown on the canvas?
> Is there a web site where I could find some examples (different from
> the sources)?

Well, there are two possibilities. Either you really want multiple
images at the same time and full control over how they overlap, or you
just want to display one image at the time. In the latter case, you
simply put a Gtk::Image inside your window and say

  my_image.set(some_pixbuf);

See

  http://www.gtkmm.org/gtkmm2/docs/reference/html/classGtk_1_1Image.html

You can load the Gdk::Pixbufs directly from files, see e.g. the create
functions (in particular the create_from_file) in

  http://www.gtkmm.org/gtkmm2/docs/reference/html/classGdk_1_1Pixbuf.html

There's also a PixbufLoader for incremental loading, I think.

If you want more images at the same time, I suggest you use the Gnome
canvas, wrapped in the libgnomecanvasmm library. Create a canvas which
is just an ordinary widget, and then create Gnome::Canvas::Pixbuf
canvas items inside the root group of the canvas. Something like

  Gnome::Canvas::Pixbuf *pixbuf = 
    new Gnome::Canvas::Pixbuf(*the_canvas.get_root(), x, y, pixbuf);

You can let your main window class keep a std::vector of these canvas
items then, so you don't leak.

A real-world canvas-using application is my hardware monitor applet
which you can grab from here:

  http://www.cs.auc.dk/~olau/hardware-monitor/

It doesn't use any pixbufs, though.


PS: It would probably be better to write to the mailing list for gtkmm
(gtkmm-list) since there's a greater chance that somebody will be able
to help you directly there. I've CC'ed the list. You can subscribe to
it from mail.gnome.org if you aren't already.

-- 
Ole Laursen
http://www.cs.auc.dk/~olau/



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]