RE: plot widget



You don't have to use a gtkplot with a gtkplotcanvas, you can use a gtkplot on a
gtkdrawingarea instead.  To do so, you must create its drawable manually and
assign the GdkWindow of the drawing area to its GTK_WIDGET(plot)->window field.
Here's an example gtkdrawingarea events callback you could use to do this after
you've created a gtkwindow "da_window", gtkdrawingarea "drawing_area", and a
gtkplot "active_plot" (Note: this example requires that widget pointers to
"drawing_area" and "active_plot" be added to "da_window" using
gtk_object_set_data()).  An added feature to this approach, which I don't think
is available from gtkplotcanvas, is that it will size itself to the size of the
gtkdrawingarea and "autoscale" your plots when you resize the gtkwindow!  Hope
this helps.


                                -- Alan Dugas


/* Function to handle drawing area events */
gboolean drawing_area_events(GtkWidget *calling_widget, GdkEvent *event,
GtkWidget *da_window)
{
   /* Declaring local variables */
   GtkWidget   *drawing_area;
   GtkWidget   *active_plot;


   /* If event is "destroy"... */
   if ( event->type == GDK_DESTROY )
      return(TRUE);


   /* If event is "configure"... */
   if ( event->type == GDK_CONFIGURE )
   {
      drawing_area = gtk_object_get_data(GTK_OBJECT(da_window), "drawing area");
      active_plot = gtk_object_get_data(GTK_OBJECT(da_window), "active plot");
      if ( drawing_area && active_plot )
      {
         if ( !GTK_WIDGET_REALIZED(drawing_area) )
            return FALSE;
  
         if ( !GTK_PLOT(active_plot)->drawable )
         {
            GTK_WIDGET(active_plot)->parent = GTK_WIDGET(drawing_area)->parent;
            if ( !GTK_WIDGET_DRAWABLE(GTK_WIDGET(active_plot)) )
            {
               gtk_widget_show (GTK_WIDGET(active_plot)); 
               gtk_widget_map (GTK_WIDGET(active_plot)); 
            }
            GTK_WIDGET(active_plot)->window = GTK_WIDGET(drawing_area)->window;
         }

         if ( GTK_PLOT(active_plot)->drawable )
            gdk_pixmap_unref(GTK_PLOT(active_plot)->drawable);
         GTK_PLOT(active_plot)->drawable =
gdk_pixmap_new(GTK_WIDGET(drawing_area)->window,
        
GTK_WIDGET(drawing_area)->allocation.width,
        
GTK_WIDGET(drawing_area)->allocation.height, -1);
         gdk_draw_rectangle(GTK_PLOT(active_plot)->drawable,
        
GTK_WIDGET(drawing_area)->style->white_gc,
                                        TRUE, 0, 0,
        
GTK_WIDGET(drawing_area)->allocation.width,
        
GTK_WIDGET(drawing_area)->allocation.height);
         gtk_plot_set_drawable(GTK_PLOT(active_plot),
GTK_PLOT(active_plot)->drawable);

         GTK_WIDGET(active_plot)->allocation.x = 0;
         GTK_WIDGET(active_plot)->allocation.y = 0;
         GTK_WIDGET(active_plot)->allocation.width =
GTK_WIDGET(drawing_area)->allocation.width;
         GTK_WIDGET(active_plot)->allocation.height =
GTK_WIDGET(drawing_area)->allocation.height;

         /* Insert drawing function(s) here to initialize plot */
      }
   }


   /* If event is "expose"... */
   if ( event->type == GDK_EXPOSE )
   {
      active_plot = gtk_object_get_data(GTK_OBJECT(da_window), "active plot");
      if ( active_plot )
         gtk_plot_refresh(GTK_PLOT(active_plot), NULL);
   }


   /* Do not propogate event? */
   return(TRUE);
}
/* End of drawing_area_events() */


----------
From:    Frederic Cazenave[SMTP:cazenave radar mcgill ca]
Sent:    Monday, March 12, 2001 1:39 PM
To:    gtk-app-devel-list gnome org
Subject:    plot widget

Hi, 

I'm developping a weather radar application using GTK. For the  beginning I
have built my 
own plot window using a simple gtk_drawing_area on a gtk_fixed . I want to
make something more sofisticated 
but I don't want to use the plot widget from gtkextra because I don't want to
build my application 
on a canvas. If someone could send me some examples of widget I could use to
plot real time data 
as the plot widget (window and axis resize ...). Also I'm looking for a scope
window example. 

Thanks for your help 

Best regards 

Fred cazenave 
-- 
 _________________________________________________________
|                                                          |
|               Frederic CAZENAVE                          |
|    _/\_  /^=  McGill Radar                               |
| \_/    \//    Box 198, MacDonald College                 |
|   | /-\ |     Ste Anne de Bellevue                       |
|   ||   ||     Quebec, Canada   H9X 3V9                   |
|               Tel (514) 398 7733 fax (514) 398 7755      |
|                mailto:Frederic Cazenave hmg inpg fr       |
|                http://www.mpl.orstom.fr/hydrologie/catch/ |
|__________________________________________________________|
 





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