Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[XForms] positioner

0 views
Skip to first unread message

alessandro basili

unread,
Apr 6, 2012, 10:23:25 AM4/6/12
to Development with and of XForms
Dear all,

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.

Any ideas and or examples?
Best,

Al

Jens Thoms Toerring

unread,
Apr 6, 2012, 5:42:01 PM4/6/12
to Development with and of XForms
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
time.

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
released.

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
deactivated.

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

-----------------8<----------------------------------------

#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 );
}
else
{
fl_deactivate_object( pos2 );
fl_activate_object( pos1 );
}
}
}

/***************************************
***************************************/

int
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;
}

-----------------8<----------------------------------------

--
\ Jens Thoms Toerring ________ j...@toerring.de
\_______________________________ http://toerring.de

alessandro basili

unread,
Apr 7, 2012, 4:01:27 PM4/7/12
to xforms-de...@nongnu.org
On 4/6/2012 11:41 PM, Jens Thoms Toerring wrote:
> 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
> time.

well, the idea was to have each cross-hair controlled by one mouse
button. The approach was kind of natural to me since I was used to an
EDA tool for circuits simulations which allowed to have the cross-hair
moving independently.
[...]
> 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
> deactivated.

that sounds interesting, I will try that.
Indeed another idea come to mind, instead of having the two cross-hair I
may have a zoom and a positioner. The latter would only take care about
moving around the picture, while the former would be needed for the
zooming functionality. In this case drawing a square, showing the zoomed
area, around the cross-hair would facilitate the usage, but I guess is
not necessary.

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

One of the biggest problem I have now is to find the documentation
matching to our release (which is 1.0 - released december 2002). Any
reference online would be appreciated.

Jens Thoms Toerring

unread,
Apr 7, 2012, 4:38:26 PM4/7/12
to Development with and of XForms
Hi Al,

On Sat, Apr 07, 2012 at 10:01:12PM +0200, alessandro basili wrote:
> One of the biggest problem I have now is to find the documentation
> matching to our release (which is 1.0 - released december 2002). Any
> reference online would be appreciated.

As far as I know there were no new releases of the docu-
mentation after the one for 0.89 (the sources for the
documentation never became available so it couldn't
easily be changed). And that version can still be
downloaded from the Savannah download area as the
files

http://download.savannah.gnu.org/releases/xforms/forms.ps.gz
http://download.savannah.gnu.org/releases/xforms/forms_sngl.ps.gz

Since they're PostScript files and thus don't have any
links I can also send you a HTML version of the 0.88 docu-
mentation which I found somewhere on the net, just send
me an email and I send them over to you.

Best regards, Jens
0 new messages