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 demo is meant to demonstrate the use of a free
22    object in a form.
23 */
24 
25 #ifdef HAVE_CONFIG_H
26 #include "config.h"
27 #endif
28 
29 #include "include/forms.h"
30 #include <stdlib.h>
31 
32 
33 int on = 1,
34     dcol = 1;
35 FL_COLOR cole;
36 
37 /***************************************
38  * The call back routine
39  ***************************************/
40 
41 int
handle_free1(FL_OBJECT * obj,int event,FL_Coord mx FL_UNUSED_ARG,FL_Coord my FL_UNUSED_ARG,int key FL_UNUSED_ARG,void * ev FL_UNUSED_ARG)42 handle_free1( FL_OBJECT * obj,
43 			  int         event,
44 			  FL_Coord    mx   FL_UNUSED_ARG,
45 			  FL_Coord    my   FL_UNUSED_ARG,
46 			  int         key  FL_UNUSED_ARG,
47 			  void      * ev   FL_UNUSED_ARG )
48 {
49     static int dcol = 1;
50 
51     switch ( event )
52     {
53         case FL_DRAW:
54             fl_rectf( obj->x, obj->y, obj->w, obj->h, obj->u_ldata );
55             break;
56 
57         case FL_RELEASE:
58             on = ! on;
59             break;
60 
61         case FL_STEP:
62             if ( on )
63             {
64                 if ( ( FL_COLOR ) obj->u_ldata >= cole )
65                     dcol = -1;
66                 if ( obj->u_ldata <= FL_FREE_COL1 )
67                     dcol = 1;
68                 obj->u_ldata += dcol;
69                 fl_redraw_object( obj );
70             }
71             break;
72     }
73     return 0;
74 }
75 
76 
77 /***************************************
78  ***************************************/
79 
done(FL_OBJECT * ob FL_UNUSED_ARG,long data FL_UNUSED_ARG)80 void done( FL_OBJECT * ob    FL_UNUSED_ARG,
81            long        data  FL_UNUSED_ARG )
82 {
83     fl_finish( );
84     exit( 0 );
85 }
86 
87 
88 /***************************************
89  ***************************************/
90 
91 int
main(int argc,char * argv[])92 main( int    argc,
93       char * argv[ ] )
94 {
95     FL_FORM *form;
96     FL_OBJECT *obj;
97     FL_COLOR i;
98     int j,
99         depth,
100         col;
101 
102     fl_initialize(&argc, argv, "FormDemo", 0, 0);
103 
104     form = fl_bgn_form( FL_UP_BOX, 400, 400 );
105     obj = fl_add_button( FL_NORMAL_BUTTON, 320, 20, 40, 30, "Exit" );
106     fl_set_object_callback( obj, done, 0 );
107     obj = fl_add_free( FL_CONTINUOUS_FREE, 40, 80, 320, 280, "", handle_free1 );
108     fl_end_form( );
109 
110     /* Can't do it if less than 4 bit deep... */
111 
112     depth  = fl_get_visual_depth( );
113 
114     if ( depth < 4 )
115     {
116         fprintf( stderr,"This Demo requires a depth of at least 4 bits\n" );
117         fl_finish( );
118         exit( 1 );
119     }
120 
121     /* ...but too large a depth also won't do */
122 
123     if ( depth > 7 )
124         depth = 7;
125 
126     cole = ( 1 << depth ) - 1;
127     if ( cole > 64 )
128         cole = 64;
129 
130     obj->u_ldata = col = FL_FREE_COL1;
131     cole += col;
132 
133     for ( i = col; i <= cole; i++ )
134     {
135         j =  255 * ( i - col ) / ( double ) ( cole  - col );
136         fl_mapcolor( i, j, j, j );
137     }
138 
139     fl_show_form( form,FL_PLACE_CENTER, FL_NOBORDER, "Free Object" );
140     fl_do_forms( );
141 
142     return 0;
143 }
144 
145 
146 /*
147  * Local variables:
148  * tab-width: 4
149  * indent-tabs-mode: nil
150  * End:
151  */
152