Function:xs2qpa

From S2PLOT

(Difference between revisions)
Jump to: navigation, search
Revision as of 03:45, 4 December 2007
S2plot admin (Talk | contribs)

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

Line 13: Line 13:
== See Also == == See Also ==
<table> <table>
-<tr><td>[[Function:s2open | s2open]]</td><td>. </td></tr>+<tr><td>[[Function:xs2cp | xs2cp]]</td><td>Select a panel for subsequent geometry calls.</td><td> </td></tr>
 +<tr><td>[[Function:xs2ap | xs2ap]]</td><td>Add a new panel.</td><td> </td></tr>
 +<tr><td>[[Function:xs2mp | xs2mp]]</td><td>Modify location of existing panel.</td><td> </td></tr>
 +<tr><td>[[Function:xs2tp | xs2tp]]</td><td>Toggle visibility of panel.</td><td> </td></tr>
 +<tr><td>[[Function:xs2lpc | xs2lpc]]</td><td>Link panel cameras together.</td><td> </td></tr>
 +<tr><td>[[Function:xs2qsp | xs2qsp]]</td><td>Query currently selected panel.</td></tr>
 +<tr><td>[[Function:xs2qcpa | xs2qcpa]]</td><td>Is currently selected panel active? </td></tr>
</table> </table>
Line 20: Line 26:
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
 +#include <time.h>
#include "s2plot.h" #include "s2plot.h"
Line 25: Line 32:
int pid = 0; /* Which panel should be drawn? */ int pid = 0; /* Which panel should be drawn? */
int panel0; /* ID of the master panel */ int panel0; /* ID of the master panel */
 +int panel1, panel2; /* IDs of newly created panels */
void cb(double *t, int *kc) void cb(double *t, int *kc)
Line 30: Line 38:
int myid = xs2qsp(); /* Query the panel id currently being drawn */ int myid = xs2qsp(); /* Query the panel id currently being drawn */
- if (myid == panel0) { /* Is this the main panel? */+ if (myid == panel0) { /* Is this the main panel? */
- static int count = 8; /* Counter */+ static int count = 6; /* Counter */
- if (count < 0) { /* Is it time to choose a new panel */+ count--; /* Decrease counter */
- pid = random()%3; /* Choose a random new panel */+ 
- count = 8; /* Reset the counter */+ int active; /* ID of panel to change */
 + if (count < 0) { /* Time to reset counter */
 + if (drand48() > 0.5) { /* Choose a random panel */
 + active = panel1;
 + } else {
 + active = panel2;
 + }
 + 
 + if (drand48() > 0.5) /* Random toggle panel activity */
 + xs2tp(active);
 + count = 6; /* Reset the counter */
} }
- count--; /* Decrease counter */ 
} }
- if (myid == pid) { /* If this panel is the selected panel... */+ int vis1 = xs2qpa(panel1); /* Query visibility of panel with ID */
- s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */+ int vis2 = xs2qpa(panel2); /* Query visibility of panel with ID */
- char string[32];+ 
- sprintf(string,"I am panel %d",myid); /* Prepare a string */+ s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0); /* Draw coordinate box */
- s2textxy(-1,0,0,string); /* Write the string */+ 
 + char string[32];
 + if (myid == panel0) { /* Is this the master panel? */
 + if (vis1 && vis2) { /* Prepare an appropraite string */
 + sprintf(string,"Active panels %d %d",panel1,panel2);
 + } else if (vis1) {
 + sprintf(string,"Active panels %d",panel1);
 + } else if (vis2) {
 + sprintf(string,"Active panels %d",panel2);
 + } else {
 + sprintf(string,"No active panels");
 + }
 + } else {
 + sprintf(string,"I am panel %d",myid);
} }
 + s2textxy(-1,0,0,string); /* Write the string */
 +
} }
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
- int panel1; /* ID of newly created panel */ 
- int panel2; /* ID of newly created panel */ 
 + srand48((long)time(NULL)); /* Seed random numbers */
