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 /* test screen/world conversion in addition to showing the xyplot styles */
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include "include/forms.h"
27 #include <stdlib.h>
28
29 typedef struct
30 {
31 int type;
32 const char * name;
33 FL_COLOR color;
34 } XYType;
35
36 #define VN( a, c ) { a, #a, c }
37
38 static XYType xytype[ ] =
39 {
40 VN( FL_NORMAL_XYPLOT, FL_BLACK ),
41 VN( FL_SQUARE_XYPLOT, FL_BLACK ),
42 VN( FL_CIRCLE_XYPLOT, FL_BLACK ),
43 VN( FL_FILL_XYPLOT, FL_BLACK ),
44 VN( FL_POINTS_XYPLOT, FL_BLACK ),
45 VN( FL_LINEPOINTS_XYPLOT, FL_BLACK ),
46 VN( FL_DASHED_XYPLOT, FL_BLACK ),
47 VN( FL_DOTTED_XYPLOT, FL_BLACK ),
48 VN( FL_DOTDASHED_XYPLOT, FL_BLACK ),
49 VN( FL_IMPULSE_XYPLOT, FL_BLACK ),
50 VN( FL_ACTIVE_XYPLOT, FL_BLACK ),
51 VN( FL_EMPTY_XYPLOT, FL_BLACK ),
52 VN( -1, 0 ),
53 };
54
55 #define N ( sizeof xytype / sizeof *xytype - 1 )
56
57
58 static FL_OBJECT *xyplot[ N ];
59 static void create_form_xyplot( void );
60 static FL_FORM *fxyplot;
61 static float x[ N ][ 21 ],
62 y[ N ][ 21 ];
63
64
65
66
67 /***************************************
68 ***************************************/
69
70 static void
done_xyplot(FL_OBJECT * ob,long q FL_UNUSED_ARG)71 done_xyplot( FL_OBJECT * ob,
72 long q FL_UNUSED_ARG )
73 {
74 fl_hide_form( ob->form );
75 fl_finish( );
76 exit( 0 );
77 }
78
79
80 #include <math.h>
81
82 /***************************************
83 ***************************************/
84
85 static int
post(FL_OBJECT * ob,int ev,FL_Coord mx,FL_Coord my,int key,void * xev FL_UNUSED_ARG)86 post( FL_OBJECT * ob,
87 int ev,
88 FL_Coord mx,
89 FL_Coord my,
90 int key,
91 void * xev FL_UNUSED_ARG )
92 {
93 if ( ev == FL_PUSH || ev == FL_MOTION )
94 {
95 float wx, wy;
96 char buf[ 64 ];
97
98 fl_xyplot_s2w( ob, mx, my, &wx, &wy );
99 sprintf( buf, "x=%d y=%d wx=%.1f wy=%.1f", mx, my, wx, wy );
100 fl_show_oneliner( buf, ob->x + ob->form->x + 5, ob->y + ob->form->y );
101 /* fl_object_ps_dump( ob,"test.ps" ); */
102 ob->wantkey = FL_KEY_ALL;
103 ob->input = 1;
104 }
105 else if ( ev == FL_RELEASE )
106 {
107 fl_hide_oneliner( );
108 }
109 else if( ev == FL_KEYPRESS )
110 {
111 fprintf( stderr,"key=%d\n",key );
112 }
113
114 return 0;
115 }
116
117
118 /***************************************
119 ***************************************/
120
121 int
main(int argc,char * argv[])122 main( int argc,
123 char * argv[ ] )
124 {
125 size_t i,
126 j;
127
128 fl_initialize( &argc, argv, "FormDemo", 0, 0 );
129 create_form_xyplot( );
130
131 /* Make sure double buffer also works */
132
133 // for ( i = 0; i < 3; i++ )
134
135 for ( i = 0; i < N; i++ )
136 {
137 fl_set_object_dblbuffer( xyplot[ i ], 1 );
138
139 for( j = 0; j < 21; j++ )
140 {
141 x[ i ][ j ] = j * 3.1415 / 10 + 0.2;
142 y[ i ][ j ] = sin( 2 * x[ i ][ j ] ) + cos( x[ i ][ j ] );
143 }
144
145 fl_set_xyplot_data( xyplot[ i ], x[ i ], y[ i ], 21, "TestTitle",
146 "X-axis", "Y|axis");
147 if ( i == 0 )
148 fl_add_xyplot_text( xyplot[ i ], x[ i ][ 15 ], 0.1,
149 "@2->", FL_ALIGN_TOP, FL_BLUE );
150 else
151 fl_add_xyplot_text( xyplot[ i ], x[ i ][ 8 ], 1.4,
152 "Text Inset", FL_ALIGN_CENTER, FL_BLUE );
153
154 if ( i == 3 )
155 {
156 fl_set_xyplot_xgrid( xyplot[ i ], FL_GRID_MAJOR );
157 fl_set_xyplot_xgrid( xyplot[ i ], FL_GRID_MINOR );
158 }
159 else if ( i == 0 )
160 {
161 fl_set_xyplot_xtics( xyplot[ i ], 7, 2 );
162 fl_set_xyplot_xbounds( xyplot[ i ], 6, 0 );
163 }
164 else if ( i == 1 )
165 {
166 fl_set_xyplot_ytics( xyplot[ i ], 5, 2 );
167 fl_set_xyplot_ybounds( xyplot[ i ], 2.4, -2.4 );
168 }
169
170 fl_set_object_posthandler( xyplot[ i ], post );
171 }
172
173 fl_show_form( fxyplot, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
174 "XYplot" );
175
176 while ( fl_do_forms( ) )
177 /* empty */;
178
179 return 0;
180 }
181
182
183 /***************************************
184 ***************************************/
185
186 static
create_form_xyplot(void)187 void create_form_xyplot( void )
188 {
189 FL_OBJECT *obj;
190 XYType *xy = xytype;
191 int dx = 180,
192 dy = 160;
193 int i = 0,
194 j = N / 3 + ( ( N % 3 ) ? 1 : 0 );
195
196 if ( fxyplot )
197 return;
198
199 fxyplot = fl_bgn_form( FL_NO_BOX, 3 * ( dx + 20 ) + 20,
200 j * ( dy + 30 ) + 120 );
201
202 fl_add_box( FL_UP_BOX, 0, 0, 3 * ( dx + 20 ) + 20, j * ( dy + 30 ) + 120,
203 "" );
204
205 for ( j = 0; xy->type != -1; j++ )
206 for ( i = 0; i < 3 && xy->type != -1; i++ )
207 {
208 xyplot[ 3 * j + i ] = obj =
209 fl_add_xyplot( xy->type, i * ( dx + 20 ) + 20 ,
210 j * ( dy + 30 ) + 60, dx, dy, xy->name );
211 fl_set_object_lsize( obj, FL_TINY_SIZE );
212 fl_set_object_color( obj, FL_COL1, xy->color );
213 xy++;
214 }
215
216 obj = fl_add_button( FL_NORMAL_BUTTON, ( 3 * ( dx + 20 ) + 20 ) / 2 - 50,
217 j * ( dy + 30 ) + 60, 100, 30, "Exit" );
218 fl_set_object_callback( obj, done_xyplot, 0 );
219
220 obj = fl_add_text( FL_NORMAL_TEXT, ( 3 * ( dx + 20 ) + 20 ) / 2 - 90,
221 15, 240, 30, "FL_XYPLOT" );
222 fl_set_object_lcolor( obj, FL_SLATEBLUE );
223 fl_set_object_lsize( obj, FL_HUGE_SIZE );
224 fl_set_object_lstyle( obj, FL_BOLD_STYLE|FL_EMBOSSED_STYLE );
225 fl_set_object_boxtype( obj, FL_FLAT_BOX );
226
227 fl_end_form( );
228 }
229
230
231 /*
232 * Local variables:
233 * tab-width: 4
234 * indent-tabs-mode: nil
235 * End:
236 */
237