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 
24 #ifdef HAVE_CONFIG_H
25 #include "config.h"
26 #endif
27 
28 
29 #include <stdio.h>
30 #include "include/forms.h"
31 
32 
33 FL_FORM *form;
34 FL_OBJECT *dial[ 3 ],
35           *text[ 3 ],
36           *result;
37 
38 enum {
39     RED,
40     GREEN,
41     BLUE
42 };
43 
44 
45 /***************************************
46  ***************************************/
47 
48 static void
dial_callback(FL_OBJECT * obj FL_UNUSED_ARG,long arg)49 dial_callback( FL_OBJECT * obj  FL_UNUSED_ARG,
50                long        arg )
51 {
52     int clr[ 3 ];
53     size_t i;
54     char str[ 60 ];
55 
56     for ( i = RED; i <= BLUE; i++ )
57         clr[ i ] = fl_get_dial_value( dial[ i ] );
58 
59     sprintf( str, "%d", clr[ arg ] );
60     fl_set_object_label( text[ arg ], str );
61 
62     fl_mapcolor( FL_FREE_COL1, clr[ 0 ], clr[ 1 ], clr[ 2 ] );
63     fl_redraw_object( result );
64 }
65 
66 
67 /***************************************
68  ***************************************/
69 
70 static void
makeform(void)71 makeform( void )
72 {
73     FL_OBJECT *quit;
74     size_t i;
75     const char *txt[ ] = { "Red",  "Green",  "Blue"  };
76     FL_COLOR clr[ ]    = { FL_RED, FL_GREEN, FL_BLUE };
77 
78     form = fl_bgn_form( FL_UP_BOX, 300, 330 );
79 
80     quit = fl_add_button( FL_NORMAL_BUTTON, 45, 15, 210, 45, "A Color Editor" );
81     fl_set_object_lsize( quit, FL_LARGE_SIZE );
82 
83     for ( i = RED; i <= BLUE; i++ )
84     {
85         dial[ i ] = fl_add_dial( FL_LINE_DIAL, 30, 240 - i * 85, 60, 60,
86                                  txt[ i ] );
87         fl_set_dial_bounds( dial[ i ], 0.0, 255.0 );
88         fl_set_dial_angles( dial[ i ], 15.0, 345.0 );
89         fl_set_dial_value( dial[ i ], 128.0 );
90         fl_set_object_color( dial[ i ], clr[ i ], FL_DIAL_COL2 );
91         fl_set_object_return( dial[ i ], FL_RETURN_CHANGED );
92         fl_set_object_callback( dial[ i ], dial_callback, i );
93 
94         text[ i ] = fl_add_box( FL_DOWN_BOX, 105, 255 - i * 85, 50, 25, "128" );
95     }
96 
97     result = fl_add_box( FL_DOWN_BOX, 180, 70, 90, 245, "" );
98     fl_mapcolor( FL_FREE_COL1, 128, 128, 128 );
99     fl_set_object_color( result, FL_FREE_COL1, FL_FREE_COL1 );
100     fl_set_object_dblbuffer( result, 1 );
101 
102     fl_end_form( );
103 }
104 
105 
106 /***************************************
107  ***************************************/
108 
109 int
main(int argc,char * argv[])110 main( int    argc,
111       char * argv[ ] )
112 {
113     fl_initialize( &argc, argv, "ColorEditor", 0, 0 );
114     makeform( );
115 
116     fl_show_form( form, FL_PLACE_MOUSE, FL_TRANSIENT, "Color Editor" );
117     fl_do_forms( );
118 
119     fl_finish();
120     return 0;
121 }
122 
123 
124 /*
125  * Local variables:
126  * tab-width: 4
127  * indent-tabs-mode: nil
128  * End:
129  */
130