[Glade-users] libglademm and DrawingArea



Hi,

I did my first steps with Glade and libglademm respektively but now I am 
stuck with the DrawingArea.

I get my derived drawing area widget like so:
   m_refGlade->get_widget_derived("drawingarea", m_pDrawingArea);
which seems to work fine, as the proportions from the Glade XML file are 
respected. (I set the widget to 200x200 size - the window is resized to 
that)

Now I wanted to draw lines and therefore overwrote the expose event with:
bool GCurveDrawingArea::on_expose_event(GdkEventExpose* event)
{
   // This is where we draw on the window
   Glib::RefPtr<Gdk::Window> window = get_window();
   window->clear();
   window->draw_line(gc_, 1, 1, 100, 100);
   std::cout << "Drawing Area exposed!" << std::endl;
   return true;
}

which I basically took from the gtkmm docs about the drawing area. This 
on the other hand does give me:
  (gcurve:29715): Gdk-CRITICAL **: file gdkdraw.c: line 370 
(gdk_draw_line): assertion `gc != NULL' failed
   Drawing Area exposed!

So why is my graphics context = NULL although I implemented the 
on_realize function just as in the tutorial?:
void GCurveDrawingArea::on_realize()
{
   // We need to call the base on_realize()
   Gtk::DrawingArea::on_realize();

   // Now we can allocate any additional resources we need
   Glib::RefPtr<Gdk::Window> window = get_window();
   gc_ = Gdk::GC::create(window);
   window->set_background(red_);
   window->clear();
   gc_->set_foreground(blue_);
   std::cout << "Drawing Area realized!" << std::endl;
}


I have never debugged a C++ programm so I am lost. What should I do? Or 
is there maybe a better way to accomplish drawing?

PS: The example from gtkmm (without glade) works just fine




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