Re: XForms: aligning positioner to xyplot

Steve Lamont (spl@szechuan.ucsd.edu)
Sun, 4 Jan 98 18:50:58 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I tested this, and found setting positioner->bw = 0
> makes everything all right. I think in your
> test code, you might've used fl_set_object_bw(ob, 0),
> which unfortunately does not work as that function
> ignores 0 border width request.

Nope, I didn't.

Here's a piece of test code which should illustrate the behavior.

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

#ifndef FD_try_h_
#define FD_try_h_
/* Header file generated with fdesign. */

/** Callback routines and free object handlers **/

extern void positioner_cb(FL_OBJECT *, long);

/**** Forms and Objects ****/

typedef struct {
FL_FORM *try;
void *vdata;
char *cdata;
long ldata;
FL_OBJECT *xyplot;
FL_OBJECT *positioner;
} FD_try;

extern FD_try * create_form_try(void);

#endif /* FD_try_h_ */

void positioner_cb( FL_OBJECT *obj, long data )

{

double x = fl_get_positioner_xvalue( obj );
double xmin;
double xmax;
double y = fl_get_positioner_yvalue( obj );
double ymin;
double ymax;
double a;
double b;
FL_Coord sx;
FL_Coord sy;
int mask;
float wx;
float wy;

fl_get_positioner_xbounds( obj, &xmin, &xmax );
fl_get_positioner_ybounds( obj, &ymin, &ymax );

/*
* Algorithmically generate positions.
*/

a = obj->w / ( xmax - xmin );
b = obj->x - ( a * xmin );
sx = ( x * a ) + b + 0.5; /* Round */

a = obj->h / ( ymin - ymax );
b = obj->y - ( a * ymax );
sy = ( y * a ) + b + 0.5; /* Round */

fl_xyplot_s2w( ( ( FD_try *) obj->form->fdui )->xyplot,
( double ) sx, ( double ) sy,
&wx, &wy );
fprintf( stderr, "%d,%d -> %g,%g / ", sx, sy, wx, wy );

/*
* Brute force.
*/

fl_get_form_mouse( obj->form, &sx, &sy, &mask );

fl_xyplot_s2w( ( ( FD_try *) obj->form->fdui )->xyplot,
( double ) sx, ( double ) sy,
&wx, &wy );
fprintf( stderr, "%d,%d -> %g,%g\n", sx, sy, wx, wy );

}

FD_try *create_form_try(void)
{
FL_OBJECT *obj;
FD_try *fdui = (FD_try *) fl_calloc(1, sizeof(*fdui));

fdui->try = fl_bgn_form(FL_NO_BOX, 630, 480);
obj = fl_add_box(FL_UP_BOX,0,0,630,480,"");
fdui->xyplot = obj = fl_add_xyplot(FL_NORMAL_XYPLOT,100,120,470,240,"");
fdui->positioner = obj = fl_add_positioner(FL_OVERLAY_POSITIONER,100,120,470,240,"");
fl_set_object_callback(obj,positioner_cb,0);
fl_end_form();

fdui->try->fdui = fdui;

return fdui;
}
/*---------------------------------------*/

int main(int argc, char *argv[])

{

FD_try *fd_try;
static float x[2] = { -1.0, 1.0 };
static float y[2] = { 1.0, -1.0 };

fl_initialize(&argc, argv, 0, 0, 0);
fd_try = create_form_try();

fd_try->positioner->bw = 0;
fd_try->xyplot->bw = 0;
fl_set_xyplot_data( fd_try->xyplot,
x, y, 2,
"Try", "X", "Y" );

fl_show_form(fd_try->try,FL_PLACE_CENTERFREE,FL_FULLBORDER,"try");
fl_do_forms();
return 0;

}
- - -

Another observation: When the form is resized, neither method gives
the right answer!

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bloch.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/