From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-0.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 Path: border1.nntp.dca3.giganews.com!backlog3.nntp.dca3.giganews.com!border3.nntp.dca.giganews.com!border1.nntp.dca.giganews.com!nntp.giganews.com!goblin2!goblin.stu.neva.ru!aioe.org!.POSTED!not-for-mail From: "Dmitry A. Kazakov" Newsgroups: comp.lang.ada Subject: Re: GTK 3.8 Graphic programming Date: Sun, 5 Jan 2014 10:12:21 +0100 Organization: cbb software GmbH Message-ID: References: <52c69509$0$22518$703f8584@news.kpn.nl> <52c90da6$0$13838$703f8584@textnews.kpn.nl> Reply-To: mailbox@dmitry-kazakov.de NNTP-Posting-Host: SACMYH1Y5pIOuwuZn7n4NQ.user.speranza.aioe.org Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Complaints-To: abuse@aioe.org User-Agent: 40tude_Dialog/2.0.15.1 X-Notice: Filtered by postfilter v. 0.8.2 X-Original-Bytes: 4035 Xref: number.nntp.dca.giganews.com comp.lang.ada:184355 Date: 2014-01-05T10:12:21+01:00 List-Id: On Sun, 5 Jan 2014 08:43:58 +0100, ldries46 wrote: > I am trying to learn myself simple graphical programming in GTK 3.8 > (GtkAda). First of all, where did you get GtkAda 3.8? The GNAT GPL 2013 version is 3.4. The latest official Windows GTK+ release is 3.6. GtkAda 3.x was never packaged for Linux. The actual GTK+ version for Linux is 3.10. [ OT: I tried to build Gtk 3.11 from sources under MinGW. It is a huge work, because they do not compile without bootstrapping and modification of both code and auto-configuration files. Neither the latest GtkAda 3.8 does compile under MinGW. After much fixing, I managed to compile both using gcc 3.7 (from GNAT GPL) or 3.8 (form MinGW), but the result is appalling. It either does not link or there are problems with handling exceptions which crash the program. It is far beyond my knowledge of gcc's internals to fix this mess. ] > 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 > > 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; You could use Stroke once. > The result is still an empty drawing area. The back round is still white > (Should be red) the lines are invisisble > I still am missing something. Yes, the drawing model is event-driven. You must draw from the signal handler. 1. You should derive your widget from Gtk_Drawing_Area_Record type My_Custom_Drawn_Widget_Record is new Gtk_Drawing_Area_Record with ... 2. In the implementation of Initialize (which you call from widget's Gtk_New) you connect to the signal "draw". The profile is: function Draw ( Widget : access My_Custom_Drawn_Widget_Record'Class; Context : Cairo.Cairo_Context ) return Boolean; Caution! AdaCore changed the interface yet again since 2.24 and then 3.4. See Glib.Object for the procedure of registering the widget's class record and its type. 3. From Draw you perform whatever drawing you wanted on Context, which is already clipped. Use Get_Allocation to obtain actual widget sizes. P.S. The described method works fine with GtkAda 3.4 and used here: http://www.dmitry-kazakov.de/ada/aicwl.htm I don't publish the version for GTK 3.x because no GtkAda is available. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de