Re: [gtk-list] signals, objects, user_data and stuff.



Add to the connector a list of connected points (identified by a number)
check within the signal callback if the point is connected and move it
if it is.

Jeroen

Thomas Mailund wrote:
> 
> Hi all.
> 
> I'm messing around with signals right now, and I've run into the
> following problem.  I need to connect a signal, as in
> 'connect_object', but I want to pass user data along with the signal,
> as in the usual signal_connect.  I can probably get around this using
> a struct and put the stuff I need into that, but it'll get quite ugly
> for my current situation and I'm looking for a more elegant solution.
> 
> A little context for the problem:  I have a gnome canvas where I've
> drawn a number of "nodes", items which I can move around, and a number
> of "connectors", lines connecting the nodes.  For the nodes I've
> subclassed the canvas item and added the signal "moved" which is
> emitted whenever I move the node.  My connectors listens for these
> signals, so they will be informed when one of their endpoints move.
> So I can do something like
> 
>   gtk_signal_connect_object (GTK_OBJECT (node), "moved",
>                              GTK_SIGNAL_FUNC (connector_moved),
>                              GTK_OBJECT (connector));
> 
> where the callback moves the connector
> 
> static void
> connector_moved (Connector *conn, gdouble dx, gdouble dy)
> {
>   <<move "the right" point>>
> }
> 
> (here the (dx,dy) are parameters from the nodes "moved" signal).
> 
> Of course, getting "the right point" is the tricky one.  If I only
> have two points on a connector, i.e. connectors are straight lines
> between nodes, I can hack it doing something like
> 
>   gtk_signal_connect_object (GTK_OBJECT (node1), "moved",
>                              GTK_SIGNAL_FUNC (connector_moved1),
>                              GTK_OBJECT (connector));
>   gtk_signal_connect_object (GTK_OBJECT (node2), "moved",
>                              GTK_SIGNAL_FUNC (connector_moved2),
>                              GTK_OBJECT (connector));
> 
> static void
> connector_moved1 (Connector *conn, gdouble dx, gdouble dy)
> {
>   connector_move_point (conn, 1);
> }
> 
> static void
> connector_moved2 (Connector *conn, gdouble dx, gdouble dy)
> {
>   connector_move_point (conn, 2);
> }
> 
> It's not nice, but it would work.  But if I add bend points to
> connectors it gets tricky.  Then I need a special callback for each
> bend point, just to pass an integer parameter along.  If I don't know
> the number of bend points statically (which I don't, since the
> connectors are read in from a file) I don't see how I can do this.
> 
> Does anyone have any suggestions on how to achieve what I want here?
> Either getting the extra parameter passed along or perhaps redesigning
> it all and do something more clever?
> 
>         /mailund
> 
> --
> To unsubscribe: mail -s unsubscribe gtk-list-request@redhat.com < /dev/null



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]