Function:cs2spcb
From S2PLOT
(Difference between revisions)
Revision as of 22:03, 3 December 2007 S2plot admin (Talk | contribs) ← Previous diff |
Current revision S2plot admin (Talk | contribs) |
||
Line 22: | Line 22: | ||
<table> | <table> | ||
<tr><td>[[Function:cs2scb | cs2scb]]</td><td>Set the callback funciton.</td></tr> | <tr><td>[[Function:cs2scb | cs2scb]]</td><td>Set the callback funciton.</td></tr> | ||
+ | <tr><td>[[Function:cs2sptxy | cs2sptxy]]</td><td>Set the text and position of a prompt.</td></tr> | ||
</table> | </table> | ||
Current revision
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.
The callback function must be of the form:
void promptcb(char *string);
Sufficient space must be allocated for the input string, otherwise a segmentation fault will result.
See Also
cs2scb | Set the callback funciton. |
cs2sptxy | Set the text and position of a prompt. |
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.