1 /*****************************************************************************
2 ** Copyright (C) 1998-2001 Ljubomir Milanovic & Horst Wagner
3 ** This file is part of the g2 library
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.
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.
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 ******************************************************************************/
24 #include "g2_device.h"
25 #include "g2_physical_device.h"
36 void g2_flush_pd(g2_physical_device *pd)
38 if(pd->ff[g2_Flush].fun!=NULL) {
39 pd->ff[g2_Flush].fun(pd->pid, pd->pdp);
41 /* emulate ... with .... */
52 void g2_save_pd(g2_physical_device *pd)
54 if(pd->ff[g2_Save].fun!=NULL) {
55 pd->ff[g2_Save].fun(pd->pid, pd->pdp);
57 /* emulate ... with .... */
68 void g2_clear_pd(g2_physical_device *pd)
70 if(pd->ff[g2_Clear].fun!=NULL) {
71 pd->ff[g2_Clear].fun(pd->pid, pd->pdp);
73 /* emulate ... with .... */
84 void g2_pen_pd(g2_physical_device *pd, int color)
86 if(pd->ff[g2_Pen].fun!=NULL) {
87 pd->ff[g2_Pen].fun(pd->pid, pd->pdp, color);
89 /* emulate ... with .... */
97 * Set background color
100 void g2_set_background_pd(g2_physical_device *pd, int color)
102 if(pd->ff[g2_SetBackground].fun!=NULL) {
103 pd->ff[g2_SetBackground].fun(pd->pid, pd->pdp, color);
105 /* emulate ... with .... */
116 int g2_ink_pd(g2_physical_device *pd, double red, double green, double blue)
120 if(pd->ff[g2_Ink].fun!=NULL) {
121 rv=pd->ff[g2_Ink].fun(pd->pid, pd->pdp,
124 /* emulate ... with .... */
137 void g2_clear_palette_pd(g2_physical_device *pd)
139 if(pd->ff[g2_ClearPalette].fun!=NULL) {
140 pd->ff[g2_ClearPalette].fun(pd->pid, pd->pdp);
142 /* emulate ... with .... */
149 * Allocate basic colors
152 void g2_allocate_basic_colors_pd(g2_physical_device *pd)
154 double ct[3]={0.0, 0.5, 1.0};
157 if(pd->ff[g2_Ink].fun!=NULL) {
158 pd->ff[g2_Ink].fun(pd->pid, pd->pdp, /* white */
160 pd->ff[g2_Ink].fun(pd->pid, pd->pdp, /* black */
165 if((r==2 && g==2 && b==2) ||
166 (r==0 && g==0 && b==0))
169 pd->ff[g2_Ink].fun(pd->pid, pd->pdp,
170 ct[r], ct[g], ct[b]);
180 void g2_set_font_size_pd(g2_physical_device *pd, double size)
185 if(pd->ff[g2_SetFontSize].fun!=NULL) {
186 switch(pd->coor_type) {
188 is=dtoi(size*fabs(pd->a22)); /* to pd coordinates */
189 pd->ff[g2_SetFontSize].fun(pd->pid, pd->pdp, is);
192 ds=size*fabs(pd->a22); /* to pd coordinates */
193 pd->ff[g2_SetFontSize].fun(pd->pid, pd->pdp, ds);
197 /* emulate ... with .... */
208 void g2_set_line_width_pd(g2_physical_device *pd, double w)
213 if(pd->ff[g2_SetLineWidth].fun!=NULL) {
214 switch(pd->coor_type) {
216 iw=dtoi(w*fabs(pd->a22)); /* to pd coordinates */
217 pd->ff[g2_SetLineWidth].fun(pd->pid, pd->pdp, iw);
220 dw=w*fabs(pd->a22); /* to pd coordinates */
221 pd->ff[g2_SetLineWidth].fun(pd->pid, pd->pdp, dw);
225 /* emulate ... with .... */
236 void g2_set_dash_pd(g2_physical_device *pd, int N, double *dashes)
242 if(pd->ff[g2_SetDash].fun!=NULL) {
243 switch(pd->coor_type) {
246 id=g2_malloc(N*sizeof(int));
248 id[j]=dtoi(dashes[j]*fabs(pd->a22));
249 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, N, id);
252 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, 0, NULL);
256 dd=g2_malloc(N*sizeof(double));
258 dd[j]=dashes[j]*fabs(pd->a22);
259 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, N, dd);
263 pd->ff[g2_SetDash].fun(pd->pid, pd->pdp, 0, NULL);
266 /* emulate ... with .... */
274 * Query pointer position and button state
277 void g2_query_pointer_pd(g2_physical_device *pd,
278 double *x, double *y, unsigned int *button)
283 if(pd->ff[g2_QueryPointer].fun!=NULL) {
284 switch(pd->coor_type) {
286 pd->ff[g2_QueryPointer].fun(pd->pid, pd->pdp,
288 g2_pdc2uc(pd, ix, iy, x, y);
291 pd->ff[g2_QueryPointer].fun(pd->pid, pd->pdp,
293 g2_pdc2uc(pd, dx, dy, x, y);
297 /* no emulation for query pointer */
304 * Get low level handles
307 void g2_get_pd_handles_pd(g2_physical_device *pd, void *handles[G2_PD_HANDLES_SIZE])
309 if(pd->ff[g2_GetPDHandles].fun!=NULL) {
310 pd->ff[g2_GetPDHandles].fun(pd->pid, pd->pdp, handles);
312 /* no emulation for low level handles */