1 /* ======================================================= *
2  * Copyright 1998-2005 Stephen C. Grubb                    *
3  * http://ploticus.sourceforge.net                         *
4  * Covered by GPL; see the file ./Copyright for details.   *
5  * ======================================================= */
6 
7 /* routines related to low level graphic initialization */
8 
9 #include "plg.h"
10 
11 extern int GL_sysdate(), GL_systime(), PLGP_setup(), PLGS_setup(), PLGX_setup(), PLGG_setup(), PLGF_setup();
12 
13 #define DEFAULT_WIN_WIDTH 8
14 #define DEFAULT_WIN_HEIGHT 9
15 #define MM_PER_INCH 25.3807
16 
17 static int uplefttx = 0, upleftty = 0;
18 static double pagewidth = DEFAULT_WIN_WIDTH, pageheight = DEFAULT_WIN_HEIGHT;
19 static int initialized = 0;
20 static char outfilename[ MAXPATH ] = "";
21 static char outlabel[80] = "ploticus-graphic";
22 static int maxdrivervect = 500;
23 
24 
25 /* ========================================== */
26 int
27 PLG_init_initstatic()
28 {
29 uplefttx = 0;
30 upleftty = 0;
31 pagewidth = DEFAULT_WIN_WIDTH;
32 pageheight = DEFAULT_WIN_HEIGHT;
33 initialized = 0;
34 strcpy( outfilename, "" );
35 strcpy( outlabel, "ploticus-graphic" );
36 maxdrivervect = 500;
37 return( 0 );
38 }
39 
40 /* ========================================== */
41 /* INIT - initialize device */
42 
43 int
44 PLG_init( dev )
45 char dev;     /* device code */
46 {
47 int yr, mon, day, hr, min, sec;
48 char sdev[8];
49 int stat;
50 
51 GL_sysdate( &mon, &day, &yr ); GL_systime( &hr, &min, &sec );
52 
53 /* initialize graphics parameters.. */
54 Edev = dev;
55 
56 if( dev == 'p' || dev == 'c' || dev == 'e' ) {
57 #ifdef NOPS
58 	return( Eerr( 12016, "PostScript capability was not included in this build.", "" ) );
59 #else
60 
61 	stat = PLGP_setup( outlabel, dev, outfilename );
62 	if( stat ) return( stat );
63 	Edev = 'p'; /* driver now knows eps/color/bw, from now on call it 'p' */
64 #endif
65 	}
66 
67 /* added support for svg - BT 05/11/01 */
68 else if( dev == 's' ) {
69 #ifdef NOSVG
70 	return( Eerr( 12016, "SVG capability was not included in this build.", "" ) );
71 #else
72         Epixelsinch = 72;
73         Esetwinscale( (int)(pagewidth*Epixelsinch), (int)(pageheight*Epixelsinch), pagewidth, pageheight );
74         stat = PLGS_setup( outlabel, dev, outfilename, Epixelsinch, pagewidth, pageheight, uplefttx, upleftty );
75 	if( stat ) return( stat );
76 #endif
77         }
78 
79 else if( dev == 'x' ) {
80 #ifdef NOX11
81 	return( Eerr( 12016, "X11 capability was not included in this build.", "" ) );
82 #else
83 	double sx, sy;
84 	Epixelsinch = 75;
85 	Esetwinscale( (int)(pagewidth*Epixelsinch), (int)(pageheight*Epixelsinch), pagewidth, pageheight );
86 	Egetglobalscale( &sx, &sy );
87 	stat = PLGX_setup( outlabel, Epixelsinch, pagewidth, pageheight, uplefttx, upleftty, maxdrivervect );
88 	if( stat ) return( stat );
89 #endif
90 	}
91 else if( dev == 'g' ) {
92 #ifdef NOGD
93 	return( Eerr( 12016, "GD image capability was not included in this build.", "" ) );
94 
95 #else
96 	Epixelsinch = 100;
97 	Esetwinscale( (int)(pagewidth*Epixelsinch), (int)(pageheight*Epixelsinch), pagewidth, pageheight );
98 	stat = PLGG_setup( outlabel, Epixelsinch, pagewidth, pageheight, uplefttx, upleftty, maxdrivervect );
99 	if( stat ) return( stat );
100 	Edev = 'g';
101 #endif
102 	}
103 
104 else if( dev == 'f' ) {
105 #ifdef NOSWF
106         return( Eerr( 12016, "SWF capability was not included in this build.", "" ) );
107 #else
108          Epixelsinch = 72;
109          Esetwinscale( (int)(pagewidth*Epixelsinch), (int)(pageheight*Epixelsinch), pagewidth, pageheight );
110          stat = PLGF_setup( outlabel, dev, outfilename, Epixelsinch, pagewidth, pageheight, uplefttx, upleftty, maxdrivervect );
111          if( stat ) return( stat );
112 #endif
113          }
Up_to_date_task1(infile, outfile)114 
115 else if( dev == 'n' ) ; /* null device */
116 
117 else 	{
118 	sprintf( sdev, "%c", dev );
119 	return( Eerr( 12016, "Unsupported display device code", sdev ) );
Up_to_date_task2(infile, outfile)120 	}
121 
122 if( dev != 'n' ) initialized = 1;
123 
124 EWinx = pagewidth;  EWiny = pageheight;
125 PLG_setdefaults();
Up_to_date_task3(infile, outfile)126 return( 0 );
127 }
128 
129 /* ================================== */
130 /* SETSIZE - set the size and position of the display.  Should be called before init()
131 */
Up_to_date_final_target(infile, outfile)132 
133 int
134 PLG_setsize( ux, uy, upleftx, uplefty )
135 double ux, uy;  /* size of window in inches.. */
136 int upleftx, uplefty; /* point (in native window system coords ) of upper-left corner of window */
137 {
138 extern int PLGX_resizewin();
139 
140 if( ! initialized ) { /* getting ready to initialize-- set size parameters */
Explicitly_specified_task(infile, outfile)141 	pagewidth = ux; pageheight = uy; uplefttx = upleftx; upleftty = uplefty;
142 	return( 0 );
143 	}
144 
145 if( initialized ) {    /* window already exists, resize it.. */
146 	/* update parameters: window size and original size */
147 	/* do this regardless of device since any code may use EWin variables.. */
148 	if( ux >= 0 ) { EWinx = ux; EWinx_0 = ux; }
Task_to_run1(infile, outfile)149 	if( uy >= 0 ) { EWiny = uy; EWiny_0 = uy; }
150 #ifndef NOX11
151 	if( Edev == 'x' ) {
152 		/* update scaling */
153 		Esetwinscale( (int)(ux*Epixelsinch), (int)(uy*Epixelsinch), ux, uy );
Task_to_run2(infile, outfile)154 		/* resize window */
155 		PLGX_resizewin( Epixelsinch, upleftx, uplefty, ux, uy );
156 		}
157 #endif
158 #ifndef NOGD
Task_to_run3(infile, outfile)159 	else if( Edev == 'g' ) {
160 		/* terminate existing image and start a new one with new size.. */
161 		Esetwinscale( (int)(pagewidth*Epixelsinch), (int)(pageheight*Epixelsinch), pagewidth, pageheight );
162 		PLGG_setup( "", Epixelsinch, pagewidth, pageheight, uplefttx, upleftty );
163 		}
164 #endif
Up_to_date_task_forced_to_rerun(infile, outfile)165 	}
166 return( 0 );
167 }
168 
169 
170 /* ====================================== */
171 int
172 PLG_setdefaults()
Final_target(infile, outfile)173 {
174 Efont( Estandard_font );
175 Etextsize( 10 );
176 Etextdir( 0 );
177 Elinetype( 0, 0.6, 1.0 );
178 Ecolor( Estandard_color ); PLG_forcecolorchg();
179 /* strcpy( Ecurcolor, Estandard_color ); */ /* added scg 7/28/04 ... related to pcode color change optimization */
180 Ebackcolor( Estandard_bkcolor );
181 Escaletype( "linear", 'x' );
182 Escaletype( "linear", 'y' );
183 Epaper( 0 );
184 Eblacklines = 1; /* set to 0 only when half-tone lines desired when displaying on b/w device */
185 EEvent = 0;
186 return( 0 );
187 }
188 
189 /* =================== */
190 int
191 PLG_setoutfilename( name )
192 char *name;
193 {
194 strncpy( outfilename, name, MAXPATH-1 );
195 outfilename[ MAXPATH-1 ] = '\0';
196 return( 0 );
197 }
198 
199 /* =================== */
200 int
201 PLG_getoutfilename( name )
202 char *name;
203 {
204 strcpy( name, outfilename );
205 return( 0 );
206 }
207 
208 /* ==================== */
209 int
210 PLG_setoutlabel( name )
211 char *name;
212 {
213 strncpy( outlabel, name, 78 );
214 outlabel[78] = '\0';
215 return( 0 );
216 }
217 
218 /* ===================== */
219 /* added scg 5/4/04 */
220 int
221 PLG_setmaxdrivervect( j )
222 int j;
223 {
224 maxdrivervect = j;
225 return( 0 );
226 }
227 
228 
229 /* ========================= */
230 int
231 PLG_handle_events( x, y, e )
232 double x, y;
233 int e;
234 {
235 /* fprintf( stderr, "[event %d]\n", e );  */
236 if( e == E_EXPOSE || e == E_RESIZE ) Erestorewin();
237 
238 #ifdef GETGUI
239   getgui_late_refresh();
240 #endif
241 
242 return( 0 );
243 }
244 
245 /* ======================================================= *
246  * Copyright 1998-2005 Stephen C. Grubb                    *
247  * http://ploticus.sourceforge.net                         *
248  * Covered by GPL; see the file ./Copyright for details.   *
249  * ======================================================= */
250