1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: sgpdrive.cpp,v 1.1 2000/06/19 18:05:03 kevin Exp $
6 ** $Log: sgpdrive.cpp,v $
7 ** Revision 1.1 2000/06/19 18:05:03 kevin
10 ** Revision 1.2 2000/06/15 19:07:10 kevin
11 ** *** empty log message ***
13 ** Revision 1.1 2000/06/13 16:20:31 kevin
14 ** finished c++ conversions
16 ** Revision 1.7 2000/06/03 06:29:22 kevin
17 ** Finished g2 conditional compilation
19 ** Revision 1.6 2000/05/24 22:49:01 kevin
20 ** Updated SGP: first function X-windows version
22 ** Revision 1.5 2000/05/11 14:07:23 kevin
23 ** Fixed compilation warnings
25 ** Revision 1.4 2000/05/08 20:08:15 kevin
26 ** *** empty log message ***
28 ** Revision 1.3 2000/04/28 18:35:23 kevin
29 ** removed unused files
31 ** Revision 1.2 2000/04/28 13:50:45 kevin
32 ** Removed Makefile Makefile.in that are automatically generated by autoconf
34 ** Revision 1.1.1.1 2000/04/28 13:02:44 kevin
35 ** Initial CVS import for first public release
39 ** This program is free software; you can redistribute it and/or modify
40 ** it under the terms of the GNU General Public License (version 2) as
41 ** published by the Free Software Foundation.
43 ** This program is distributed in the hope that it will be useful,
44 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
45 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
46 ** GNU General Public License for more details.
48 ** You should have received a copy of the GNU General Public License
49 ** along with this program; if not, write to the Free Software
50 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
51 ******************************************************************************/
52 /* Device Driver for IBM PC Kevin Rosenberg March 84 */
62 static int init_prt(void);
63 static void term_prt(void);
65 /*===========================================================*/
66 /* fundamental device drivers */
67 /*===========================================================*/
69 #define XCHARSIZ (1.0 / 80.0) /* size of standard characters */
70 #define YCHARSIZ (1.0 / 25.0) /* on screen in NDC */
72 #define CRTASPT (0.75) /* for IBM ECD */
74 /*-------------------*/
75 /* print buffer data */
76 /*-------------------*/
82 #define PRTMODE 1 /* Epson 120 dot/in graphic mode */
83 #define PRTASPT (120.0 / 72.0) /* dots/in vectical / horizontal */
85 static DEVICE crt, prt;
87 static GRFSTATE state;
92 * gp_init Initialize graphics package
100 _sgp2_init_dev (SGP_ID cwin)
103 initdevice (CRTDEV, GM_ENHANCED, 0, 0);
104 initdevice (PRTDEV, PRTMODE, (int) (PRTSIZE * PRTASPT), PRTSIZE);
106 setlinestyle (LS_SOLID);
108 _sgp2_set_text (XCHARSIZ, YCHARSIZ, 0.0, 0);
111 gp_set_aspect (CRTDEV, CRTASPT);
112 gp_set_aspect (PRTDEV, 1.0);
115 state.xndc = 10.; /* to guarntee a move */
116 _sgp2_stylus (cwin, 0.0,0.0,0); /* move to starting corner */
123 * gp_initdev Initializes graphic device
126 * initdevice (dev, mode, xsize, ysize)
127 * int dev Device handle
128 * int mode Mode for device (device specific)
129 * int xsize Size of x buffer for PRTDEV
130 * int ysize Size of y buffer for PRTDEV
134 initdevice (int dev, int mode, int xsize, int ysize)
138 // crt.dotfunc = crt_wdot;
139 // crt.linefunc = crt_line;
189 case GM_1024x768x256:
200 // crt_set_mode (crt.mode, TRUE); /* Initialize device */
204 if (prt.open == TRUE)
205 closedevice (PRTDEV);
214 if (xsize > 1 && ysize > 1) {
219 prt.xmax = prt.xsize - 1;
220 prt.ymax = prt.ysize - 1;
224 // prt.dotfunc = prtdot;
225 // prt.linefunc = prtline;
227 init_prt (); /* Initialize the device */
235 * gp_opendev Open device for output
239 * int dev Device handle
240 * devices are number in powers of two
257 * gp_closedev Close device for output
261 * int dev Device handle
264 * Temporarily suspends output from going to a device
268 closedevice (int dev)
270 if (dev & CRTDEV) /* close crt */
285 static int init_prt(void)
291 static void term_prt(void)
295 /*===========================================================*/
296 /* stylus draws a line to the absolute point x,y in NDC's */
297 /* t=0 for move, t=1 for draw */
298 /*===========================================================*/
300 _sgp2_stylus (SGP_ID cwin, double x, double y, int beam)
304 if ((state.xndc == x) && (state.yndc == y) && (beam == 0))
305 return; /* no need to move */
307 state.xndc = x; /* save current beam location */
311 xp = (int) (x * cwin->pw_xsize + 0.5);
312 yp = (int) (y * cwin->pw_ysize + 0.5);
315 g2_line (cwin->g2_id, (double) cwin->phys_curx, (double) cwin->phys_cury, (double) xp, (double) yp);
317 cwin->phys_curx = xp;
318 cwin->phys_cury = yp;
323 pntndc (SGP_ID cwin, double x, double y)
325 _sgp2_stylus (cwin, x, y, 0); /* move to point */
326 // if (crt.open == TRUE)
327 // cpix_set (crt.icurx, crt.icury, crt.color);
331 markndc (SGP_ID cwin, double x, double y)
333 _sgp2_stylus (cwin, x, y, 0); /* move to point */
335 if (crt.open == TRUE)
336 wrtsymbol (state.marktype, crt.icurx, crt.icury, &crt);
338 if (prt.open == TRUE)
339 wrtsymbol (state.marktype, prt.icurx, prt.icury, &prt);
349 gp_set_aspect (int dev, double asp)
360 setlinestyle (int style)
362 if (style == state.linestyle)
365 state.linestyle = style;
370 // crt_line_style (crt.style);
374 setlinewidth (int wid)
376 state.linewidth = wid;
382 extern DEVICE prt, crt;
386 else if (dev & PRTDEV)
392 /*===========================================================*/
394 /*===========================================================*/
396 _sgp2_set_text ( SGP_ID cwin,
398 double height, /* size of character in NDC */
399 double textangle, /* text angle */
400 int font /* text font */
406 g2_set_font_size(cwin->g2_id, (height * cwin->pw_ysize));
408 height = clamp (height, 0.0, 1.0);
409 width = clamp (width, 0.0, 1.0);
410 /* textangle = textangle - (2 * PI * (int) (textangle / (2 * PI)));
413 cspec.height = height;
414 cspec.textangle = textangle;
417 if (textangle > - HALFPI / 2 && textangle < HALFPI / 2) {
419 cspec.textdir = XPLUS;
420 } else if (textangle > HALFPI / 2 && textangle < 3 * HALFPI / 2) {
421 cspec.updir = XMINUS;
422 cspec.textdir = YPLUS;
423 } else if (textangle > 3 * HALFPI / 2 && textangle < 5 * HALFPI / 2) {
424 cspec.updir = YMINUS;
425 cspec.textdir = XMINUS;
426 } else if (textangle > 5 * HALFPI / 2 && textangle < 7 * HALFPI / 2) {
428 cspec.textdir = YMINUS;
431 cspec.textdir = XPLUS;
434 if (cspec.updir == XMINUS || cspec.updir == XPLUS) {
440 crt.icwidth = (int) (width * crt.xsize + 0.5);
441 crt.icheight = (int) (height * crt.ysize + 0.5);
442 crt.icwidth = clamp (crt.icwidth, 8, crt.xsize);
443 crt.icheight = clamp (crt.icheight, 8, crt.ysize);
445 prt.icwidth = (int) (width * prt.xsize + 0.5);
446 prt.icheight = (int) (height * prt.ysize + 0.5);
447 prt.icwidth = clamp (prt.icwidth, 8, prt.xsize);
448 prt.icheight = clamp (prt.icheight, 8, prt.ysize);
452 settextclr (int fore, int back)
458 prt.cfore = clamp (fore, 0, prt.colormax);
467 state.foregnd = fore;
468 back = state.backgnd;
469 crtcolor (crt.mode, &fore, &back); /* set colors on crt */
471 prt.color = clamp (fore, 0, prt.colormax);
479 state.backgnd = back;
480 fore = state.foregnd;
481 crtcolor (crt.mode, &fore, &back);
485 * INITMARKER (<SYMBOL>)
487 * Sets the current marker symbol (cross, square, diamond..)
490 initmarker (int marker, int color)
492 if (marker > NMARKERS || marker < 0)
495 state.marktype = marker;
496 state.markcolor = color;
499 } /* end initmarker */
502 * SETCHARDIR ( <DIRECTION> )
504 * indicates in which direction a string should be printed, e.g.:
505 * direction = YPLUS -> print on the horizontal from left to right
506 * direction = YMINUS -> print upside-down characters from right to left
507 * direction = XMINUS -> print on the vertical from down to up
508 * direction = XPLUS -> print on the vertical from up to down
512 int direction /* direction flag */
516 if (direction != XPLUS &&
517 direction != XMINUS &&
518 direction != YPLUS &&
519 direction != YMINUS ) {
520 printf("Error in character direction: %d\n", direction);
523 cspec.textdir = direction;
524 charsize (cspec.width, cspec.height);
527 } /* end setchardir */
531 _sgp2_dev_text (SGP_ID cwin, char *message)
534 g2_string (cwin->g2_id, cwin->phys_curx, cwin->phys_cury, message);
538 /*===========================================================*/
539 /* terminate graphics to current device */
540 /* close any files, and output any buffers */
541 /*===========================================================*/
545 if (prt.open == TRUE) {
546 flushdevice (PRTDEV);
547 closedevice (PRTDEV);
551 if (crt.open == TRUE) {
552 closedevice (CRTDEV);
558 flushdevice (int dev)
561 // prtline (PRTTERM, 0, 0, 0, 0, 0, 0); /* print contents of printer buffer */