1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: driver_x11.cpp,v 1.1 2000/06/19 18:05:03 kevin Exp $
6 ** $Log: driver_x11.cpp,v $
7 ** Revision 1.1 2000/06/19 18:05:03 kevin
10 ** Revision 1.1 2000/05/08 20:08:15 kevin
11 ** *** empty log message ***
14 ** This program is free software; you can redistribute it and/or modify
15 ** it under the terms of the GNU General Public License (version 2) as
16 ** published by the Free Software Foundation.
18 ** This program is distributed in the hope that it will be useful,
19 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
20 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 ** GNU General Public License for more details.
23 ** You should have received a copy of the GNU General Public License
24 ** along with this program; if not, write to the Free Software
25 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 ******************************************************************************/
37 #include <X11/Xutil.h>
39 struct sgp_x11_driver {
45 typedef struct sgp_x11_driver SGP_X11_DRIVER;
47 SGP_X11_DRIVER sgp_x11;
53 sgp_x11.theDisplay = NULL;
54 for (i = 0; i < 2 && theDisplay == NULL; i++)
55 sgp_x11.theDisplay = XOpenDisplay( NULL );
57 if ( sgp_x11.theDisplay == NULL ) {
58 fprintf( stderr, "ERROR: Cannot establish a connection to the X Server %s\n", XDisplayName( NULL ));
62 sgp_x11.theScreen = DefaultScreen( sgp_x11.theDisplay );
63 sgp_x11.theDepth = DefaultDepth( sgp_x11.theDisplay, sgp_x11.theScreen );
68 printf("%s version %d of the X Window System, X%d R%d\n",
69 ServerVendor( sgp_x11.theDisplay ),
70 VendorRelease( sgp_x11.theDisplay ),
71 ProtocolVersion( sgp_x11.theDisplay ),
72 ProtocolRevision( sgp_x11.theDisplay ) );
74 if ( sgp_x11.theDepth == 1)
75 printf( "Color plane depth....................%d (monochrome)\n", sgp_x11.theDepth );
77 printf( "Color plane depth....................%d\n", sgp_x11.theDepth);
79 printf( "Display Width........................%d\n",
80 DisplayWidth( sgp_x11.theDisplay, sgp_x11.theScreen ));
81 printf( "Display Height.......................%d\n",
82 DisplayHeight( theDisplay, theScreen ));
83 printf( "The display %s\n", XDisplayName( sgp_x11.theDisplay ));
88 setlinestyle (LS_SOLID);
90 settext (XCHARSIZ, YCHARSIZ, 0.0, 0);
93 gp_set_aspect (CRTDEV, CRTASPT);
94 gp_set_aspect (PRTDEV, 1.0);
95 state.xndc = 10.; /* to guarntee a move */
96 stylus (0.0,0.0,0); /* move to starting corner */
100 initdevice (int dev, int mode, int xsize, int ysize)
102 // crt.dotfunc = crt_wdot;
103 // crt.linefunc = crt_line;
112 * gp_closedev Close device for output
116 * int dev Device handle
119 * Temporarily suspends output from going to a device
122 void sgpdrv_x11_term()
126 void sgpdrv_x11_line()
130 void sgpdrive_x11_point()
135 sgpdrv_x11_linestyle (int style)
138 state.linestyle = style;
140 // crt_line_style (crt.style);
144 sgpdrv_x11_linewidth (int wid)
146 state.linewidth = wid;
150 sgpdrv_x11_textparam (
152 double height, /* size of character in NDC */
153 double textangle, /* text angle */
154 int font /* text font */
159 CLIP(height, 0.0, 1.0);
160 CLIP(width, 0.0, 1.0);
161 /* textangle = textangle - (2 * PI * (int) (textangle / (2 * PI)));
164 cspec.height = height;
165 cspec.textangle = textangle;
168 if (textangle > - HALFPI / 2 && textangle < HALFPI / 2) {
170 cspec.textdir = XPLUS;
171 } else if (textangle > HALFPI / 2 && textangle < 3 * HALFPI / 2) {
172 cspec.updir = XMINUS;
173 cspec.textdir = YPLUS;
174 } else if (textangle > 3 * HALFPI / 2 && textangle < 5 * HALFPI / 2) {
175 cspec.updir = YMINUS;
176 cspec.textdir = XMINUS;
177 } else if (textangle > 5 * HALFPI / 2 && textangle < 7 * HALFPI / 2) {
179 cspec.textdir = YMINUS;
182 cspec.textdir = XPLUS;
185 if (cspec.updir == XMINUS || cspec.updir == XPLUS) {
191 crt.icwidth = width * crt.xsize + 0.5;
192 crt.icheight = height * crt.ysize + 0.5;
193 crt.icwidth = iclip (crt.icwidth, 8, crt.xsize);
194 crt.icheight = iclip (crt.icheight, 8, crt.ysize);
196 prt.icwidth = width * prt.xsize + 0.5;
197 prt.icheight = height * prt.ysize + 0.5;
198 prt.icwidth = iclip (prt.icwidth, 8, prt.xsize);
199 prt.icheight = iclip (prt.icheight, 8, prt.ysize);
203 sgpdrv_textcolor (int fore, int back)
209 prt.cfore = iclip (fore, 0, prt.colormax);
214 sgpdrv_color (int fore)
218 state.foregnd = fore;
219 back = state.backgnd;
220 crtcolor (crt.mode, &fore, &back); /* set colors on crt */
224 sgpdrv_backgroundg (int back)
228 state.backgnd = back;
229 fore = state.foregnd;
230 crtcolor (crt.mode, &fore, &back);
234 * INITMARKER (<SYMBOL>)
236 * Sets the current marker symbol (cross, square, diamond..)
238 void sgpdrv_marker (int marker, int color)
240 if (marker > NMARKERS || marker < 0)
243 state.marktype = marker;
244 state.markcolor = color;
247 } /* end initmarker */
250 * SETCHARDIR ( <DIRECTION> )
252 * indicates in which direction a string should be printed, e.g.:
253 * direction = YPLUS -> print on the horizontal from left to right
254 * direction = YMINUS -> print upside-down characters from right to left
255 * direction = XMINUS -> print on the vertical from down to up
256 * direction = XPLUS -> print on the vertical from up to down
258 void sgpdrv_x11_textdir (
259 int direction /* direction flag */
262 if (direction != XPLUS &&
263 direction != XMINUS &&
264 direction != YPLUS &&
265 direction != YMINUS ) {
266 printf("Error in character direction: %d\n", direction);
269 cspec.textdir = direction;
270 charsize (cspec.width, cspec.height);
274 void sgpdrv_x11_charsize (double wid, double height)
276 settext (wid, height, cspec.textangle, cspec.font);
280 sgpdrv_x11_textangle (double angle)
282 settext (cspec.width, cspec.height, angle, cspec.font);