[cairo] Context in ExposeEvent with gtkmm

Massimo Redaelli massimo at redaelli.name
Thu Jul 23 14:03:35 PDT 2009


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;


[e-write-win.cc]

eWriteWin::eWriteWin(...) {
  refGlade->get_widget("drawingarea1", pda);
  if(pda) {
    [...]
    pda->signal_expose_event().connect( sigc::mem_fun(*this,
           &eWriteWin::onExposeEvent) );
  }
  cr = pda->get_window()->create_cairo_context();
  [...]
}

bool eWriteWin::onExposeEvent ( GdkEventExpose *event)
{
  std::cerr << "Expose!" << std::endl;
  // cr = pda->get_window()->create_cairo_context();
  cr->set_line_width(10.0);
  cr->move_to(0, 0);
  cr->line_to(100, 100);
  cr->stroke();
  return true;
}

So, "Expose!" gets printed, but no line is drawn.

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)?

I hope I was clear :)

Thanks!

M.


More information about the cairo mailing list