[gtkada] Gtk_Plot

manuel.op.de.coul at eon-benelux.com manuel.op.de.coul at eon-benelux.com
Mon Jun 25 18:14:22 CEST 2001


I am at a total loss getting a Gtk_Plot visible.
I've created code to put a plot directly on a Gtk_Drawing_Area.
Unfortunately, there's no example in testgtk on how to do
that, only on a canvas. I have no need to move anything so
I choose the drawing area. It remains blank whatever I try.
I used the first Gtk_New(Plot, Drawable) and filled in
the drawing area for the drawable, converted by
Gtk.Drawing_Area.Get_Window to Gdk_Window.
Like this:

   Gtk_New (Scale_Plot_Dialog.Drawingarea_Plot);
   Size (Scale_Plot_Dialog.Drawingarea_Plot, 350, 300);
   Pack_Start (Scale_Plot_Dialog.Dialog_Vbox60, Scale_Plot_Dialog.Drawingarea_Plot, True, True, 0);
   Return_Callback.Connect
     (Scale_Plot_Dialog.Drawingarea_Plot, "expose_event", On_Drawingarea_Plot_Expose_Event'Access);
   Gdkw := Gtk.Drawing_Area.Get_Window(Scale_Plot_Dialog.Drawingarea_Plot);
   Gtk_New (Scale_Plot_Dialog.Scale_Curve, Gdkw);

Then the plot is created like this:

   X, Y, Dx, Dy : Gdouble_Array_Access := new Glib.Gdouble_Array(0 .. 500);

   procedure Plot_Scale (S : Scale_Bounded.Scale) is
      Pl_Data : Gtk_Plot_Data;
      Plot : Gtk_Plot renames Scale_Plot_Dialog.Scale_Curve;
      Extent : constant Natural := Sb.Extent_Of(S);
      L : Gtk_Plot_Line;
   begin
      Set_Background (Plot, Get_White(Get_Style(Plot)));
      Axis_Hide_Title (Plot, Axis_Top);
      X0_Set_Visible (Plot, True);
      Y0_Set_Visible (Plot, True);
      Show(Plot);
      Gtk_New(Pl_Data);
      Add_Data(Plot, Pl_Data);
      Show(Pl_Data);
      Set_Line_Attributes(Pl_Data, Line_Solid, 1.0, Get_Black(Get_Style(Plot)));
      for I in 0 .. Extent loop
         Y(I) := Gdouble(1200.0 * Sb.Log2(S, I));
      end loop;
      Set_Points(Pl_Data, X, Y, Dx, Dy);
      Set_Numpoints(Pl_Data, Gint(Extent + 1));

      Axis_Set_Visible (Plot, Axis_Bottom, True);
      Axis_Set_Visible (Plot, Axis_Left, True);
      Axis_Set_Visible (Plot, Axis_Top, False);
      Axis_Set_Visible (Plot, Axis_Right, False);
      Axis_Show_Ticks (Plot, Axis_Bottom, Ticks_In, Ticks_In);
      Axis_Show_Ticks (Plot, Axis_Left, Ticks_In, Ticks_In);
      Axis_Set_Ticks (Plot,  Axis_X, 1.0, 1);
      Axis_Set_Ticks (Plot,  Axis_Y, 100.0, 1);
      Axis_Set_Title (Plot, Axis_Bottom, "Scale degrees");
      Axis_Set_Title (Plot, Axis_Left, "Cents");
      Set_Xscale (Plot, Scale_Linear);
      Set_Yscale (Plot, Scale_Linear);
      Grids_Set_Visible (Plot, True, True, True, True);
      Autoscale (Plot);
      Set_Symbol (Pl_Data, Symbol_Square, Symbol_Opaque, 8, 2.0,
                  Get_Black (Get_Style (Plot)), Get_Black (Get_Style (Plot)));
      Set_Line_Attributes (Pl_Data, Line_Solid, 4.0,
        Get_Black(Get_Style(Plot)));
      Set_Connector (Pl_Data, Connect_Straight);
      Set_X_Attributes (Pl_Data, Line_Solid, 0.0, Get_Black (Get_Style (Plot)));
      Set_Y_Attributes (Pl_Data, Line_Solid, 0.0, Get_Black (Get_Style (Plot)));
      Queue_Draw(Plot);
      Show_All(Scale_Plot_Dialog);
   end Plot_Scale;

And this is the expose callback:

   function On_Drawingarea_Plot_Expose_Event
     (Object : access Gtk_Widget_Record'Class;
      Params : Gtk.Arguments.Gtk_Args) return Boolean
   is
      Arg1 : Gdk_Event := To_Event (Params, 1);
   begin
      Refresh(Scale_Plot_Dialog.Scale_Curve, Gdk.Event.Get_Area(Arg1));
      return False;
   end On_Drawingarea_Plot_Expose_Event;

I also tried calling Paint and Refresh myself, still nothing.
Only the primitive Drawable subprograms work, but with Plot the only
thing I get is a blank window.

Manuel Op de Coul





More information about the gtkada mailing list