WSTester updated to work plus hopefully all the other changes that need to go into...
[jabaws.git] / binaries / src / ViennaRNA / RNAforester / g2-0.70 / src / g2_control_pd.c
1 /*****************************************************************************
2 **  Copyright (C) 1998-2001  Ljubomir Milanovic & Horst Wagner
3 **  This file is part of the g2 library
4 **
5 **  This library is free software; you can redistribute it and/or
6 **  modify it under the terms of the GNU Lesser General Public
7 **  License as published by the Free Software Foundation; either
8 **  version 2.1 of the License, or (at your option) any later version.
9 **
10 **  This library is distributed in the hope that it will be useful,
11 **  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 **  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 **  Lesser General Public License for more details.
14 **
15 **  You should have received a copy of the GNU Lesser General Public
16 **  License along with this library; if not, write to the Free Software
17 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18 ******************************************************************************/
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <math.h>
22
23 #include "g2.h"
24 #include "g2_device.h"
25 #include "g2_physical_device.h"
26 #include "g2_util.h"
27 #include "g2_funix.h"
28
29
30
31 /*
32  *
33  * Flush output
34  *
35  */
36 void g2_flush_pd(g2_physical_device *pd)
37 {
38     if(pd->ff[g2_Flush].fun!=NULL) {
39         pd->ff[g2_Flush].fun(pd->pid, pd->pdp);
40     } else {
41         /* emulate ... with .... */  
42     }
43 }
44
45
46
47 /*
48  *
49  * Save output
50  *
51  */
52 void g2_save_pd(g2_physical_device *pd)
53 {
54     if(pd->ff[g2_Save].fun!=NULL) {
55         pd->ff[g2_Save].fun(pd->pid, pd->pdp);
56     } else {
57         /* emulate ... with .... */  
58     }
59 }
60
61
62
63 /*
64  *
65  * Clear device
66  *
67  */
68 void g2_clear_pd(g2_physical_device *pd)
69 {
70     if(pd->ff[g2_Clear].fun!=NULL) {
71         pd->ff[g2_Clear].fun(pd->pid, pd->pdp);
72     } else {
73         /* emulate ... with .... */  
74     }
75 }
76
77
78
79 /*
80  *
81  * Set pen
82  *
83  */
84 void g2_pen_pd(g2_physical_device *pd, int color)
85 {
86     if(pd->ff[g2_Pen].fun!=NULL) {
87         pd->ff[g2_Pen].fun(pd->pid, pd->pdp, color);
88     } else {
89         /* emulate ... with .... */  
90     }
91 }
92
93
94
95 /*
96  *
97  * Set background color
98  *
99  */
100 void g2_set_background_pd(g2_physical_device *pd, int color)
101 {
102     if(pd->ff[g2_SetBackground].fun!=NULL) {
103         pd->ff[g2_SetBackground].fun(pd->pid, pd->pdp, color);
104     } else {
105         /* emulate ... with .... */  
106     }
107 }
108
109
110
111 /*
112  *
113  * Set ink
114  *
115  */
116 int g2_ink_pd(g2_physical_device *pd, double red, double green, double blue)
117 {
118     int rv=-1;
119     
120     if(pd->ff[g2_Ink].fun!=NULL) {
121         rv=pd->ff[g2_Ink].fun(pd->pid, pd->pdp,
122                               red, green, blue);
123     } else {
124         /* emulate ... with .... */  
125     }
126     return rv;
127 }
128
129
130
131
132 /*
133  *
134  * Clear palette
135  *
136  */
137 void g2_clear_palette_pd(g2_physical_device *pd)
138 {
139     if(pd->ff[g2_ClearPalette].fun!=NULL) {
140         pd->ff[g2_ClearPalette].fun(pd->pid, pd->pdp);
141     } else {
142         /* emulate ... with .... */  
143     }
144 }
145
146
147 /*
148  *
149  * Allocate basic colors
150  *
151  */
152 void g2_allocate_basic_colors_pd(g2_physical_device *pd)
153 {
154     double ct[3]={0.0, 0.5, 1.0};
155     int r, g, b;
156     
157     if(pd->ff[g2_Ink].fun!=NULL) {
158         pd->ff[g2_Ink].fun(pd->pid, pd->pdp,      /* white */
159                            1.0, 1.0, 1.0);
160         pd->ff[g2_Ink].fun(pd->pid, pd->pdp,      /* black */
161                            0.0, 0.0, 0.0);
162         for(r=0;r<3;r++)
163             for(g=0;g<3;g++)
164                 for(b=0;b<3;b++)
165                     if((r==2 && g==2 && b==2) ||
166                        (r==0 && g==0 && b==0))
167                         continue;
168                     else
169                         pd->ff[g2_Ink].fun(pd->pid, pd->pdp,
170                                            ct[r], ct[g], ct[b]);
171     }  
172 }
173
174
175 /*
176  *
177  * Set font size
178  *
179  */
180 void g2_set_font_size_pd(g2_physical_device *pd, double size)
181 {
182     int is;
183     double ds;
184
185     if(pd->ff[g2_SetFontSize].fun!=NULL) {
186         switch(pd->coor_type) {
187           case g2_IntCoor:
188             is=dtoi(size*fabs(pd->a22));          /* to pd coordinates */
189             pd->ff[g2_SetFontSize].fun(pd->pid, pd->pdp, is);
190             break;
191           case g2_DoubleCoor:
192             ds=size*fabs(pd->a22);                /* to pd coordinates */
193             pd->ff[g2_SetFontSize].fun(pd->pid, pd->pdp, ds);
194             break;
195         }
196     } else {
197         /* emulate ... with .... */  
198     }
199 }
200
201
202
203 /*
204  *
205  * Set line width
206  *
207  */
208 void g2_set_line_width_pd(g2_physical_device *pd, double w)
209 {
210     int iw;
211     double dw;
212
213     if(pd->ff[g2_SetLineWidth].fun!=NULL) {
214         switch(pd->coor_type) {
215           case g2_IntCoor:
216             iw=dtoi(w*fabs(pd->a22));     /* to pd coordinates */
217             pd->ff[g2_SetLineWidth].fun(pd->pid, pd->pdp, iw);
218             break;
219           case g2_DoubleCoor:
220             dw=w*fabs(pd->a22);         /* to pd coordinates */
221             pd->ff[g2_SetLineWidth].fun(pd->pid, pd->pdp, dw);
222             break;
223         }
224     } else {
225         /* emulate ... with .... */  
226     }
227 }
228
229
230
231 /*
232  *
233  * Set dash
234  *
235  */
236 void g2_set_dash_pd(g2_physical_device *pd, int N, double *dashes)
237 {
238     int j;
239     double *dd=NULL;
240     int    *id=NULL;
241     
242     if(pd->ff[g2_SetDash].fun!=NULL) {
243         switch(pd->coor_type) {
244           case g2_IntCoor:
245             if(dashes!=NULL) {
246                 id=g2_malloc(N*sizeof(int));
247                 for(j=0;j<N;j++)
248                     id[j]=dtoi(dashes[j]*fabs(pd->a22));
249                 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, N, id);
250                 g2_free(id);
251             } else
252                 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, 0, NULL);
253             break;
254           case g2_DoubleCoor:
255             if(dashes!=NULL) {
256                 dd=g2_malloc(N*sizeof(double));
257                 for(j=0;j<N;j++)
258                     dd[j]=dashes[j]*fabs(pd->a22);
259                 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, N, dd);
260                 g2_free(dd);
261                 break;
262             } else
263                 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, 0, NULL);
264         }
265     } else {
266         /* emulate ... with .... */  
267     }
268 }
269
270
271
272 /*
273  *
274  * Query pointer position and button state
275  *
276  */
277 void g2_query_pointer_pd(g2_physical_device *pd,
278                          double *x, double *y, unsigned int *button)
279 {
280     int    ix, iy;
281     double dx, dy;
282
283     if(pd->ff[g2_QueryPointer].fun!=NULL) {
284         switch(pd->coor_type) {
285           case g2_IntCoor:
286             pd->ff[g2_QueryPointer].fun(pd->pid, pd->pdp,
287                                  &ix, &iy, button);
288             g2_pdc2uc(pd, ix, iy, x, y);
289             break;
290           case g2_DoubleCoor:
291             pd->ff[g2_QueryPointer].fun(pd->pid, pd->pdp,
292                                         &dx, &dy, button);
293             g2_pdc2uc(pd, dx, dy, x, y);
294             break;
295         }
296     } else {
297         /* no emulation for query pointer */
298     }
299 }
300
301
302 /*
303  *
304  * Get low level handles
305  *
306  */
307 void g2_get_pd_handles_pd(g2_physical_device *pd, void *handles[G2_PD_HANDLES_SIZE])
308 {
309     if(pd->ff[g2_GetPDHandles].fun!=NULL) {
310         pd->ff[g2_GetPDHandles].fun(pd->pid, pd->pdp, handles);
311     } else {
312         /* no emulation for low level handles */
313     }
314 }