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  * Demo showing the use of xyplot overlay, plot key and
23  * PostScript output.
24  *
25  *  This file is part of xforms package
26  *  T.C. Zhao and M. Overmars
27  */
28 
29 #ifdef HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32 
33 #include "include/forms.h"
34 #include <stdlib.h>
35 #include <math.h>
36 
37 /**** Forms and Objects ****/
38 
39 typedef struct
40 {
41     FL_FORM *   fff;
42     void *      vdata;
43     long        ldata;
44     FL_OBJECT * xyplot;
45 } FD_fff;
46 
47 extern FD_fff * create_form_fff( void );
48 extern void init_xyplot( FD_fff * );
49 
50 
51 /***************************************
52  ***************************************/
53 
54 int
main(int argc,char * argv[])55 main( int    argc,
56       char * argv[ ] )
57 {
58     FD_fff *fd_fff;
59 
60     fl_initialize( &argc, argv, "FormDemo", 0, 0 );
61 
62     fd_fff = create_form_fff( );
63 
64     /* Fill-in form initialization code */
65 
66     init_xyplot( fd_fff );
67 
68     /* Show the first form */
69 
70     fl_show_form( fd_fff->fff, FL_PLACE_MOUSE | FL_FREE_SIZE, FL_TRANSIENT,
71                   "XYPlot Overlay" );
72 
73     fl_do_forms( );
74 
75     if ( fl_object_ps_dump( fd_fff->xyplot, "test.ps" ) >= 0 )
76         fprintf( stderr, "PostScript output test.ps written\n" );
77 
78     return 0;
79 }
80 
81 
82 /***************************************
83  ***************************************/
84 
85 void
init_xyplot(FD_fff * fd_fff)86 init_xyplot( FD_fff * fd_fff )
87 {
88     int i;
89     float xx[ 20 ],
90           yy[ 20 ];
91 
92     for ( i = 0; i <= 10; i++ )
93     {
94         xx[ i ] = i;
95         yy[ i ] = exp( - 0.125 * ( i - 5 ) * ( i - 5 ) );
96     }
97 
98     fl_set_xyplot_data( fd_fff->xyplot, xx, yy, 8,
99                         "Plot Title", "X-Axis", "Y|Axis");
100     fl_set_xyplot_ybounds( fd_fff->xyplot, 0, 1.1 );
101     fl_set_xyplot_xbounds( fd_fff->xyplot, 0, 10 );
102     fl_add_xyplot_overlay( fd_fff->xyplot, 1, xx, yy, 11, FL_YELLOW );
103     fl_set_xyplot_overlay_type( fd_fff->xyplot, 1, FL_LINEPOINTS_XYPLOT );
104     fl_set_xyplot_interpolate( fd_fff->xyplot, 1, 2, 0.1 );
105 
106     fl_add_xyplot_text( fd_fff->xyplot, 0.5, 1.0, "Gaussian\nDistribution",
107                         FL_ALIGN_RIGHT, FL_WHITE );
108 
109     fl_set_xyplot_key( fd_fff->xyplot, 0, "Original" );
110     fl_set_xyplot_key( fd_fff->xyplot, 1, "Overlay" );
111     fl_set_xyplot_key_position( fd_fff->xyplot, 9.8, 1.08,
112                                 FL_ALIGN_LEFT_BOTTOM );
113 }
114 
115 
116 /***************************************
117  ***************************************/
118 
119 FD_fff *
create_form_fff(void)120 create_form_fff( void )
121 {
122     FL_OBJECT *obj;
123     FD_fff *fdui = fl_calloc( 1, sizeof *fdui );
124 
125     fdui->fff = fl_bgn_form( FL_NO_BOX, 370, 310 );
126 
127     fl_add_box( FL_UP_BOX, 0, 0, 370, 310, "" );
128 
129     fdui->xyplot = obj = fl_add_xyplot( FL_IMPULSE_XYPLOT, 10, 20, 350, 260,
130                                         "An XYPlot with overlay" );
131     fl_set_object_lalign( obj, fl_to_inside_lalign( FL_ALIGN_BOTTOM ) );
132     fl_set_object_lsize( obj, FL_NORMAL_SIZE );
133     fl_set_object_boxtype( obj, FL_DOWN_BOX );
134     fl_set_object_color( obj, FL_BLACK, FL_GREEN );
135 
136     obj = fl_add_button( FL_HIDDEN_BUTTON, 10, 10, 350, 290, "" );
137     fl_set_button_shortcut( obj,"qQ", 0 );
138 
139     fl_end_form( );
140 
141     return fdui;
142 }
143 
144 
145 /*
146  * Local variables:
147  * tab-width: 4
148  * indent-tabs-mode: nil
149  * End:
150  */
151