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 a crazy demo showing the "use" of changing
23  * fields in objects.
24  *
25  *  T.C. Zhao and M. Overmars
26  */
27 
28 #ifdef HAVE_CONFIG_H
29 #include "config.h"
30 #endif
31 
32 #include "include/forms.h"
33 
34 
35 /***************************************
36  ***************************************/
37 
38 void
move_cb(FL_OBJECT * ob FL_UNUSED_ARG,long data)39 move_cb( FL_OBJECT * ob  FL_UNUSED_ARG,
40          long        data )
41 {
42     static FL_Coord dx = 8,
43                     dy = 8;
44     FL_OBJECT *but = ( FL_OBJECT * ) data;
45     FL_Coord x,
46              y,
47              w,
48              h;
49 
50     fl_get_object_geometry( but, &x, &y, &w, &h );
51 
52     if ( x + dx < 0 || x + w + dx >= but->form->w )
53         dx = -dx;
54     if ( y + dy < 0 || y + h + dy >= but->form->h )
55         dy = -dy;
56     x += dx;
57     y += dy;
58 
59     fl_set_object_position( but, x, y );
60 }
61 
62 
63 /***************************************
64  ***************************************/
65 
66 int
main(int argc,char * argv[])67 main( int    argc,
68       char * argv[ ] )
69 {
70     FL_FORM *form;
71     FL_OBJECT *but,
72               *obj;
73 
74     fl_initialize( &argc, argv, "FormDemo", 0, 0 );
75 
76     form = fl_bgn_form( FL_DOWN_BOX, 400, 200 );
77     but = fl_add_button( FL_NORMAL_BUTTON, 140, 160, 70, 35, "Exit" );
78     fl_set_object_resize( but, FL_RESIZE_NONE );
79     obj = fl_add_button( FL_TOUCH_BUTTON, 330, 150, 50, 30, "Move" );
80     fl_set_object_resize( obj, FL_RESIZE_NONE );
81     fl_set_object_gravity( obj, FL_SouthEast, FL_SouthEast );
82     fl_set_object_callback( obj,move_cb,( long ) but );
83     fl_end_form( );
84 
85     fl_show_form( form, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_FULLBORDER,
86                   "ObjPos" );
87 
88     fl_do_forms( );
89 
90     return 0;
91 }
92 
93 
94 /*
95  * Local variables:
96  * tab-width: 4
97  * indent-tabs-mode: nil
98  * End:
99  */
100