1 /*
2  *  This file is part of XForms.
3  *
4  *  XForms is free software; you can redistribute it and/or modify it
5  *  under the terms of the GNU Lesser General Public License as
6  *  published by the Free Software Foundation; either version 2.1, or
7  *  (at your option) any later version.
8  *
9  *  XForms is distributed in the hope that it will be useful, but
10  *  WITHOUT ANY WARRANTY; without even the implied warranty of
11  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  *  Lesser General Public License for more details.
13  *
14  *  You should have received a copy of the GNU Lesser General Public
15  *  License along with XForms; see the file COPYING.  If not, write to
16  *  the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
17  *  MA 02111-1307, USA.
18  */
19 
20 
21 /*
22  * This is an example of the use of counters.
23  *
24  *  This file is part of xforms package
25  *  T.C. Zhao and M. Overmars
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include <stdio.h>
33 #include "include/forms.h"
34 
35 
36 FL_FORM *form;
37 FL_OBJECT *result,
38           *co[ 3 ];
39 
40 
41 /***************************************
42  ***************************************/
43 
44 void
color_change(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)45 color_change( FL_OBJECT * ob    FL_UNUSED_ARG,
46               long        data  FL_UNUSED_ARG )
47 {
48     int c[ 3 ];
49     int i;
50 
51     for ( i = 0; i < 3; i++ )
52         c[ i ] = fl_get_counter_value( co[ i ] );
53 
54     fl_mapcolor( FL_FREE_COL1, c[ 0 ], c[ 1 ], c[ 2 ] );
55     fl_redraw_object( result );
56 }
57 
58 
59 /***************************************
60  ***************************************/
61 
62 void
create_form_form(void)63 create_form_form( void )
64 {
65    FL_OBJECT *obj;
66 
67    form = fl_bgn_form( FL_NO_BOX, 480, 200 );
68 
69    fl_add_box( FL_UP_BOX, 0, 0, 480, 200, "" );
70 
71    result = obj = fl_add_box( FL_DOWN_BOX, 310, 20, 150, 160, "" );
72    fl_set_object_dblbuffer( result, 1 );
73 
74    co[ 0 ] = obj = fl_add_counter( FL_NORMAL_COUNTER, 20, 20, 270, 30, "" );
75    fl_set_object_color( obj, FL_INDIANRED, FL_RED );
76    fl_set_object_callback( obj, color_change, 0 );
77 
78    co[ 1 ] = obj = fl_add_counter( FL_NORMAL_COUNTER, 20, 60, 270, 30, "" );
79    fl_set_object_color( obj, FL_PALEGREEN, FL_GREEN );
80    fl_set_object_callback( obj, color_change, 0 );
81 
82    co[ 2 ] = obj = fl_add_counter( FL_NORMAL_COUNTER, 20, 100, 270, 30, "" );
83    fl_set_object_color( obj, FL_SLATEBLUE, FL_BLUE );
84    fl_set_object_callback( obj, color_change, 0 );
85 
86    fl_add_button( FL_NORMAL_BUTTON, 100, 150, 110, 30, "Exit" );
87 
88    fl_end_form( );
89 }
90 
91 
92 /***************************************
93  ***************************************/
94 
95 int
main(int argc,char * argv[])96 main( int    argc,
97       char * argv[ ] )
98 {
99 	int i;
100 
101 	fl_initialize( &argc, argv, "FormDemo", 0, 0 );
102 
103 	create_form_form( );
104 	fl_set_object_color( result, FL_FREE_COL1, FL_FREE_COL1 );
105 
106 	for ( i = 0; i < 3; i++ )
107 	{
108 		fl_set_counter_bounds( co[ i ], 0.0, 255.0 );
109 		fl_set_counter_step( co[ i ], 1.0, 10.0 );
110 		fl_set_counter_precision( co[ i ], 0 );
111 		fl_set_counter_return( co[ i ], 1 );
112 	}
113 
114 	fl_call_object_callback( co[ 0 ] );
115 
116 	fl_show_form( form, FL_PLACE_CENTER, FL_TRANSIENT, "Counter" );
117 
118 	fl_do_forms( );
119 
120 	fl_finish( );
121 	return 0;
122 }
123 
124 
125 /*
126  * Local variables:
127  * tab-width: 4
128  * indent-tabs-mode: nil
129  * End:
130  */
131