~ubuntu-branches/ubuntu/trusty/libcdk5/trusty

« back to all changes in this revision

Viewing changes to examples/fslider_ex.c

  • Committer: Bazaar Package Importer
  • Author(s): John Goerzen
  • Date: 2007-06-06 03:54:31 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20070606035431-ba4gdvw0h6ybffsu
Tags: 5.0.20060507-1
* New upstream release.
* Fixed header patching.  Patch from Robert Schiele.
  Closes: #402978, #416336.
* Update widget count in description.  Closes: #294709.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* $Id: fslider_ex.c,v 1.1 2005/12/27 19:16:29 tom Exp $ */
 
2
 
 
3
#include <cdk_test.h>
 
4
 
 
5
#ifdef HAVE_XCURSES
 
6
char *XCursesProgramName = "slider_ex";
 
7
#endif
 
8
 
 
9
/*
 
10
 * This program demonstrates the Cdk slider widget.
 
11
 */
 
12
int main (int argc, char **argv)
 
13
{
 
14
   /* Declare variables. */
 
15
   CDKSCREEN *cdkscreen = 0;
 
16
   CDKFSLIDER *widget   = 0;
 
17
   WINDOW *cursesWin    = 0;
 
18
   char *title          = "<C></U>Enter a value:";
 
19
   char *label          = "</B>Current Value:";
 
20
   char temp[256], *mesg[5];
 
21
   float selection;
 
22
 
 
23
   CDK_PARAMS params;
 
24
   float high;
 
25
   float inc;
 
26
   float low;
 
27
 
 
28
   float scale;
 
29
   int n, digits;
 
30
 
 
31
   CDKparseParams(argc, argv, &params, "h:i:l:w:p:" CDK_MIN_PARAMS);
 
32
   digits = CDKparamNumber2(&params, 'p', 0);
 
33
 
 
34
   scale = 1.0;
 
35
   for (n = 0; n < digits; ++n) {
 
36
      scale = scale * 10.0;
 
37
   }
 
38
 
 
39
   high   = CDKparamNumber2(&params, 'h', 100) / scale;
 
40
   inc    = CDKparamNumber2(&params, 'i', 1) / scale;
 
41
   low    = CDKparamNumber2(&params, 'l', 1) / scale;
 
42
 
 
43
   /* Set up CDK. */
 
44
   cursesWin = initscr();
 
45
   cdkscreen = initCDKScreen (cursesWin);
 
46
 
 
47
   /* Start CDK Colors. */
 
48
   initCDKColor();
 
49
 
 
50
   /* Create the widget. */
 
51
   widget = newCDKFSlider (cdkscreen,
 
52
                          CDKparamValue(&params, 'X', CENTER),
 
53
                          CDKparamValue(&params, 'Y', CENTER),
 
54
                          title, label,
 
55
                          A_REVERSE | COLOR_PAIR (29) | ' ',
 
56
                          CDKparamNumber2(&params, 'w', 50),
 
57
                          low, low, high,
 
58
                          inc, (inc*2),
 
59
                          digits,
 
60
                          CDKparamValue(&params, 'N', TRUE),
 
61
                          CDKparamValue(&params, 'S', FALSE));
 
62
 
 
63
   /* Is the widget null? */
 
64
   if (widget == 0)
 
65
   {
 
66
      /* Exit CDK. */
 
67
      destroyCDKScreen (cdkscreen);
 
68
      endCDK();
 
69
 
 
70
      /* Print out a message. */
 
71
      printf ("Oops. Can't make the widget. Is the window too small?\n");
 
72
      ExitProgram (EXIT_FAILURE);
 
73
   }
 
74
 
 
75
   /* Activate the widget. */
 
76
   selection = activateCDKFSlider (widget, 0);
 
77
 
 
78
   /* Check the exit value of the widget. */
 
79
   if (widget->exitType == vESCAPE_HIT)
 
80
   {
 
81
      mesg[0] = "<C>You hit escape. No value selected.";
 
82
      mesg[1] = "",
 
83
      mesg[2] = "<C>Press any key to continue.";
 
84
      popupLabel (cdkscreen, mesg, 3);
 
85
   }
 
86
   else if (widget->exitType == vNORMAL)
 
87
   {
 
88
      sprintf (temp, "<C>You selected %.*f", digits, selection);
 
89
      mesg[0] = copyChar (temp);
 
90
      mesg[1] = "",
 
91
      mesg[2] = "<C>Press any key to continue.";
 
92
      popupLabel (cdkscreen, mesg, 3);
 
93
      freeChar (mesg[0]);
 
94
   }
 
95
 
 
96
   /* Clean up.*/
 
97
   destroyCDKFSlider (widget);
 
98
   destroyCDKScreen (cdkscreen);
 
99
   endCDK();
 
100
   ExitProgram (EXIT_SUCCESS);
 
101
}