Function:ds2unprotect

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 03:31, 10 March 2008
S2plot admin (Talk | contribs)

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

Line 19: Line 19:
==Code Example== ==Code Example==
<code><pre> <code><pre>
 +#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 */
 +
 +}
 +
 +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 */
 +
 + char string[32]; /* Write instruction label */
 + sprintf(string,"Press 1 to protect, press 2 to unprotect");
 + s2lab("","","",string);
 +
 + s2show(1); /* Open the s2plot window */
 +
 + return 1;
 +}
 +
</pre></code> </pre></code>
[[S2PLOT:Function List | Back]] to S2PLOT function list. [[S2PLOT:Function List | Back]] to S2PLOT function list.
__NOTOC__ __NOTOC__
__NOEDITSECTION__ __NOEDITSECTION__

Current revision

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

}

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

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

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

   return 1;
}

Back to S2PLOT function list.


Personal tools