# To subscribers of the xforms list from Ivan Powis <Ivan.Powis@nottingham.ac.uk> :
>
> # To subscribers of the xforms list from Steve Lamont <spl@ncmir.ucsd.edu> :
>
> > I am trying to come up with a zoom in feature on my XY Plots that I
> > use for analysis purposes. I know what to do about zooming in on an
> > area but I'm having trouble trying to figure out how I can visually
> > highlight an area in the XY Plot in XFORMS with the mouse. I'm not
> > sure whether this capability is in XFORMS or not but I thought I
> > would ask.
>
Here is a rubber banding routine implemented as a posthandler
which i use a lot. I've quickly hacked it from my sources, so
there may be extraneous bits ... but I hope that there is
sufficient to make clear whats happening
.........
/*--- Data structures used by interface ---*/
typedef struct{
FL_COORD ox, oy; /* starting x,y */
FL_COORD dx, dy; /* last displacement */
float wx,wy;
int drawn; /* flag set while box displayed */
} XY_RBAND; /* SUPPORT FOR RUBBER BANDING */
.......
static char rcsid[]=
"$Header: srsgui_cb.c,v 1.6 00/03/16 16:01:27 pczip Exp $";
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
.......
/*------------------------------------------------------------*/
/*--- pph Post handler for xyplots with rubber banding ---*/
/*--- Assumes plot->u_vdata points to an XY_RBAND struct ---*/
/*------------------------------------------------------------*/
int pph(FL_OBJECT *ob, int ev, FL_Coord mx, FL_Coord my, int key, void *xev)
{
#define CLR FL_GREEN
XY_RBAND *rbc = (XY_RBAND *) ob->u_vdata;
SRS *s = (SRS *) ob->u_cdata;
float wx0,wx1,wy0,wy1;
float wx,wy;
char buf[50];
FL_Coord dx,dy;
unsigned keymask;
int i, dmode;
dmode=fl_get_drawmode();
switch(ev){
case FL_ENTER:
fl_set_cursor(FL_ObjWin(ob),XC_crosshair);
break;
case FL_MOTION: /* show one liner */
fl_xyplot_s2w(ob,mx,my,&wx,&wy);
sprintf(buf,"%.2f eV",wx);
fl_show_oneliner(buf,ob->x + ob->form->x, ob->y+ob->form->y-20);
break;
case FL_LEAVE:
fl_hide_oneliner();
fl_reset_cursor(FL_ObjWin(ob));
break;
case FL_PUSH: /* button pressed */
if(rbc->drawn){ /* deal with existing rbanded region */
fl_drawmode(GXxor); /* visually erase box */
fl_rectf(rbc->ox,rbc->oy,rbc->dx,rbc->dy,CLR);
fl_drawmode(dmode);
/* get real coordinates of existing box */
fl_xyplot_s2w(ob,rbc->ox,rbc->oy,&wx0,&wy0);
fl_xyplot_s2w(ob,rbc->ox+rbc->dx,rbc->oy+rbc->dy,&wx1,&wy1);
if( wx1 < wx0 ){ wy0=wx0; wx0=wx1; wx1=wy0;} /* re-order */
switch (key){
case FL_LEFT_MOUSE: /* exclude */
for(i=0;i<s->npts;i++){
if(s->be[i] <= wx1 && s->be[i] >= wx0 ) s->ig[i]=(short) OFF;
}
edc_plot(ob, s); /*replot data */
break;
case FL_RIGHT_MOUSE: /* include */
for(i=0;i<s->npts;i++){
if(s->be[i] <= wx1 && s->be[i] >= wx0 ) s->ig[i]=(short) ON;
}
edc_plot(ob, s); /*replot data */
break;
case FL_MIDDLE_MOUSE: /* cancel */
break;
}
}
rbc->ox=mx;
rbc->oy=my;
fl_xyplot_s2w(ob,mx,my,&rbc->wx,&rbc->wy);
rbc->drawn=0;
break;
case FL_MOUSE: /* dragging */
fl_drawmode(GXxor);
if(rbc->drawn){ /* erase old box */
fl_rectf(rbc->ox,rbc->oy,rbc->dx,rbc->dy,CLR);
}
rbc->dx=mx - rbc->ox;
rbc->dy=my - rbc->oy;
fl_rectf(rbc->ox,rbc->oy,rbc->dx,rbc->dy,CLR); /* draw new box */
rbc->drawn=TRUE;
fl_drawmode(dmode);
fl_xyplot_s2w(ob,mx,my,&wx,&wy);
sprintf(buf,"%.3f :: %.3f eV",rbc->wx, wx);
fl_show_oneliner(buf,ob->x + ob->form->x, ob->y+ob->form->y-20);
break;
case FL_RELEASE:
switch (key){
case FL_LEFT_MOUSE:
fl_get_mouse(&dx, &dy, &keymask);
if (keymask & ShiftMask){
psdump(ob);
return 0;
}
break;
case FL_RIGHT_MOUSE:
break;
case FL_MIDDLE_MOUSE:
break;
default:
printf("LM=%x, MM=%x RM=%x that was %x event flmouse() %x!\n",
FL_LEFT_MOUSE, FL_MIDDLE_MOUSE, FL_RIGHT_MOUSE,key,
fl_mouse_button());
return 0;
}
break;
}
return 0;
}
-- -------------------------------------------------------------------- ___ ___/ _ __ / Ivan Powis [Ivan.Powis@Nottingham.ac.uk] / / / School of Chemistry / / _/ University of Nottingham / ___/ Nottingham NG7 2RD, UK / / TEL: +44-115-951-3467 / / FAX: +44-115-951-3562 _______/ ____/ http://www.chem.nott.ac.uk/IP.html --------------------------------------------------------------------_________________________________________________ To unsubscribe, send the message "unsubscribe" to xforms-request@bob.usuhs.mil or see http://bob.usuhs.mil/mailserv/xforms.html XForms Home Page: http://world.std.com/~xforms List Archive: http://bob.usuhs.mil/mailserv/list-archives/
This archive was generated by hypermail 2b29 : Thu Nov 30 2000 - 12:17:50 EST