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 /* Demo for scaling forms. */
22
23 #ifdef HAVE_CONFIG_H
24 #include "config.h"
25 #endif
26
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include "include/forms.h"
30
31 typedef struct
32 {
33 FL_FORM * form;
34 FL_OBJECT *smallerobj,
35 *largerobj,
36 *scaleobj,
37 *cell00,
38 *exitobj;
39 } FD_form;
40
41
42 /***************************************
43 ***************************************/
44
45 FD_form *
create_form_form(void)46 create_form_form(void)
47 {
48 FL_OBJECT *obj;
49 FD_form *fdui = calloc( 1, sizeof *fdui );
50
51 fdui->form = fl_bgn_form( FL_NO_BOX, 470, 370 );
52
53 fl_add_box( FL_UP_BOX, 0, 0, 470, 370, "" );
54
55 obj = fl_add_box( FL_SHADOW_BOX, 30, 30, 410, 70, "Scaling Forms" );
56 fl_set_object_color( obj, 9, 47 );
57 fl_set_object_lsize( obj, 16 );
58
59 fdui->smallerobj = fl_add_button( FL_NORMAL_BUTTON, 30, 220, 130, 40,
60 "Smaller" );
61
62 fdui->largerobj = fl_add_button( FL_NORMAL_BUTTON, 310, 220, 130, 40,
63 "Larger" );
64
65 fdui->scaleobj = obj = fl_add_input( FL_FLOAT_INPUT, 170, 140, 270, 40,
66 "Scale:" );
67
68 fdui->exitobj = obj = fl_add_button( FL_NORMAL_BUTTON, 310, 300, 130, 40,
69 "Exit" );
70
71 fl_end_form( );
72
73 return fdui;
74 }
75
76
77 /***************************************
78 ***************************************/
79
80 int
main(int argc,char * argv[])81 main( int argc,
82 char * argv[ ] )
83 {
84 float sc = 1,
85 oldsc;
86 FL_OBJECT *obj;
87 FD_form *ui;
88 char str[ 32 ];
89
90 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
91 ui = create_form_form( );
92 sprintf( str, "%.2f", sc );
93 fl_set_input( ui->scaleobj, str );
94
95 fl_show_form( ui->form, FL_PLACE_CENTER | FL_FREE_SIZE,
96 FL_FULLBORDER, "Scaling" );
97
98 while ( 1 )
99 {
100 oldsc = sc;
101 obj = fl_do_forms( );
102
103 if ( obj == ui->exitobj )
104 exit( 0 );
105
106 if ( obj == ui->smallerobj )
107 sc = sc * 0.8;
108
109 if ( obj == ui->largerobj )
110 sc = sc / 0.8;
111
112 if ( obj == ui->scaleobj )
113 sc = atof( fl_get_input( ui->scaleobj ) );
114
115 if ( sc < 0.50 )
116 sc = 0.50;
117
118 if ( sc > 3 )
119 sc = 3;
120
121 if ( sc != oldsc )
122 {
123 fl_scale_form( ui->form, sc / oldsc, sc / oldsc );
124 sprintf( str, "%.2f", sc );
125 fl_set_input( ui->scaleobj, str );
126 }
127 }
128 }
129
130
131 /*
132 * Local variables:
133 * tab-width: 4
134 * indent-tabs-mode: nil
135 * End:
136 */
137