Gtkmm + Glade = invisible DrawingArea



I'm trying to get work this gtkmm doc example:
http://developer.gnome.org/gtkmm-tutorial/2.24/gtkmm-tutorial.html#cairo-example-lines

Taken as is, it works without problems...but if I try to modify it
adding a little interface created with glade (A Gtk Window with inside a
DrawingArea element), it compiles but I obtain a window with an empty
drawing area.

Here the code:
#include<gtkmm.h>
#include<iostream>
#include<fstream>
#include<iomanip>
#include<string>
#include<cairomm/context.h>

#include<gtkmm/main.h>
#include<gtkmm/window.h>
#include<gtkmm/drawingarea.h>

class MyArea : public Gtk::DrawingArea
{
     public:
         MyArea(BaseObjectType* cobject, const
Glib::RefPtr<Gtk::Builder>&  refGlade) {};
         virtual ~MyArea() {};

     protected:
         //Override default signal handler:
         virtual bool on_expose_event(GdkEventExpose* event)
         {
             // This is where we draw on the window
             Glib::RefPtr<Gdk::Window>  window = get_window();
             if(window)
             {
                 Gtk::Allocation allocation = get_allocation();
                 const int width = allocation.get_width();
                 const int height = allocation.get_height();

                 // coordinates for the center of the window
                 int xc, yc;
                 xc = width / 2;
                 yc = height / 2;

                 Cairo::RefPtr<Cairo::Context>  cr =
window->create_cairo_context();
                 cr->set_line_width(10.0);

                 // clip to the area indicated by the expose event so
that we only redraw
                 // the portion of the window that needs to be redrawn
                 cr->rectangle(event->area.x, event->area.y,
                         event->area.width, event->area.height);
                 cr->clip();

                 // draw red lines out from the center of the window
                 cr->set_source_rgb(0.8, 0.0, 0.0);
                 cr->move_to(0, 0);
                 cr->line_to(xc, yc);
                 cr->line_to(0, height);
                 cr->move_to(xc, yc);
                 cr->line_to(width, yc);
                 cr->stroke();
             }

             return true;
         }
};

int main(int argc, char** argv)
{
     Gtk::Window    *win = 0;

     Gtk::Main kit(argc, argv);

     //Load the GtkBuilder file and instantiate its widgets:
     Glib::RefPtr<Gtk::Builder>  refBuilder = Gtk::Builder::create();
     try
     {
         refBuilder->add_from_file("drawingArea.ui");
     }
     catch(const Glib::FileError&  ex)
     {
         std::cerr<<  "FileError: "<<  ex.what()<<  std::endl;
         return 1;
     }
     catch(const Gtk::BuilderError&  ex)
     {
         std::cerr<<  "BuilderError: "<<  ex.what()<<  std::endl;
         return 1;
     }

     //Get the GtkBuilder-instantiated Dialog:
     refBuilder->get_widget("window1", win);
     if(win)
     {
         MyArea *circuitDrawingArea;
         win->set_title("MTA Automotive");

         refBuilder->get_widget_derived("drawingarea1", circuitDrawingArea);
//        win->add(circuitDrawingArea);
         circuitDrawingArea->show();
     }

     kit.run(*win);

     return 0;
}

This is drawingArea.ui:
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk+" version="2.16"/>
<!-- interface-naming-policy project-wide -->
<object class="GtkWindow" id="window1">
<child>
<object class="GtkDrawingArea" id="drawingarea1"/>
</child>
</object>
</interface>

I experienced with a simple print that I do not enter the
on_expose_event() method.
Can anyone tell me where am I wrong?

Thanks in advance!

--
Alessandro Candini

MEEO S.r.l.
Via Saragat 9
I-44122 Ferrara, Italy
Tel: +39 0532 1861501
Fax: +39 0532 1861637
http://www.meeo.it

========================================
"ATTENZIONE:le informazioni contenute in questo messaggio sono
da considerarsi confidenziali ed il loro utilizzo è riservato unicamente
al destinatario sopra indicato. Chi dovesse ricevere questo messaggio
per errore è tenuto ad informare il mittente ed a rimuoverlo
definitivamente da ogni supporto elettronico o cartaceo."

"WARNING:This message contains confidential and/or proprietary
information which may be subject to privilege or immunity and which
is intended for use of its addressee only. Should you receive this
message in error, you are kindly requested to inform the sender and
to definitively remove it from any paper or electronic format."



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