[cairo] Context in ExposeEvent with gtkmm
Jonathon Jongsma
jonathon at quotidian.org
Thu Jul 23 21:01:52 PDT 2009
Massimo Redaelli wrote:
> Hi all. I'm a newbie trying to write a simple program in
> gtkmm+cairomm, basically copied from the Scribble/DrawingArea
> tutorial.
>
> The only difference is that I need to redraw with Cairo on
> ExposeEvents, while in the tutorial a pixmap is used.
> I set up the ExposeEvent for DrawingArea, and I am sure it gets
> called. However, all Cairo drawing commands have no effect.
> I have a feeling I have problems with the Cairo context...
>
> Specifically, my custom window eWriteWin contains a DrawingArea. I have:
>
> [e-write-win.h]
>
> private:
> Gtk::DrawingArea* pda;
> Cairo::RefPtr<Cairo::Context> cr;
You should not cache the Cairo context between expose events. That will not work as you expect it to. You should simply create a new context in each expose handler
> bool eWriteWin::onExposeEvent ( GdkEventExpose *event)
> {
> std::cerr << "Expose!" << std::endl;
> // cr = pda->get_window()->create_cairo_context();
As this commented-out-code does here ^
> cr->set_line_width(10.0);
> cr->move_to(0, 0);
> cr->line_to(100, 100);
> cr->stroke();
> return true;
> }
> I tried to create a new context, but I have no idea if that's the
> right thing to do (afterall, the ols context works if I draw *after*
> the ExposeEvent), and even if it is, how do I get create a c++ Context
> (or how do I get the c++ Gtk::Window from event->window)?
first of all: I assume that the expose event that you're handling is the drawing area's expose event and not some parent widget's expose event (?). If so, then the commented-out code above should work fine.
--
jonner
More information about the cairo
mailing list