1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: driver_x11.cpp,v 1.2 2000/06/19 19:04:05 kevin Exp $
6 ** $Log: driver_x11.cpp,v $
7 ** Revision 1.2 2000/06/19 19:04:05 kevin
8 ** reorganized header files
10 ** Revision 1.1 2000/06/19 18:05:03 kevin
13 ** Revision 1.1 2000/05/08 20:08:15 kevin
14 ** *** empty log message ***
17 ** This program is free software; you can redistribute it and/or modify
18 ** it under the terms of the GNU General Public License (version 2) as
19 ** published by the Free Software Foundation.
21 ** This program is distributed in the hope that it will be useful,
22 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
23 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 ** GNU General Public License for more details.
26 ** You should have received a copy of the GNU General Public License
27 ** along with this program; if not, write to the Free Software
28 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 ******************************************************************************/
34 #include "ctsupport.h"
38 #include <X11/Xutil.h>
40 struct sgp_x11_driver {
46 typedef struct sgp_x11_driver SGP_X11_DRIVER;
48 SGP_X11_DRIVER sgp_x11;
54 sgp_x11.theDisplay = NULL;
55 for (i = 0; i < 2 && theDisplay == NULL; i++)
56 sgp_x11.theDisplay = XOpenDisplay( NULL );
58 if ( sgp_x11.theDisplay == NULL ) {
59 fprintf( stderr, "ERROR: Cannot establish a connection to the X Server %s\n", XDisplayName( NULL ));
63 sgp_x11.theScreen = DefaultScreen( sgp_x11.theDisplay );
64 sgp_x11.theDepth = DefaultDepth( sgp_x11.theDisplay, sgp_x11.theScreen );
69 printf("%s version %d of the X Window System, X%d R%d\n",
70 ServerVendor( sgp_x11.theDisplay ),
71 VendorRelease( sgp_x11.theDisplay ),
72 ProtocolVersion( sgp_x11.theDisplay ),
73 ProtocolRevision( sgp_x11.theDisplay ) );
75 if ( sgp_x11.theDepth == 1)
76 printf( "Color plane depth....................%d (monochrome)\n", sgp_x11.theDepth );
78 printf( "Color plane depth....................%d\n", sgp_x11.theDepth);
80 printf( "Display Width........................%d\n",
81 DisplayWidth( sgp_x11.theDisplay, sgp_x11.theScreen ));
82 printf( "Display Height.......................%d\n",
83 DisplayHeight( theDisplay, theScreen ));
84 printf( "The display %s\n", XDisplayName( sgp_x11.theDisplay ));
89 setlinestyle (LS_SOLID);
91 settext (XCHARSIZ, YCHARSIZ, 0.0, 0);
94 gp_set_aspect (CRTDEV, CRTASPT);
95 gp_set_aspect (PRTDEV, 1.0);
96 state.xndc = 10.; /* to guarntee a move */
97 stylus (0.0,0.0,0); /* move to starting corner */
101 initdevice (int dev, int mode, int xsize, int ysize)
103 // crt.dotfunc = crt_wdot;
104 // crt.linefunc = crt_line;
113 * gp_closedev Close device for output
117 * int dev Device handle
120 * Temporarily suspends output from going to a device
123 void sgpdrv_x11_term()
127 void sgpdrv_x11_line()
131 void sgpdrive_x11_point()
136 sgpdrv_x11_linestyle (int style)
139 state.linestyle = style;
141 // crt_line_style (crt.style);
145 sgpdrv_x11_linewidth (int wid)
147 state.linewidth = wid;
151 sgpdrv_x11_textparam (
153 double height, /* size of character in NDC */
154 double textangle, /* text angle */
155 int font /* text font */
160 CLIP(height, 0.0, 1.0);
161 CLIP(width, 0.0, 1.0);
162 /* textangle = textangle - (2 * PI * (int) (textangle / (2 * PI)));
165 cspec.height = height;
166 cspec.textangle = textangle;
169 if (textangle > - HALFPI / 2 && textangle < HALFPI / 2) {
171 cspec.textdir = XPLUS;
172 } else if (textangle > HALFPI / 2 && textangle < 3 * HALFPI / 2) {
173 cspec.updir = XMINUS;
174 cspec.textdir = YPLUS;
175 } else if (textangle > 3 * HALFPI / 2 && textangle < 5 * HALFPI / 2) {
176 cspec.updir = YMINUS;
177 cspec.textdir = XMINUS;
178 } else if (textangle > 5 * HALFPI / 2 && textangle < 7 * HALFPI / 2) {
180 cspec.textdir = YMINUS;
183 cspec.textdir = XPLUS;
186 if (cspec.updir == XMINUS || cspec.updir == XPLUS) {
192 crt.icwidth = width * crt.xsize + 0.5;
193 crt.icheight = height * crt.ysize + 0.5;
194 crt.icwidth = iclip (crt.icwidth, 8, crt.xsize);
195 crt.icheight = iclip (crt.icheight, 8, crt.ysize);
197 prt.icwidth = width * prt.xsize + 0.5;
198 prt.icheight = height * prt.ysize + 0.5;
199 prt.icwidth = iclip (prt.icwidth, 8, prt.xsize);
200 prt.icheight = iclip (prt.icheight, 8, prt.ysize);
204 sgpdrv_textcolor (int fore, int back)
210 prt.cfore = iclip (fore, 0, prt.colormax);
215 sgpdrv_color (int fore)
219 state.foregnd = fore;
220 back = state.backgnd;
221 crtcolor (crt.mode, &fore, &back); /* set colors on crt */
225 sgpdrv_backgroundg (int back)
229 state.backgnd = back;
230 fore = state.foregnd;
231 crtcolor (crt.mode, &fore, &back);
235 * INITMARKER (<SYMBOL>)
237 * Sets the current marker symbol (cross, square, diamond..)
239 void sgpdrv_marker (int marker, int color)
241 if (marker > NMARKERS || marker < 0)
244 state.marktype = marker;
245 state.markcolor = color;
248 } /* end initmarker */
251 * SETCHARDIR ( <DIRECTION> )
253 * indicates in which direction a string should be printed, e.g.:
254 * direction = YPLUS -> print on the horizontal from left to right
255 * direction = YMINUS -> print upside-down characters from right to left
256 * direction = XMINUS -> print on the vertical from down to up
257 * direction = XPLUS -> print on the vertical from up to down
259 void sgpdrv_x11_textdir (
260 int direction /* direction flag */
263 if (direction != XPLUS &&
264 direction != XMINUS &&
265 direction != YPLUS &&
266 direction != YMINUS ) {
267 printf("Error in character direction: %d\n", direction);
270 cspec.textdir = direction;
271 charsize (cspec.width, cspec.height);
275 void sgpdrv_x11_charsize (double wid, double height)
277 settext (wid, height, cspec.textangle, cspec.font);
281 sgpdrv_x11_textangle (double angle)
283 settext (cspec.width, cspec.height, angle, cspec.font);