comp.lang.ada
 help / color / mirror / Atom feed
From: hreba <f_hreba@yahoo.com.br>
Subject: Re: Where do I get my Cairo context from (in GTK3)?
Date: Wed, 27 Apr 2016 15:15:40 +0200
Date: 2016-04-27T15:15:40+02:00	[thread overview]
Message-ID: <dobsbsF3o8rU1@mid.individual.net> (raw)
In-Reply-To: <31e4394b-eb85-4d31-bd25-f2bd332c7c9b@googlegroups.com>

On 04/27/2016 09:47 AM, briot.emmanuel@gmail.com wrote:
>> I would use On_* procedures if I didn't need user data. Until now no
>> success.
>
> Are you sure you really need that user data ? In my experience, it is often
> better to extend the widget type in your application, store whatever information
> is needed in that child type, and then use the On_* procedure passing a Slot
> object (so that the callback receives your widget type, rather than the widget
> on which the action occurred). This works in 95% of the cases.
>
> The GNAT Development Studio (GPS), which is about 500_000 lines of code
> has almost no use of user data, and those that remain are mostly because
> that part of the code hasn't been updated yet.
>

I am creating a drawing surface, a new layer for isolating the end user 
from GTK. The idea is that the end user gets a constructor for a new 
type "Canvas". He has to specify 3 handlers: the first is called once 
after the canvas appears on the screen, the second is called after each 
resizing, the third one when the canvas needs redrawing. Drawing is done 
by calling a series of of standardized drawing procedures (for lines, 
arcs etc.) The end user needs no knowledge about connecting handlers, 
about cairo contexts or "Stroke" calls. He gets a framework for 
technical drawings with a simple user interface.

The drawing handler at the end user level is a subprogram with basically 
one parameter: the user data which specifies what has to be drawn. I am 
implementing the framework and I don't now what the end user will draw, 
so I write a GTK "draw" handler which calls the handler of the end user 
and passes the end user's data.

Probably I will never do it, but in principle the framework could be 
implemented with other graphics toolkits than GTK and the end user would 
have the same API.

Meanwhile I have found a solution for my problem. It compiles but is not 
tested yet. It doesn't use a marshaller:

--
    package DA_Ret_Callback is new Gtk.Handlers.User_Return_Callback
      (Gtk.Drawing_Area.Gtk_Drawing_Area_Record, Boolean, Handler_DataD);

    function Draw_Handler
      (da: access Gtk.Drawing_Area.Gtk_Drawing_Area_Record'Class;
       pars: Glib.Values.GValues;
       hd: Handler_DataD) return Boolean is
    begin
       hd.can.cc:= Cairo.Get_Context (Glib.Values.Nth(pars, 1));
       hd.Draw (hd.data, hd.gads);
       return True;	-- don't propagate signal further
    end Draw_Handler;

    procedure Connect_Handlers
      (obj: Glib.Object.GObject; hd: Handler_DataD;
       sn_realize, sn_config, sn_draw: Glib.Signal_Name) is
    begin
       ...
       DA_Ret_Callback.Connect
	(Gtk.Drawing_Area.Gtk_Drawing_Area(obj),
	 sn_draw, Draw_Handler'Access, hd);
    end Connect_Handlers;
-- 

hd.Draw is the drawing handler of the end user, and hd.data is the end 
user's data.

-- 
Frank Hrebabetzky		+49 / 6355 / 989 5070


  parent reply	other threads:[~2016-04-27 13:15 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-04-24 20:44 Where do I get my Cairo context from (in GTK3)? hreba
2016-04-25  7:40 ` Dmitry A. Kazakov
2016-04-25 10:03   ` hreba
2016-04-25 11:58     ` Dmitry A. Kazakov
2016-04-26  7:22       ` briot.emmanuel
2016-04-26  7:34         ` hreba
2016-04-27  7:47           ` briot.emmanuel
2016-04-27  8:08             ` Dmitry A. Kazakov
2016-04-28  7:48               ` briot.emmanuel
2016-04-27 13:15             ` hreba [this message]
2016-04-27 13:37               ` Dmitry A. Kazakov
2016-04-28  7:49                 ` briot.emmanuel
2016-08-05 15:56 ` borisgaertner56
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox