Re: Drawing with cairo



Doug Baldwin wrote:

On May 15, 2008, at 11:05 AM, Diego A. Fons wrote:

Like Theodore I'm using gtkmm. This is an extrac of the code which
doesn't work:
void Plotter::on_realize( void )
{
   // Create the GDK window
   refGdkWindow = Gdk::Window::create(get_window(), &attributes,
           GDK_WA_X | GDK_WA_Y);

   // Create Cairo context
Cairo::RefPtr<Cairo::Context> cr = refGdkWindow->create_cairo_context();
}


bool Plotter::on_expose_event( GdkEventExpose* event )
{
   // ... Use cr to do some drawing
}

Both cr and refGdkWindow are members of the class Plotter....

Isn't variable cr local to Plotter::on_realize in the above? Even if you declare a similarly-named variable in the class, I'm pretty sure the declaration in the on_realize method will shadow the class member. You might get the result you want if you drop the declaration from the statement that saves the context in cr, i.e., change the second half of Plotter::on_realize to...

    // Create Cairo context
    cr = refGdkWindow->create_cairo_context();

My mistake!

That's what i meant:

void Plotter::on_realize( void )
{
  // Create the GDK window
  refGdkWindow = Gdk::Window::create(get_window(), &attributes,
          GDK_WA_X | GDK_WA_Y);

  // Create Cairo context
  cr = refGdkWindow->create_cairo_context();
  // cr is a private member of the class
}


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