Function:cs2spcb

From S2PLOT

(Difference between revisions)
Jump to: navigation, search

Revision as of 22:02, 3 December 2007

cs2spcb

Set the user prompt callback.

Prototype

void cs2spcb(void *pcbfn, void *data);

Description

Set the callback function for the prompt functionality. When the users presses '~', a prompt is placed on screen and they can type input. When ENTER is pressed, the registered callback is called with the command string as argument. If ESC is pressed instead, the prompt is dropped.


See Also

cs2scbSet the callback funciton.

Code Example

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

/* Global variable */
float r = 0, g = 0, b = 0;                      /* Background colour */

void pcb(char *string)
{
   int res;                                     /* How many numbers entered? */
   float rr, gg, bb;                            /* Local variables */
   res = sscanf(string,"%f %f %f",&rr,&gg,&bb); /* Read from prompt string */
   if (res == 3) {
      r = rr;                                   /* Change background colour */
      g = gg;
      b = bb;
   }
}

void cb(double *t, int *kc)
{
   ss2sbc(r, g, b);                             /* Set background colour */
   ss2sfc(1-r, 1-g, 1-b);                       /* Choose sensible foreground */
   s2scr(32, 1-r, 1-g, 1-b);                    /* Create a new colour index */
   s2sci(32);                                   /* Set colour to this index */
   s2textxy(-1,0,0,"Press ~ then enter R G B values e.g 1 1 1");
                                                /* Write some text */
}

int main(int argc, char *argv[])
{
   s2opend("/s2mono", argc, argv);             /* Open in mono mode */
   s2swin(-1.,1., -1.,1., -1.,1.);              /* Set the window coordinates */
   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

   cs2scb(cb);                                  /* Install dynamic callback */

   char string[32];                             /* Allocate prompt string memory */
   cs2spcb(pcb, string);                        /* Install a prompt callback */

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

   return 1;
}

Back to S2PLOT function list.


Personal tools