Function:cs2shcb

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 01:01, 30 October 2007
S2plot admin (Talk | contribs)

← Previous diff
Current revision
S2plot admin (Talk | contribs)

Line 12: Line 12:
Set the handle callback function; use NULL argument to cancel the callback. The handle callback function must be of the form: Set the handle callback function; use NULL argument to cancel the callback. The handle callback function must be of the form:
 +
<tt>void cbfn(int *id)</tt> <tt>void cbfn(int *id)</tt>
 +
where id is the index of the selected handle. where id is the index of the selected handle.
 +
 +A handle is selected/deselected by clicking the <tt>RIGHT MOUSE BUTTON</tt> while the mouse cursor is over the visible handle.
== See Also == == See Also ==
<table> <table>
-<tr><td>[[Function:cs2ah | cs2ah ]]</td><td>Add a handle to allow interactive picking of objects </td></tr>+<tr><td>[[Function:cs2thv | cs2thv]]</td><td>Toggle the current state of selection handles .</td></tr>
 +<tr><td>[[Function:ss2txh | ss2txh]]</td><td>Enable/disable/toggle the visibility of the cursor cross-hair.</td></tr>
 +<tr><td>[[Function:ds2ah | ds2ah ]]</td><td>Add a handle to allow interactive picking of objects </td></tr>
<tr><td>[[Function:cs2th | cs2th ]]</td><td>Toggle the state of a named (dynamic) handle </td></tr> <tr><td>[[Function:cs2th | cs2th ]]</td><td>Toggle the state of a named (dynamic) handle </td></tr>
<tr><td>[[Function:cs2scb | cs2scb ]]</td><td>Set the callback function; can be null to cancel callback. </td></tr> <tr><td>[[Function:cs2scb | cs2scb ]]</td><td>Set the callback function; can be null to cancel callback. </td></tr>
Line 54: Line 60:
for (i=0;i<N;i++) { for (i=0;i<N;i++) {
ns2vthpoint(xyz[i], col[i], 3); /* Draw thick point */ ns2vthpoint(xyz[i], col[i], 3); /* Draw thick point */
- cs2ah(xyz[i], hsize, col[i], hilite, i, sel[i]);+ ds2ah(xyz[i], hsize, col[i], hilite, i, sel[i]);
/* Draw handles */ /* Draw handles */
} }
Line 61: Line 67:
if (sel[i]) { if (sel[i]) {
ns2vthpoint(xyz[i], col[i], 3); /* Draw thick point */ ns2vthpoint(xyz[i], col[i], 3); /* Draw thick point */
- cs2ah(xyz[i], hsize, col[i], hilite, i, sel[i]);+ ds2ah(xyz[i], hsize, col[i], hilite, i, sel[i]);
/* Draw handles */ /* Draw handles */
} }

Current revision

cs2shcb

Set the handle callback function for when a handle is (de)selected

Prototype

void cs2shcb(void *cbfn);

Description

Set the handle callback function; use NULL argument to cancel the callback. The handle callback function must be of the form:

void cbfn(int *id)

where id is the index of the selected handle.

A handle is selected/deselected by clicking the RIGHT MOUSE BUTTON while the mouse cursor is over the visible handle.

See Also

cs2thvToggle the current state of selection handles .
ss2txhEnable/disable/toggle the visibility of the cursor cross-hair.
ds2ah Add a handle to allow interactive picking of objects
cs2th Toggle the state of a named (dynamic) handle
cs2scb Set the callback function; can be null to cancel callback.
cs2sncb Set the function to call when number-keys pressed.
cs2socb Register function that will draw direct OpenGL graphics when called.


Code Example

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "s2plot.h"

#define N 100                   /* Number of points */

XYZ xyz[N];                     /* Global variable: positions */
COLOUR col[N];                  /* Colour of the point */
int sel[N];                     /* Global varibale: selected data */

void pick(int *id)
/* Callback when an item is clicked */
{
   sel[*id] = (sel[*id]+1)%2;                   /* Toggle the selection */
   cs2th(*id);                         		/* Update handle list */
}

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 */

   if ((*kc%2) == 0) {
      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 */
      }
   } else {
      for (i=0;i<N;i++) {                       /* Only show selected */
         if (sel[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 */
   float x, y, z;                               /* Random data */

   srand48((long)time(NULL));                   /* Seed random numbers */

   fprintf(stderr,"Shift-s to toggle handles\nShift-c to toggle crosshair\n");
   fprintf(stderr,"Right mouse select\nSpacebar toggle show all/show sel\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 */
   cs2shcb(&pick);                               /* Install handle callback */

   s2slw(2);                                    /* Set line width */
   for (i=0;i<N;i++) {          /* Non-selectable random data points */
      x = drand48()*2.0 - 1.0;
      y = drand48()*2.0 - 1.0;
      z = drand48()*2.0 - 1.0;
      s2sci(15*drand48() + 1);                  /* Random colour */
      s2pt1(x,y,z,1);
   }

   s2show(1);                                   /* Open the s2plot window */

   return 1;
}


Back to S2PLOT function list.


Personal tools