Re: [gtk-list] Drawing Area woes: Sample code (Gtk--)




The error is quite simple.  You added a function called setUsize
that constructs the pixmap.  However, the widget has yet to be
realized or mapped.  No gdk resources can be constructed until after
realization of the widget.  Prior to realization the widget is
just caching up values for constructing resources later.    

There are several ways of handling this.  One is to override the 
realize_impl method and have it set up the resources immediately
following the realization of the widget.  The second is to use
the initial configure event to size the pixmap and put checks for 
attempts to draw prior to the first configure. 

Other suggestions:
  Use the impl methods rather that connect resources in Gtk--
    (They are smaller and faster)
  Try to cache the size of the pixmap and only do a unref/new if
    the pixmap has grown in size.  (It doesn't matter if the 
    pixmap got smaller!)
  Use C++ strings so that you don't have to do silly things like
    strdup/free.
  Make sure that you get the patch for Gtk-- 1.0.0,  there was
    a construction problem in the current release (minor).
   
  (Consider using Gdk--, it frees resources automatical, so
    you don't have to ref/unref)


Okay now to the hyper links.
Here are a few examples that demo the proper allocation of gdk resources
(allocate pixmap with realize_impl.)
http://www.ece.ucdavis.edu/~kenelson/private/canvas.cc
(allocate pixmap with configure_impl.)
http://www.ece.ucdavis.edu/~kenelson/private/scribble-simple.cc
(allocate OpenGL with realize_impl.)
http://www.ece.ucdavis.edu/~kenelson/gtkglareamm/dist/untarred/gtkglareamm-0.4/examples/planetmm/planet.cc

And last but not least.... your fixed program.
http://www.ece.ucdavis.edu/~kenelson/private/guidialog.cc

Hope it helps.

--Karl



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