Function:cs2sdhcb
From S2PLOT
(Difference between revisions)
Revision as of 23:37, 27 November 2007 S2plot admin (Talk | contribs) ← Previous diff |
Revision as of 23:42, 27 November 2007 S2plot admin (Talk | contribs) Next diff → |
||
Line 10: | Line 10: | ||
==Description== | ==Description== | ||
Set the drag handle callback function; use NULL argument to cancel callback. | Set the drag handle callback function; use NULL argument to cancel callback. | ||
+ | |||
+ | The callback function must be of the form: | ||
+ | |||
+ | <tt>void dragfn(int *id, XYZ *pos)</tt> | ||
+ | |||
+ | where id is the identifier of the chosen handle and pos is a pointer to XYZ variable containing new coordinates. | ||
== See Also == | == See Also == | ||
<table> | <table> | ||
<tr><td>[[Function:ds2ah | ds2ah]]</td><td>Add a handle to allow interactive picking of objects. </td></tr> | <tr><td>[[Function:ds2ah | ds2ah]]</td><td>Add a handle to allow interactive picking of objects. </td></tr> | ||
+ | <tr><td>[[Function:cs2scb | cs2scb]]</td><td>Set the callback function. </td></tr> | ||
+ | <tr><td>[[Function:struct_XYZ | struct_XYZ]]</td><td>Data structure for (x,y,z) coordinates.</td></tr> | ||
</table> | </table> | ||
Revision as of 23:42, 27 November 2007
cs2sdhcb
Set the handle dragging callback.
Prototype
void cs2sdhcb(void *cbfn);
Description
Set the drag handle callback function; use NULL argument to cancel callback.
The callback function must be of the form:
void dragfn(int *id, XYZ *pos)
where id is the identifier of the chosen handle and pos is a pointer to XYZ variable containing new coordinates.
See Also
ds2ah | Add a handle to allow interactive picking of objects. |
cs2scb | Set the callback function. |
struct_XYZ | Data structure for (x,y,z) coordinates. |
Code Example
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"
#define N 10 /* Number of points */
XYZ xyz[N]; /* Global variable: positions */
COLOUR col[N]; /* Colour of the point */
int sel[N]; /* Global varibale: selected data */
void drag(int *id, XYZ *p) /* The drag callback */
{
xyz[*id] = *p; /* Update the dragged point's location */
}
void cb(double *t, int *kc)
{
COLOUR hilite = { 1.0, 1.0, 1.0 }; /* Highlight colour */
float hsize = 0.02; /* Size of handle */
int i; /* Loop variable */
for (i=0;i<N;i++) {
ns2vthpoint(xyz[i], col[i], 3); /* Draw thick point */
ds2ah(xyz[i], hsize, col[i], hilite, i, sel[i]); /* Draw handles */
}
}
int main(int argc, char *argv[])
{
int i; /* Loop varibale */
srand48((long)time(NULL)); /* Seed random numbers */
fprintf(stderr,"Shift and right mouse click to drag a handle\n");
s2opend("/?",argc, argv); /* Open the display */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
for (i=0;i<N;i++) { /* Set-up globals */
xyz[i].x = drand48()*2.0 - 1.0; /* Random position */
xyz[i].y = drand48()*2.0 - 1.0;
xyz[i].z = drand48()*2.0 - 1.0;
col[i].r = drand48(); /* Random colour */
col[i].g = drand48();
col[i].b = drand48();
sel[i] = 0; /* Not currently selected */
}
cs2scb(&cb); /* Install dynamic callback */
cs2sdhcb(&drag); /* Install handle dragging callback */
cs2thv(1); /* Make handles visible */
ss2txh(1); /* Make crosshairs visible */
s2show(1); /* Open the s2plot window */
return 1;
}
Back to S2PLOT function list.