SV: drawables.



> > I'm currently trying to make an application that retrieves an image
> > from, say, jpeg, and I would like to draw some lines on top of this
> > image.
> >
> > I have found this snippet in the tutotial
> >
(http://www.gtkmm.org/docs/gtkmm-2.4/docs/tutorial/html/ch15s06.html):
> >
> > bool myarea::on_expose_event(GdkEventExpose* ev)
> > {
> > Glib::RefPtr<Gdk::PixBuf> image =
> > Gdk::PixBuf::create_from_file("myimage.png");
> > image->render_to_drawable(get_window(), get_style()->get_black_gc(),
> > 0, 0, 100, 80, image->get_width(), image->get_height(), // draw the
> > whole image (from 0,0 to the full width,height) at 100,80 in the
window
> > Gdk::RGB_DITHER_NONE, 0, 0);
> > return true;
> > }
> >
> > It works. But I don't want to draw directly on the window, and every
> > example I find the gdk::drawable used is from get_window().
> 
> First, I just want to make sure that you're aware of the distinction
> between Gtk::Window and Gdk::Window.  (I apologize if you know all of
> this already -- I have no idea what level of experience you have with
> Gtk / gtkmm so I don't want to make any assumptions).  A
> Gtk::DrawingArea contains its own Gdk::Window (which is just a
> rectangular region on the screen), but this has nothing to do with the
> Gtk::Window widget that it is displayed in.  The Gdk::Window is the
> window you're getting when you call the get_window() function, not the
> Gtk::Window.
> 
This was the key point that I had completely misunderstood.

> > I don't understand why Gtk::DrawingArea is not gdk::drawable.
> 
> it is.  You just have to get its Gdk::Window to do the actual drawing
> (Gdk::Window inherits from Gdk::Drawable).
> 
> > The question is what gtk-widget to use. Apparently only pixmap and
> > bitmap are gdk::drawable, but they are usuable for "offscreen"
> > rendering.
> >
> > Help, pseudocode, links to examples would be much appreciated.
> 
> Does that help, or did I just repeat things you already knew?

It did help, thanks.

Now I do this (using libglade) - (InData is a class of my own making):

Gtk::DrawingArea *PolyDrawArea;
xml_interface->get_widget( "PolyDrawArea", PolyDrawArea );

Glib::RefPtr<Gdk::Pixbuf> image = Gdk::Pixbuf::create_from_file(
"nn.bmp" );
PolyDrawArea->set_size_request( image->get_width(), image->get_height()
);
image->render_to_drawable( 	PolyDrawArea->get_window(), 
			PolyDrawArea->get_style()->get_black_gc(),
			0, 0, 0, 0, 
			image->get_width(), image->get_height(), 
			Gdk::RGB_DITHER_NONE, 0, 0);


It works, but I get

(AcqTest.exe:3996): Gdk-CRITICAL **: gdk_draw_pixbuf: assertion
'GDK_IS_DRAWABLE (drawable)' failed

on the render_to_drawable() line.
Any ideas?

Thanks again

morten



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