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: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.mb-net.net!open-news-network.org!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 19:10:16 +0100 Organization: cbb software GmbH Message-ID: References: <52c69509$0$22518$703f8584@news.kpn.nl> <52c90da6$0$13838$703f8584@textnews.kpn.nl> <52c98c95$0$10508$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 Xref: news.eternal-september.org comp.lang.ada:18123 Date: 2014-01-05T19:10:16+01:00 List-Id: On Sun, 5 Jan 2014 17:45:32 +0100, ldries46 wrote: > "Dmitry A. Kazakov" schreef in bericht > news:z154dfja3q0m.17hbcu4i3o1u8.dlg@40tude.net... > > On Sun, 5 Jan 2014 08:43:58 +0100, ldries46 wrote: > >> First of all, where did you get GtkAda 3.8? > > I probably get all different versions mixed up. Possibly a mix-up of > versions of GTK, GtkAda and Glade. I am sorry if this made it difficult for > you. That won't work. I tested GtkAda 3.4 mixed with GTK+ 3.6, 3.8, 3.10 from various builds, they do not work together. Even if it appears working it has serious problems like heap corruption and failures in Ada exception propagation. > I wanted a standard grid in the window at the moment of initialization. This > meant that the first try was the drawing procedure using before I carried > out Gtk.Main.Main. It does not work this way. You should never draw directly into a window. > By inserting a breakpoint just before this point I found > the grid was visible but it vanished when I executed the next step. > My next step was putting the routine in the callback procedure from > File/New. Now also the grid became visible except for the part that was > under the pull-down menu from File. Because it gets drawn over by the default handler. This is why you must override the handler. > All this means that I am missing the part that fixes the grid in the > Gtk_Drawing_Area. See: https://developer.gnome.org/gtk3/3.2/GtkWidget.html#GtkWidget-draw >> You could use Stroke once. > > It is nice to find that only one Stroke is necessary. But in the Testcairo > example in the GTK distribution also more stroke routines are used. Single Stroke is more efficient. You should also take care about line alignments. When you draw vertical or horizontal lines at whole pixel positions, as you do, lines get blurred due to aliasing. In order to draw sharp lines you should draw at the positions "between" the pixels, e.g. at 1.5 instead of 1.0. >> Yes, the drawing model is event-driven. You must draw from the signal >> handler. > > Firstly the initial grid is never drawn from a event so there should be an > event handler which is triggered by starting the program. Of course it gets drawn. First, when you call Show on the widget, and then any time the widget contents gets exposed. >> 1. You should derive your widget from Gtk_Drawing_Area_Record > > With glade3 I get the drawing area with > > Object := Get_Object (Builder, "My_drawing_area"); > My_Area := Gtk_Drawing_Area(Object); I cannot comment on Glade, I have no idea what it does under the hood (and why people are so obsessed with it). Anyway, the relevant documentation about GtkDrawingArea is here: https://developer.gnome.org/gtk3/stable/GtkDrawingArea.html It contains description of the "draw" signal and a small sample. Note that though it also refers to "configure-event", that signal cannot be caught and thus cannot be handled. Widget resizing is dealt with by other means. >> 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; > > I think initialization is also done in this case. The draw function I could > not find but. The Draw function is the callback you have to declare and implement. It is then connected to "draw." See On_Draw in Gtk.Widget. You can use it in order to connect your Draw to the signal. The corresponding access to function type is named Cb_Gtk_Widget_Cairo_Context_Boolean. In the same package. >From Initialize, you would do: procedure Initialize (Widget : not null access My_Custom_Draw_Record'Class, ...) is begin ... -- Registering the class, initialization of the parent ... Widget.On_Draw (Draw'Access); -- Connect to the signal end Initialize; This is the simplest way, but it will require a type conversion of the first argument of Draw. So if you don't like casts, you should instantiate Return_Callback from Gtk.Handlers this way: package Return_Boolean_Callback is new Gtk.Handlers.Return_Callback (My_Custom_Draw_Record, Boolean); And connect to the signal so: Return_Boolean_Callback.Connect ( Widget, "draw", Return_Boolean_Callback.To_Marshaller (Draw'Access), True ); >> 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 will study your link and hopes that I can conclude my program soon Remember, that the latest published version of AICWL is for GtkAda 2.24. GtkAda 3.x is *significantly* different with regard to drawing and the procedure of registering a custom widget. You cannot use this code as a sample for GtkAda 3.x! Furthermore, if your GtkAda is 3.4 you would wasting your time, because, as I said, AdaCore screwed it again in the parts you would use in your widget. You should start with 3.8 and hope that they stop changing interfaces. Presently I see no other alternative as to wait for GNAT GPL 2014... (:-() -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de