1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sgpdrive.cpp,v 1.2 2000/06/19 18:44:51 kevin Exp $
6 ** $Log: sgpdrive.cpp,v $
7 ** Revision 1.2 2000/06/19 18:44:51 kevin
8 ** *** empty log message ***
10 ** Revision 1.1 2000/06/19 18:05:03 kevin
13 ** Revision 1.2 2000/06/15 19:07:10 kevin
14 ** *** empty log message ***
16 ** Revision 1.1 2000/06/13 16:20:31 kevin
17 ** finished c++ conversions
19 ** Revision 1.7 2000/06/03 06:29:22 kevin
20 ** Finished g2 conditional compilation
22 ** Revision 1.6 2000/05/24 22:49:01 kevin
23 ** Updated SGP: first function X-windows version
25 ** Revision 1.5 2000/05/11 14:07:23 kevin
26 ** Fixed compilation warnings
28 ** Revision 1.4 2000/05/08 20:08:15 kevin
29 ** *** empty log message ***
31 ** Revision 1.3 2000/04/28 18:35:23 kevin
32 ** removed unused files
34 ** Revision 1.2 2000/04/28 13:50:45 kevin
35 ** Removed Makefile Makefile.in that are automatically generated by autoconf
37 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
38 ** Initial CVS import for first public release
42 ** This program is free software; you can redistribute it and/or modify
43 ** it under the terms of the GNU General Public License (version 2) as
44 ** published by the Free Software Foundation.
46 ** This program is distributed in the hope that it will be useful,
47 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
48 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
49 ** GNU General Public License for more details.
51 ** You should have received a copy of the GNU General Public License
52 ** along with this program; if not, write to the Free Software
53 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
54 ******************************************************************************/
55 /* Device Driver for IBM PC Kevin Rosenberg March 84 */
65 static int init_prt(void);
66 static void term_prt(void);
68 /*===========================================================*/
69 /* fundamental device drivers */
70 /*===========================================================*/
72 #define XCHARSIZ (1.0 / 80.0) /* size of standard characters */
73 #define YCHARSIZ (1.0 / 25.0) /* on screen in NDC */
75 #define CRTASPT (0.75) /* for IBM ECD */
77 /*-------------------*/
78 /* print buffer data */
79 /*-------------------*/
85 #define PRTMODE 1 /* Epson 120 dot/in graphic mode */
86 #define PRTASPT (120.0 / 72.0) /* dots/in vectical / horizontal */
88 static DEVICE crt, prt;
90 static GRFSTATE state;
95 * gp_init Initialize graphics package
103 _sgp2_init_dev (SGP_ID cwin)
106 initdevice (CRTDEV, GM_ENHANCED, 0, 0);
107 initdevice (PRTDEV, PRTMODE, (int) (PRTSIZE * PRTASPT), PRTSIZE);
109 setlinestyle (LS_SOLID);
111 _sgp2_set_text (XCHARSIZ, YCHARSIZ, 0.0, 0);
114 gp_set_aspect (CRTDEV, CRTASPT);
115 gp_set_aspect (PRTDEV, 1.0);
118 state.xndc = 10.; /* to guarntee a move */
119 _sgp2_stylus (cwin, 0.0,0.0,0); /* move to starting corner */
126 * gp_initdev Initializes graphic device
129 * initdevice (dev, mode, xsize, ysize)
130 * int dev Device handle
131 * int mode Mode for device (device specific)
132 * int xsize Size of x buffer for PRTDEV
133 * int ysize Size of y buffer for PRTDEV
137 initdevice (int dev, int mode, int xsize, int ysize)
141 // crt.dotfunc = crt_wdot;
142 // crt.linefunc = crt_line;
192 case GM_1024x768x256:
203 // crt_set_mode (crt.mode, TRUE); /* Initialize device */
207 if (prt.open == TRUE)
208 closedevice (PRTDEV);
217 if (xsize > 1 && ysize > 1) {
222 prt.xmax = prt.xsize - 1;
223 prt.ymax = prt.ysize - 1;
227 // prt.dotfunc = prtdot;
228 // prt.linefunc = prtline;
230 init_prt (); /* Initialize the device */
238 * gp_opendev Open device for output
242 * int dev Device handle
243 * devices are number in powers of two
260 * gp_closedev Close device for output
264 * int dev Device handle
267 * Temporarily suspends output from going to a device
271 closedevice (int dev)
273 if (dev & CRTDEV) /* close crt */
288 static int init_prt(void)
294 static void term_prt(void)
298 /*===========================================================*/
299 /* stylus draws a line to the absolute point x,y in NDC's */
300 /* t=0 for move, t=1 for draw */
301 /*===========================================================*/
303 _sgp2_stylus (SGP_ID cwin, double x, double y, int beam)
307 if ((state.xndc == x) && (state.yndc == y) && (beam == 0))
308 return; /* no need to move */
310 state.xndc = x; /* save current beam location */
314 xp = (int) (x * cwin->pw_xsize + 0.5);
315 yp = (int) (y * cwin->pw_ysize + 0.5);
318 g2_line (cwin->g2_id, (double) cwin->phys_curx, (double) cwin->phys_cury, (double) xp, (double) yp);
320 cwin->phys_curx = xp;
321 cwin->phys_cury = yp;
326 pntndc (SGP_ID cwin, double x, double y)
328 _sgp2_stylus (cwin, x, y, 0); /* move to point */
329 // if (crt.open == TRUE)
330 // cpix_set (crt.icurx, crt.icury, crt.color);
334 markndc (SGP_ID cwin, double x, double y)
336 _sgp2_stylus (cwin, x, y, 0); /* move to point */
338 if (crt.open == TRUE)
339 wrtsymbol (state.marktype, crt.icurx, crt.icury, &crt);
341 if (prt.open == TRUE)
342 wrtsymbol (state.marktype, prt.icurx, prt.icury, &prt);
352 gp_set_aspect (int dev, double asp)
363 setlinestyle (int style)
365 if (style == state.linestyle)
368 state.linestyle = style;
373 // crt_line_style (crt.style);
377 setlinewidth (int wid)
379 state.linewidth = wid;
387 else if (dev & PRTDEV)
393 /*===========================================================*/
395 /*===========================================================*/
397 _sgp2_set_text ( SGP_ID cwin,
399 double height, /* size of character in NDC */
400 double textangle, /* text angle */
401 int font /* text font */
407 g2_set_font_size(cwin->g2_id, (height * cwin->pw_ysize));
409 height = clamp (height, 0.0, 1.0);
410 width = clamp (width, 0.0, 1.0);
411 /* textangle = textangle - (2 * PI * (int) (textangle / (2 * PI)));
414 cspec.height = height;
415 cspec.textangle = textangle;
418 if (textangle > - HALFPI / 2 && textangle < HALFPI / 2) {
420 cspec.textdir = XPLUS;
421 } else if (textangle > HALFPI / 2 && textangle < 3 * HALFPI / 2) {
422 cspec.updir = XMINUS;
423 cspec.textdir = YPLUS;
424 } else if (textangle > 3 * HALFPI / 2 && textangle < 5 * HALFPI / 2) {
425 cspec.updir = YMINUS;
426 cspec.textdir = XMINUS;
427 } else if (textangle > 5 * HALFPI / 2 && textangle < 7 * HALFPI / 2) {
429 cspec.textdir = YMINUS;
432 cspec.textdir = XPLUS;
435 if (cspec.updir == XMINUS || cspec.updir == XPLUS) {
441 crt.icwidth = (int) (width * crt.xsize + 0.5);
442 crt.icheight = (int) (height * crt.ysize + 0.5);
443 crt.icwidth = clamp (crt.icwidth, 8, crt.xsize);
444 crt.icheight = clamp (crt.icheight, 8, crt.ysize);
446 prt.icwidth = (int) (width * prt.xsize + 0.5);
447 prt.icheight = (int) (height * prt.ysize + 0.5);
448 prt.icwidth = clamp (prt.icwidth, 8, prt.xsize);
449 prt.icheight = clamp (prt.icheight, 8, prt.ysize);
453 settextclr (int fore, int back)
459 prt.cfore = clamp (fore, 0, prt.colormax);
468 state.foregnd = fore;
469 back = state.backgnd;
470 crtcolor (crt.mode, &fore, &back); /* set colors on crt */
472 prt.color = clamp (fore, 0, prt.colormax);
480 state.backgnd = back;
481 fore = state.foregnd;
482 crtcolor (crt.mode, &fore, &back);
486 * INITMARKER (<SYMBOL>)
488 * Sets the current marker symbol (cross, square, diamond..)
491 initmarker (int marker, int color)
493 if (marker > NMARKERS || marker < 0)
496 state.marktype = marker;
497 state.markcolor = color;
500 } /* end initmarker */
503 * SETCHARDIR ( <DIRECTION> )
505 * indicates in which direction a string should be printed, e.g.:
506 * direction = YPLUS -> print on the horizontal from left to right
507 * direction = YMINUS -> print upside-down characters from right to left
508 * direction = XMINUS -> print on the vertical from down to up
509 * direction = XPLUS -> print on the vertical from up to down
513 int direction /* direction flag */
517 if (direction != XPLUS &&
518 direction != XMINUS &&
519 direction != YPLUS &&
520 direction != YMINUS ) {
521 printf("Error in character direction: %d\n", direction);
524 cspec.textdir = direction;
525 charsize (cspec.width, cspec.height);
528 } /* end setchardir */
532 _sgp2_dev_text (SGP_ID cwin, char *message)
535 g2_string (cwin->g2_id, cwin->phys_curx, cwin->phys_cury, message);
539 /*===========================================================*/
540 /* terminate graphics to current device */
541 /* close any files, and output any buffers */
542 /*===========================================================*/
546 if (prt.open == TRUE) {
547 flushdevice (PRTDEV);
548 closedevice (PRTDEV);
552 if (crt.open == TRUE) {
553 closedevice (CRTDEV);
559 flushdevice (int dev)
562 // prtline (PRTTERM, 0, 0, 0, 0, 0, 0); /* print contents of printer buffer */