Re: [gtkmm] how to display an image
- From: Paul Davis <paul linuxaudiosystems com>
- To: Silviu D Minut <minutsil cse msu edu>
- Cc: gtkmm-list gnome org
- Subject: Re: [gtkmm] how to display an image
- Date: Fri, 02 May 2003 07:51:36 -0400
>I'm new to gtkmm (not to gtk+ though), and I have to write a simple gui
>that is supposed to display a pgm/ppm image and collect mouse clicks from
>the user. In gtk+ displaying the rgb image was done like so:
>
>gboolean on_darea_expose (GtkWidget *widget,
> GdkEventExpose *event,
> gpointer user_data)
>{
> gdk_draw_rgb_image (widget->window,
> widget->style->fg_gc[GTK_STATE_NORMAL],
> 0, 0, width, height,
> GDK_RGB_DITHER_MAX, rgbbuf, width * 3);
> return 1;
>}
>
>How do I do this in gtkmm? Is there a function at a higher level than gdk,
>or do I derive my own Image from Gtk::Image with a member function which
>essentially digs for pointers to data, and wraps the gdk_draw_rgb_image
>call? Does anybody have an example of this?
there are several examples of many things in the examples directory
that comes with the source to gtkmm. a simple untested translation of
what you wrote above:
gint
MyWidget::on_expose_event (GdkEventExpose* event)
{
get_window()->draw_rgb_image (get_style()->fg_gc (GTK_STATE_NORMAL),
0, 0, width, height,
GD_RGB_DITHER_MAX, rgbbuf, width*3);
return TRUE;
}
note that expose event handlers returns gint, not gboolean.
you'd define a MyWidget class something like this:
class MyWidget : public Gtk::DrawingArea
{
public:
...
protected:
gint on_expose_event (GdkEventExpose*);
...
};
i may have gotten the naming convention for virtual signal handling
methods wrong (i'm still stuck in the stone ages of gtkmm 1.2), but
the idea is that MyWidget::on_expose_event() will override
Gtk::DrawingArea::on_expose_event(), and so without any work on your
part it will be called whenever there is an expose event on the
widget.
--p
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]