s2opend("/s2mono", argc, argv); /* Open in mono mode */ s2opend("/s2mono", argc, argv); /* Open in mono mode */
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
Line 68: Line 99:
s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */ s2swin(-1.,1., -1.,1., -1.,1.); /* Set the window coordinates */
cs2scb(&cb); /* Install a dynamic callback */ cs2scb(&cb); /* Install a dynamic callback */
- 
xs2cp(panel0); /* Go back to main panel */ xs2cp(panel0); /* Go back to main panel */
Line 77: Line 107:
return 1; return 1;
} }
 +
 +
</pre></code> </pre></code>

Current revision

xs2qpa

Is specified panel active?

Prototype

int xs2qpa(int panelid);

Description

Is the specified panel active? Activity of a panel is modified using xs2tp. In dynamic mode, the callback is disabled if the panel is inactive.

See Also

xs2cpSelect a panel for subsequent geometry calls.
xs2apAdd a new panel.
xs2mpModify location of existing panel.
xs2tpToggle visibility of panel.
xs2lpcLink panel cameras together.
xs2qspQuery currently selected panel.
xs2qcpaIs currently selected panel active?

Code Example

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

/* Global variable */
int pid = 0;                    /* Which panel should be drawn? */
int panel0;                     /* ID of the master panel */
int panel1, panel2;             /* IDs of newly created panels */

void cb(double *t, int *kc)
{
   int myid = xs2qsp();         /* Query the panel id currently being drawn */

   if (myid == panel0) {                /* Is this the main panel? */
      static int count = 6;             /* Counter  */
      count--;                          /* Decrease counter */

      int active;                       /* ID of panel to change */
      if (count < 0) {                  /* Time to reset counter */
         if (drand48() > 0.5) {         /* Choose a random panel */
            active = panel1;
         } else {
            active = panel2;
         }

         if (drand48() > 0.5)           /* Random toggle panel activity */
            xs2tp(active);
         count = 6;                     /* Reset the counter */
      }
   }

   int vis1 = xs2qpa(panel1);           /* Query visibility of panel with ID */
   int vis2 = xs2qpa(panel2);           /* Query visibility of panel with ID */

   s2box("BCDET",0,0,"BCDET",0,0,"BCDET",0,0);  /* Draw coordinate box */

   char string[32];
   if (myid == panel0) {                /* Is this the master panel? */
      if (vis1 && vis2) {               /* Prepare an appropraite string */
         sprintf(string,"Active panels %d %d",panel1,panel2);
      } else if (vis1) {
         sprintf(string,"Active panels %d",panel1);
      } else if (vis2) {
         sprintf(string,"Active panels %d",panel2);
      } else {
         sprintf(string,"No active panels");
      }
   } else {
      sprintf(string,"I am panel %d",myid);
   }
   s2textxy(-1,0,0,string);                   /* Write the string */

}

int main(int argc, char *argv[])
{

   srand48((long)time(NULL));           /* Seed random numbers */
   s2opend("/s2mono", argc, argv);      /* Open in mono mode */
   s2swin(-1.,1., -1.,1., -1.,1.);      /* Set the window coordinates */

   panel0 = xs2qsp();                   /* Get the ID of the master panel */
   xs2mp(panel0, 0.0, 0.5, 1.0, 1.0);   /* Move default panel to top left */
   cs2scb(&cb);                         /* Install a dynamic callback */

   panel1 = xs2ap(0.0, 0.0, 0.5, 0.5);  /* Create panel in bottom left */
   xs2cp(panel1);                       /* Choose this panel */
   s2swin(-1.,1., -1.,1., -1.,1.);      /* Set the window coordinates */
   cs2scb(&cb);                         /* Install a dynamic callback */

   panel2 = xs2ap(0.5, 0.0, 1.0, 0.5);  /* Create panel in bottom right */
   xs2cp(panel2);                       /* Choose this panel */
   s2swin(-1.,1., -1.,1., -1.,1.);      /* Set the window coordinates */
   cs2scb(&cb);                         /* Install a dynamic callback */
   xs2cp(panel0);                       /* Go back to main panel */

   s2sch(2);                            /* Set the character height */

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

   return 1;
}



Back to S2PLOT function list.


Personal tools