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 /* This is an example of the use of dials.  */
22 
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26 
27 #include <stdio.h>
28 #include "include/forms.h"
29 
30 FL_FORM *form;
31 FL_OBJECT * dials[ 3 ],
32           * texts[ 3 ],
33           * result;
34 
35 
36 /***************************************
37  ***************************************/
38 
39 void
cb(FL_OBJECT * obj,long data)40 cb( FL_OBJECT * obj,
41     long        data )
42 {
43     static int cols[ 3 ] = { 128, 128, 128 };
44     char str[ 4 ];
45 
46     cols[ data ] = fl_get_dial_value( obj );
47     fl_mapcolor( FL_FREE_COL1, cols[ 0 ], cols[ 1 ], cols[ 2 ] );
48     fl_redraw_object( result );
49     sprintf( str, "%d", cols[ data ] );
50     fl_set_object_label( texts[ data ], str );
51 
52 }
53 
54 
55 /***************************************
56  ***************************************/
57 
58 void
makeform(void)59 makeform( void )
60 {
61     FL_OBJECT *obj;
62     const char *label[ 3 ] = { "Red", "Green", "Blue" };
63     FL_COLOR col[ 3 ] = { FL_RED, FL_GREEN, FL_BLUE };
64     int i;
65     int y = 70;
66 
67     form = fl_bgn_form( FL_UP_BOX, 300, 330 );
68 
69     obj = fl_add_button( FL_NORMAL_BUTTON, 45, 15, 210, 45, "Color Editor" );
70     fl_set_object_lsize( obj, FL_LARGE_SIZE );
71 
72     for ( i = 0; i < 3; y += 85, i++ )
73     {
74         dials[ i ] = obj = fl_add_dial( FL_NORMAL_DIAL, 30, y, 60, 60,
75                                         label[ i ] );
76         fl_set_object_boxtype( obj, FL_UP_BOX );
77         fl_set_dial_bounds( obj, 0.0, 255.0 );
78         fl_set_dial_value( obj, 128.0 );
79         fl_set_object_color( obj, col[ i ], FL_DIAL_COL2 );
80         fl_set_object_callback( obj, cb, i );
81         fl_set_object_return( obj, FL_RETURN_CHANGED );
82 
83         texts[ i ] = fl_add_box( FL_DOWN_BOX, 105, y + 17, 50, 25, "128" );
84     }
85 
86     result = fl_add_box( FL_DOWN_BOX, 180, 70, 90, 245, "" );
87     fl_set_object_color( result, FL_FREE_COL1, FL_FREE_COL1 );
88     fl_mapcolor( FL_FREE_COL1, 128, 128, 128 );
89     fl_set_object_dblbuffer( result, 1 );     /* to avoid flicker */
90 
91     fl_end_form( );
92 }
93 
94 
95 /***************************************
96  ***************************************/
97 
98 int
main(int argc,char * argv[])99 main( int    argc,
100       char * argv[ ] )
101 {
102     fl_initialize( &argc, argv, "FormDemo", 0, 0 );
103     makeform( );
104 
105     fl_show_form( form, FL_PLACE_MOUSE, FL_TRANSIENT, "A Form" );
106 
107     fl_do_forms( );
108 
109     fl_finish( );
110     return 0;
111 }
112 
113 
114 /*
115  * Local variables:
116  * tab-width: 4
117  * indent-tabs-mode: nil
118  * End:
119  */
120