Function:cs2sptxy

From S2PLOT

Revision as of 03:50, 29 August 2011; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

cs2sptxy

Set the text and position of a prompt.

Prototype

void cs2sptxy(char *prompt, float xfrac, float yfrac);

Description

Set the text and position of the prompt. xfrac and yfrac are fractions of the viewport from bottom left.

See Also

cs2spcbSet the user prompt callback.

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;
   }

/* Change where the prompt appears next time */
   float px = drand48()*0.6 + 0.2;
   float py = drand48()*0.6 + 0.2;

   cs2sptxy("R G B >", px, py);
}

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

   s2lab("","","","Demonstrates positioning of the prompt");

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

   return 1;
}

Back to S2PLOT function list.


Personal tools