Function:ds2unprotect

From S2PLOT

Revision as of 04:14, 10 March 2008; view current revision
←Older revision | Newer revision→
Jump to: navigation, search

ds2unprotect

Unprotect dynamic geometry.

Prototype

void ds2unprotect(void);

Description

Unprotect the dynamic geometry. Typically use this by setting ds2protect() at the end of your standard dynamic callback, then call ds2unprotect() if key presses / events processed by other callbacks will result in a changed geometry state. Use with caution ... incorrect use can result in TMC: total memory consumption.

See Also

ds2protectProtect dynamic geometry.
ds2isprotectedQuery state of dynamic geometry protection.

Code Example

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

void ncb(int *N)
{
   int pstate = ds2isprotected();               /* What is current protection state? */

   if ((*N == 1) && (pstate == 0)) {            /* Key 1 was pressed */
      ds2protect();                             /* Protect dynamic geometry */
   }
   if ((*N == 2) && (pstate == 1)) {            /* Key 2 was pressed */
      ds2unprotect();                           /* Unprotect dynamic geometry */
   }
}

void cb(double *t, int *kc)
{
   static XYZ orbit;                            /* Position of point to draw */
   static float tt = 0;                         /* Current position in orbit */
   orbit.x = cos(tt);                           /* Update point position */
   orbit.y = sin(tt);
   tt += 0.05;

   COLOUR ocol = { 1, 1, 0 };                   /* Point colour = yellow*/
   ns2vthpoint(orbit, ocol,  3);                /* Draw the point */

   char string[32];                             /* Write instruction label */
   sprintf(string,"Press 1 to protect, press 2 to unprotect");
   s2lab("","","",string);

}

int main(int argc, char *argv[])
{
   srand48((long)time(NULL));                   /* Seed random numbers */
   s2opend("/?", argc, argv);                   /* Prompt for display type */
   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 geometry callback */
   cs2sncb(ncb);                                /* Install number key press callback */

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

   return 1;
}

Back to S2PLOT function list.


Personal tools