GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Jul 28, 2014 8:31 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: GTK 3.8 Graphic programming in ADA (GtkAda)
PostPosted: Sat Jan 04, 2014 3:24 am 
Offline
Familiar Face

Joined: Fri Sep 23, 2011 12:04 pm
Posts: 28
I am using Ada with the GtkAda implementation of Gtk 3.8

I am trying to learn myself simple graphical programming in GTK 3.8
(GtkAda).
I want to draw a a simple grid in a drawing area.
With Glade 3 I created a window with a GtkdrawingArea with in a GtkViewport
with in a GtkScrolledWindow
within a GtkVBox within a GtkWindow. So far the program works.
With Get_Object the GtkdrawingArea was extracted from the builder and used
to create a Cairo context C
Now I want to draw a grid using

Code:
Gdkw := Get_Window (Gtk_Drawing_Area);
CR := Create(Gdkw);
Save(CR);
Set_Source_Rgb(CR, 1.0, 0.0, 0.0);
Paint(CR);
Restore(CR);
Number := Width * Height;
Total_W := Init_W + W * W * CW;
Total_H := Init_H + H * H * CW;
Set_Line_Width(CR, 3.0);
Set_Source_Rgb(CR, 1.0, 1.0, 1.0);
for n in 0.. H * H loop
   Move_To(CR, GDouble(Init_W + n * CW), GDouble(Init_H));
   Rel_Line_To(CR, GDouble(Total_W), 0.0);
   Stroke(CR);
end loop;
for n in 0.. W * W loop
   Move_To(CR, GDouble(Init_W), GDouble(Init_H + n * CW));
   Rel_Line_To(CR, 0.0, GDouble(Total_H));
   Stroke(CR);
end loop;


The result is still an empty drawing area. The background is still white
(Should be red) the lines are invisible
I still am missing something.
I tried to find Ada examples how to create a running program but I cannot
find anything.
Who can help either by directing me to Ada examples or by telling me what I
do miss in this program


Top
 Profile  
 
 Post subject: Re: GTK 3.8 Graphic programming in ADA (GtkAda)
PostPosted: Sun Jan 05, 2014 7:55 am 
Offline
Familiar Face

Joined: Fri Sep 23, 2011 12:04 pm
Posts: 28
Further investigation revealed that the grid was visible at a breakpoint before Gtk.Main.Main. at the moment I start again the grid disappears. The problem seems to be that I cannot create an initial drawing before I can create any normal action like clicking on "New". How do I create such an initial drawing?


Top
 Profile  
 
 Post subject: Re: GTK 3.8 Graphic programming in ADA (GtkAda)
PostPosted: Wed Jan 08, 2014 8:59 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Hello,

Please excuse my Ada. I have never used it before. Your code needs to be on the lines of the following.

Code:
procedure Draw_Handler (Widget : access Gtk_Widget_Record'Class; Cr : Cairo.Cairo_Context) is
begin
  Save(CR);
  Set_Source_Rgb(CR, 1.0, 0.0, 0.0);
  Paint(CR);
  Restore(CR);
  Number := Width * Height;
  Total_W := Init_W + W * W * CW;
  Total_H := Init_H + H * H * CW;
  Set_Line_Width(CR, 3.0);
  Set_Source_Rgb(CR, 1.0, 1.0, 1.0);
  for n in 0.. H * H loop
     Move_To(CR, GDouble(Init_W + n * CW), GDouble(Init_H));
     Rel_Line_To(CR, GDouble(Total_W), 0.0);
     Stroke(CR);
  end loop;
  for n in 0.. W * W loop
     Move_To(CR, GDouble(Init_W), GDouble(Init_H + n * CW));
     Rel_Line_To(CR, 0.0, GDouble(Total_H));
     Stroke(CR);
  end loop;
end Draw_Handler;

...
  Gtk_Drawing_Area.On_Draw (Draw_Handler'Access);
...


The actual drawing is done within a call-back by the signal called "draw" which is called when ever a redraw is require on the drawing area. From the C++ tutorial :-
Quote:
The DrawingArea widget is a blank window that gives you the freedom to create any graphic you desire. Along with that freedom comes the responsibility to handle draw signals on the widget. When a widget is first shown, or when it is covered and then uncovered again it needs to redraw itself. Most widgets have code to do this, but the DrawingArea does not, allowing you to write your own draw signal handler to determine how the contents of the widget will be drawn.

References to the original C documentation can be found at https://developer.gnome.org/gtk3/stable/ch24s02.html#id-1.6.3.4.11 and https://developer.gnome.org/gtk3/stable/GtkWidget.html#GtkWidget-draw

_________________
E.


Top
 Profile  
 
 Post subject: Re: GTK 3.8 Graphic programming in ADA (GtkAda)
PostPosted: Thu Jan 09, 2014 11:09 am 
Offline
Familiar Face

Joined: Fri Sep 23, 2011 12:04 pm
Posts: 28
Thank you for the answer.
I still have one problem related to this one. I am using Glade 3 for building my GUI and Gtk 3 (I think 3.4) Now can I couple with Register_Handler a handler to an event. Only That handler cannot use a second parameter (here CR). How do I couple this?

L. Dries


Top
 Profile  
 
 Post subject: Re: GTK 3.8 Graphic programming in ADA (GtkAda)
PostPosted: Sun Jan 12, 2014 10:52 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Sorry I am going to have to admit defeat here as my knowledge of Ada is very limited. When you do find a solution it would be great if you can post back here so that others can learn.

Thanks.

_________________
E.


Top
 Profile  
 
 Post subject: Re: GTK 3.8 Graphic programming in ADA (GtkAda)
PostPosted: Wed Jan 15, 2014 5:54 pm 
Offline

Joined: Wed Jan 15, 2014 4:25 pm
Posts: 1
errol wrote:
Sorry I am going to have to admit defeat here as my knowledge of Ada is very limited. When you do find a solution it would be great if you can post back here so that others can learn.

Thanks.

Agreed, any success with Ada?


Top
 Profile  
 
 Post subject: Re: GTK 3.8 Graphic programming in ADA (GtkAda)
PostPosted: Thu Jan 16, 2014 8:06 am 
Offline
Familiar Face

Joined: Fri Sep 23, 2011 12:04 pm
Posts: 28
I am trying to draw a grid on Gtk_Drawing Area. I want that drawing to
appear when then program starts before anything is done.
I can draw that grid and see it but whenever the program redraws the window
it disappears as a whole or in some cases partly. As various sources I found
out that I have to act on the draw signal. As I build my GUI with Glade 3 I
thought I could connect the drawing signal with:

Code:
Register_Handler
  (Builder      => Builder,
   Handler_Name => "On_Area_Draw", -- from XML file <signal handler=..>
   Handler      => Sudoku_Callbacks.On_Area_Draw'Access);


Where I coupled "On_Area_Draw" in Glade with the draw signal in the
Gtk_Drawing_Area. Although This was carried out case Sensitive the program
aborted. The most likely reason therefor is that the handler procedure was:

Code:
procedure On_Area_Draw (Object : access Gtkada_Builder_Record'Class);


where it should have been

Code:
function On_Area_Draw (Object : access Gtkada_Builder_Record'Class; Context
: Cairo.Cairo_Context) return boolean;


Using the last results in aborting the compilation.

The question now is how should I connect the draw signal to which
function/procedure to get a correct working program?

PS For C/C++ programmers a procedure is compatible with a void function and the function is then a bool function.

L. Dries


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group