summaryrefslogtreecommitdiff
path: root/dist/cdk/examples/scale_ex.c
blob: 23d83eb858ca83eb5ca7aac595adecfc88b5e151 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include <cdk.h>

#ifdef HAVE_XCURSES
char *XCursesProgramName="scale_ex";
#endif

/*
 * This program demonstrates the Cdk scale widget.
 */
int main (int argc, char **argv)
{
   /* Declare variables. */
   CDKSCREEN *cdkscreen = 0;
   CDKSCALE *scale	= 0;
   WINDOW *cursesWin	= 0;
   char *title		= "<C>Select a value\n<R>scale\n<L>scale";
   char *label		= "</5>Current value";
   int low		= 0;
   int high		= 100;
   int inc		= 1;
   char temp[256], *mesg[5];
   int selection, ret;

   /* Parse up the command line.*/
   while (1)
   {
      ret = getopt (argc, argv, "l:h:i:");

      /* Are there any more command line options to parse. */
      if (ret == -1)
      {
	 break;
      }

      switch (ret)
      {
	 case 'l':
	      low = atoi (optarg);
	      break;

	 case 'h':
	      high = atoi (optarg);
	      break;

	 case 'i':
	      inc = atoi (optarg);
	      break;
      }
   }

   /* Set up CDK. */
   cursesWin = initscr();
   cdkscreen = initCDKScreen (cursesWin);

   /* Start CDK Colors. */
   initCDKColor();

   /* Create the scale. */
   scale = newCDKScale (cdkscreen, CENTER, CENTER,
			title, label, A_NORMAL,
			4, low, low, high,
			inc, (inc*2), TRUE, TRUE);

   /* Is the scale null? */
   if (scale == 0)
   {
      /* Exit CDK. */
      destroyCDKScreen (cdkscreen);
      endCDK();

      /* Print out a message. */
      printf ("Oops. Can't make the scale widget. Is the window too small?\n");
      exit (1);
   }

   /* Activate the scale. */
   selection = activateCDKScale (scale, 0);

   /* Check the exit value of the scale widget. */
   if (scale->exitType == vESCAPE_HIT)
   {
      mesg[0] = "<C>You hit escape. No value selected.";
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
   }
   else if (scale->exitType == vNORMAL)
   {
      sprintf (temp, "<C>You selected %d", selection);
      mesg[0] = copyChar (temp);
      mesg[1] = "",
      mesg[2] = "<C>Press any key to continue.";
      popupLabel (cdkscreen, mesg, 3);
      freeChar (mesg[0]);
   }

   /* Clean up. */
   destroyCDKScale (scale);
   destroyCDKScreen (cdkscreen);
   delwin (cursesWin);
   endCDK();
   exit (0);
}