[Glade-users] Gtkmm + Glade = invisible DrawingArea

I'm trying to get work this gtkmm doc example: 

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
         MyArea(BaseObjectType* cobject, const 
Glib::RefPtr<Gtk::Builder>& refGlade) {};
         virtual ~MyArea() {};

         //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();
                 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 = 

                 // 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);

                 // 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);

             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();
     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);
         MyArea *circuitDrawingArea;
         win->set_title("MTA Automotive");

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


     return 0;

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

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

"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]