[Top][All Lists]

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

Re: [XForms] positioner

From: Jens Thoms Toerring
Subject: Re: [XForms] positioner
Date: Fri, 6 Apr 2012 23:41:47 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

Hi Al,

On Fri, Apr 06, 2012 at 04:23:16PM +0200, alessandro basili wrote:
> is there a way to have two cross-hair cursors in the positioner?
> I'd like to use it to zoom in and out in a 2d picture.

Sorry, but there's only a single cross-hair to a positioner.
Otherwise this would be a rather different object, e.g. you
would need additional functions to switch which of the
tow cross-hairs is controlled by the mouse at a certain

The simplest way to "fake" it might be to draw something
that looks like the cross-hair when the first point has
been selected and then use the same positioner to have
the user select the econd position. Question is what
kind of event you consider to indicate that the user
has selected the first point. It probably will be the
moment the user releases the mouse button. Now to be
able to figure out when that happened I think you need
a newer version of XForms than 1.0.92, since before
that the positioner object only returned when the
mouse position had changed, but not when the mouse
button was released. With newer versions you now can
adjust under which circumstances the positioner re-
turns (or when its callback is called). To do so
you'd use

fl_set_object_return( obj, FL_RETURN_CHANGED | FL_RETURN_END );

This makes the positioner return (or call its callback) not
only on changes of the mouse position but also on the end
of the interaction, i.e. when the mouse button becomes

To find out for what reason the positionrt returnred (or
called its callback) you then can use

fl_get_object_return_state( obj );

And if you're interested into the end of the interaction
you would do

   if ( fl_get_object_return_state( obj ) & FL_RETURN_END )

Now, in there you could draw the "fake" cross-hair at the
positioners position and then start interpreting the next
sequence of events as the selection of the second point.

Instead of "faking" the cross-hair you could also try to
put two positioners on top of each other and deactivate
one of them at first, and, when the one still active is
finished, deactivate it and activate the one previously

I've been playing around with that second idea and it seems
to work, though there seem to be some problems with the
redraw of the deactivated positioner I haven't tracked down
yet (I have some idea but didn't have to time to look into
it any further). I append that test program (based on the
positioner.c demo program) anyway, perhaps some of it is
of some help to you.

But mind, this won't work with version 0.89 (and even some
newer ones, I think you need at least 1.0.92).

                         Best regards, Jens


#include <stdio.h>
#include "forms.h"

static FL_OBJECT * xval,
                 * yval;
static FL_OBJECT * pos1,
                 * pos2;


static void
positioner_cb( FL_OBJECT * obj,
               long        data )
    char str[ 30 ];

    sprintf( str, "%f", fl_get_positioner_xvalue( obj ) );
    fl_set_object_label( xval, str );
    sprintf( str, "%f", fl_get_positioner_yvalue( obj ) );
    fl_set_object_label( yval, str );

    if ( fl_get_object_return_state( obj ) & FL_RETURN_END )
        if ( data == 0 )
            fl_deactivate_object( pos1 );
            fl_activate_object( pos2 );
            fl_deactivate_object( pos2 );
            fl_activate_object( pos1 );


main( int    argc,
      char * argv[ ] )
    FL_FORM   * form;

    fl_initialize( &argc, argv, "FormDemo", 0, 0 );

    form = fl_bgn_form( FL_UP_BOX, 400, 280 );

    pos1 = fl_add_positioner( FL_NORMAL_POSITIONER, 40, 40, 200, 200, "" );
    fl_set_positioner_xbounds( pos1, 0, 1 );
    fl_set_positioner_ybounds( pos1, 0, 1 );
    fl_set_object_callback( pos1, positioner_cb, 0 );
    fl_set_object_return( pos1, FL_RETURN_CHANGED | FL_RETURN_END );
    fl_deactivate_object( pos1 );

    pos2 = fl_add_positioner( FL_OVERLAY_POSITIONER, 40, 40, 200, 200, "" );
    fl_set_positioner_xbounds( pos2, 0, 1 );
    fl_set_positioner_ybounds( pos2, 0, 1 );
    fl_set_object_callback( pos2, positioner_cb, 1 );
    fl_set_object_color( pos2, FL_YELLOW, FL_YELLOW );
    fl_set_object_return( pos2, FL_RETURN_CHANGED | FL_RETURN_END );

    xval = fl_add_box( FL_DOWN_BOX, 270, 40, 100, 30, "" );
    fl_set_object_color( xval, FL_COL1, FL_COL1 );

    yval = fl_add_box( FL_DOWN_BOX, 270, 90, 100, 30, "" );
    fl_set_object_color( yval, FL_COL1, FL_COL1 );

    fl_add_button( FL_NORMAL_BUTTON, 270, 210, 100, 30, "Exit" );

    fl_end_form( );

    fl_show_form( form, FL_PLACE_CENTER, FL_NOBORDER, "positioner2" );

    fl_do_forms( );
    fl_hide_form( form );
    fl_finish( );

    return 0;


  \   Jens Thoms Toerring  ________      address@hidden
   \_______________________________      http://toerring.de

reply via email to

[Prev in Thread] Current Thread [Next in Thread]