From: Kevin M. Rosenberg Date: Mon, 19 Jun 2000 19:20:11 +0000 (+0000) Subject: r112: *** empty log message *** X-Git-Tag: debian-4.5.3-3~905 X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=commitdiff_plain;h=37ccf79b1044c04db41f5cf924f63c75be1c2366 r112: *** empty log message *** --- diff --git a/libctgraphics/Makefile.am b/libctgraphics/Makefile.am index 7bc2d47..5daeb60 100644 --- a/libctgraphics/Makefile.am +++ b/libctgraphics/Makefile.am @@ -1,5 +1,5 @@ noinst_LIBRARIES = libctgraphics.a -libctgraphics_a_SOURCES=ezplot.cpp ezsupport.cpp ezset.cpp ezpol.cpp circle.cpp ctm.cpp drawbox.cpp sgp.cpp sgpdrive.cpp sgptext.cpp +libctgraphics_a_SOURCES=ezplot.cpp ezsupport.cpp ezset.cpp ezpol.cpp ctm.cpp sgp.cpp sgpdriver.cpp sgptext.cpp INCLUDES=@my_includes@ EXTRA_DIST=Makefile.nt diff --git a/libctgraphics/circle.cpp b/libctgraphics/circle.cpp deleted file mode 100644 index 5c74dee..0000000 --- a/libctgraphics/circle.cpp +++ /dev/null @@ -1,93 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: circle.cpp,v 1.2 2000/06/19 19:04:05 kevin Exp $ -** $Log: circle.cpp,v $ -** Revision 1.2 2000/06/19 19:04:05 kevin -** reorganized header files -** -** Revision 1.1 2000/06/19 18:05:03 kevin -** initial cvs import -** -** Revision 1.1 2000/06/13 16:20:31 kevin -** finished c++ conversions -** -** Revision 1.2 2000/05/24 22:49:01 kevin -** Updated SGP: first function X-windows version -** -** Revision 1.1.1.1 2000/04/28 13:02:44 kevin -** Initial CVS import for first public release -** -** -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License (version 2) as -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* FUNCTION - * sgp2_circle - draw circle of radius r at current center - */ - -#include "math.h" -#include "ctsupport.h" -#include "sgp.h" - -void -sgp2_draw_circle (const double r) -{ - sgp2_draw_arc (0.0, 7.0, r); -} - -/*==============================================================*/ -/* draw arc around current center. pass angles and radius */ -/*==============================================================*/ - -void -sgp2_draw_arc (double start, double stop, const double r) -{ - double c, s, theta, angle; - float x, y, xp, yp; - - if ((stop-start) > 2 * PI) - stop = start + 2 * PI; - if ((start-stop) > 2 * PI) - stop = start + 2 * PI; - while (start >= stop) - stop += 2*PI; - - x = r * cos ((double) start); - y = r * sin ((double) start); - sgp2_move_rel (x, y); /* move from center to start of arc */ - - theta = 5 * PI / 180; - c = cos(theta); - s = sin(theta); - - for (angle = start; angle < stop - theta; angle += theta) { - xp = c * x - s * y; - yp = s * x + c * y; - sgp2_line_rel (xp - x, yp - y); - x = xp; y = yp; - } - - c = cos (stop - angle); - s = sin (stop - angle); - xp = c * x - s * y; - yp = s * x + c * y; - sgp2_line_rel (xp - x, yp - y); - - x = r * cos ((double) stop); - y = r * sin ((double) stop); - sgp2_move_rel (-x, -y); /* move back to center of circle */ -} diff --git a/libctgraphics/drawbox.cpp b/libctgraphics/drawbox.cpp deleted file mode 100644 index f0bc899..0000000 --- a/libctgraphics/drawbox.cpp +++ /dev/null @@ -1,44 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: drawbox.cpp,v 1.2 2000/06/19 19:04:05 kevin Exp $ -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License (version 2) as -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* NAME - * sgp2_draw_rect Draw box in graphics mode - * - * SYNOPSIS - * drawbox (xmin, ymin, xmax, ymax) - * double xmin, ymin Lower left corner of box - * double xmax, ymax Upper left corner of box - * - * NOTES - * This routine leaves the current position of graphic cursor at lower - * left corner of box. - */ - -#include "sgp.h" - -void -sgp2_draw_rect(double xmin, double ymin, double xmax, double ymax) -{ - sgp2_move_abs (xmin, ymin); - sgp2_line_abs (xmax, ymin); - sgp2_line_abs (xmax, ymax); - sgp2_line_abs (xmin, ymax); - sgp2_line_abs (xmin, ymin); -} diff --git a/libctgraphics/sgp.cpp b/libctgraphics/sgp.cpp index 55d3c0e..cc87671 100644 --- a/libctgraphics/sgp.cpp +++ b/libctgraphics/sgp.cpp @@ -7,7 +7,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: sgp.cpp,v 1.2 2000/06/19 19:04:05 kevin Exp $ +** $Id: sgp.cpp,v 1.3 2000/06/19 19:16:17 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -448,6 +448,83 @@ sgp2_point_rel (double x, double y) } +/* NAME + * sgp2_draw_rect Draw box in graphics mode + * + * SYNOPSIS + * drawbox (xmin, ymin, xmax, ymax) + * double xmin, ymin Lower left corner of box + * double xmax, ymax Upper left corner of box + * + * NOTES + * This routine leaves the current position of graphic cursor at lower + * left corner of box. + */ + +void +sgp2_draw_rect(double xmin, double ymin, double xmax, double ymax) +{ + sgp2_move_abs (xmin, ymin); + sgp2_line_abs (xmax, ymin); + sgp2_line_abs (xmax, ymax); + sgp2_line_abs (xmin, ymax); + sgp2_line_abs (xmin, ymin); +} + +/* FUNCTION + * sgp2_circle - draw circle of radius r at current center + */ + +void +sgp2_draw_circle (const double r) +{ + sgp2_draw_arc (0.0, 7.0, r); +} + +/*==============================================================*/ +/* draw arc around current center. pass angles and radius */ +/*==============================================================*/ + +void +sgp2_draw_arc (double start, double stop, const double r) +{ + double c, s, theta, angle; + float x, y, xp, yp; + + if ((stop-start) > 2 * PI) + stop = start + 2 * PI; + if ((start-stop) > 2 * PI) + stop = start + 2 * PI; + while (start >= stop) + stop += 2*PI; + + x = r * cos ((double) start); + y = r * sin ((double) start); + sgp2_move_rel (x, y); /* move from center to start of arc */ + + theta = 5 * PI / 180; + c = cos(theta); + s = sin(theta); + + for (angle = start; angle < stop - theta; angle += theta) { + xp = c * x - s * y; + yp = s * x + c * y; + sgp2_line_rel (xp - x, yp - y); + x = xp; y = yp; + } + + c = cos (stop - angle); + s = sin (stop - angle); + xp = c * x - s * y; + yp = s * x + c * y; + sgp2_line_rel (xp - x, yp - y); + + x = r * cos ((double) stop); + y = r * sin ((double) stop); + sgp2_move_rel (-x, -y); /* move back to center of circle */ +} + + /*----------------------------------------------------------------------*/ /* Current Transformation Matrix Routine */ /*----------------------------------------------------------------------*/ diff --git a/libctgraphics/sgpdrive.cpp b/libctgraphics/sgpdrive.cpp deleted file mode 100644 index 09445ba..0000000 --- a/libctgraphics/sgpdrive.cpp +++ /dev/null @@ -1,528 +0,0 @@ -/***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg -** -** $Id: sgpdrive.cpp,v 1.3 2000/06/19 19:04:05 kevin Exp $ -** -** This program is free software; you can redistribute it and/or modify -** it under the terms of the GNU General Public License (version 2) as -** published by the Free Software Foundation. -** -** This program is distributed in the hope that it will be useful, -** but WITHOUT ANY WARRANTY; without even the implied warranty of -** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -** GNU General Public License for more details. -** -** You should have received a copy of the GNU General Public License -** along with this program; if not, write to the Free Software -** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -******************************************************************************/ - -/* Device Driver for IBM PC Kevin Rosenberg March 84 */ - -#include -#include -#include -#include "ctsupport.h" -#include "sgp.h" - - -static int init_prt(void); -static void term_prt(void); - -/*===========================================================*/ -/* fundamental device drivers */ -/*===========================================================*/ - -#define XCHARSIZ (1.0 / 80.0) /* size of standard characters */ -#define YCHARSIZ (1.0 / 25.0) /* on screen in NDC */ - -#define CRTASPT (0.75) /* for IBM ECD */ - -/*-------------------*/ -/* print buffer data */ -/*-------------------*/ -#define PRTINIT 1 -#define PRTLIN 2 -#define PRTTERM 3 - -#define PRTSIZE 200 -#define PRTMODE 1 /* Epson 120 dot/in graphic mode */ -#define PRTASPT (120.0 / 72.0) /* dots/in vectical / horizontal */ - -static DEVICE crt, prt; -CHARSPEC cspec; -static GRFSTATE state; - - - -/* NAME - * gp_init Initialize graphics package - * - * SYNOPSIS - * gp_init() - */ - - -int -_sgp2_init_dev (SGP_ID cwin) -{ -#if 0 - initdevice (CRTDEV, GM_ENHANCED, 0, 0); - initdevice (PRTDEV, PRTMODE, (int) (PRTSIZE * PRTASPT), PRTSIZE); - opendevice (CRTDEV); - setlinestyle (LS_SOLID); - setcolor (1); - _sgp2_set_text (XCHARSIZ, YCHARSIZ, 0.0, 0); - setbackg (0); - settextclr (1, 0); - gp_set_aspect (CRTDEV, CRTASPT); - gp_set_aspect (PRTDEV, 1.0); -#endif - - state.xndc = 10.; /* to guarntee a move */ - _sgp2_stylus (cwin, 0.0,0.0,0); /* move to starting corner */ - - return (TRUE); -} - - -/* NAME - * gp_initdev Initializes graphic device - * - * SYNOPSIS - * initdevice (dev, mode, xsize, ysize) - * int dev Device handle - * int mode Mode for device (device specific) - * int xsize Size of x buffer for PRTDEV - * int ysize Size of y buffer for PRTDEV - */ - -int -initdevice (int dev, int mode, int xsize, int ysize) -{ - if (dev & CRTDEV) - { - // crt.dotfunc = crt_wdot; - // crt.linefunc = crt_line; - crt.xmin = 0; - crt.ymin = 0; - switch (crt.mode) - { -#if 0 - case 4: - case 5: - crt.xmax = 319; - crt.xsize = 320; - crt.ymax = 199; - crt.ysize = 200; - crt.colormax = 3; - break; - case GM_640x200: - crt.xmax = 639; - crt.xsize = 640; - crt.ymax = 199; - crt.ysize = 200; - crt.colormax = 1; - break; - case GM_ENHANCED: - case GM_MONOGRF: - crt.xmax = 639; - crt.xsize = 640; - crt.ymax = 349; - crt.ysize = 350; - crt.colormax = 15; - break; - case GM_640x480x16: - crt.xmax = 639; - crt.xsize = 640; - crt.ymax = 479; - crt.ysize = 480; - crt.colormax = 15; - break; - case GM_640x480x256: - crt.xmax = 639; - crt.xsize = 640; - crt.ymax = 479; - crt.ysize = 480; - crt.colormax = 255; - break; - case GM_1024x768x16: - crt.xmax = 1023; - crt.xsize = 1024; - crt.ymax = 767; - crt.ysize = 768; - crt.colormax = 15; - break; - case GM_1024x768x256: - crt.xmax = 1023; - crt.xsize = 1024; - crt.ymax = 767; - crt.ysize = 768; - crt.colormax = 255; - break; -#endif - default: - return (FALSE); - } - // crt_set_mode (crt.mode, TRUE); /* Initialize device */ - } - - if (dev & PRTDEV) { - if (prt.open == TRUE) - closedevice (PRTDEV); - prt.buf = NULL; - if (mode < 0) - prt.mode = PRTMODE; - if (mode > 6) - prt.mode = PRTMODE; - else - prt.mode = mode; - - if (xsize > 1 && ysize > 1) { - prt.xsize = xsize; - prt.ysize = ysize; - prt.xmin = 0; - prt.ymin = 0; - prt.xmax = prt.xsize - 1; - prt.ymax = prt.ysize - 1; - } - - prt.colormax = 1; - // prt.dotfunc = prtdot; - // prt.linefunc = prtline; - - init_prt (); /* Initialize the device */ - } - - return (TRUE); -} - - -/* NAME - * gp_opendev Open device for output - * - * SYNOPSIS - * gp_opendev (dev) - * int dev Device handle - * devices are number in powers of two - */ - -int -opendevice (int dev) -{ - if (dev & CRTDEV) - crt.open = TRUE; - - if (dev & PRTDEV) - prt.open = TRUE; - - return(TRUE); -} - - -/* NAME - * gp_closedev Close device for output - * - * SYNOPSIS - * gp_closedev (dev) - * int dev Device handle - * - * DESCRIPTION - * Temporarily suspends output from going to a device - */ - -void -closedevice (int dev) -{ - if (dev & CRTDEV) /* close crt */ - crt.open = FALSE; - - if (dev & PRTDEV) - prt.open = FALSE; -} - - -void -termdevice (int dev) -{ - if (dev & PRTDEV) - term_prt (); -} - -static int init_prt(void) -{ - return(0); -} - - -static void term_prt(void) -{ -} - -/*===========================================================*/ -/* stylus draws a line to the absolute point x,y in NDC's */ -/* t=0 for move, t=1 for draw */ -/*===========================================================*/ -void -_sgp2_stylus (SGP_ID cwin, double x, double y, int beam) -{ - int xp, yp; - - if ((state.xndc == x) && (state.yndc == y) && (beam == 0)) - return; /* no need to move */ - - state.xndc = x; /* save current beam location */ - state.yndc = y; - - if (cwin != NULL) { - xp = (int) (x * cwin->pw_xsize + 0.5); - yp = (int) (y * cwin->pw_ysize + 0.5); -#if HAVE_G2_H - if (beam != 0) - g2_line (cwin->g2_id, (double) cwin->phys_curx, (double) cwin->phys_cury, (double) xp, (double) yp); -#endif - cwin->phys_curx = xp; - cwin->phys_cury = yp; - } -} - -void -pntndc (SGP_ID cwin, double x, double y) -{ - _sgp2_stylus (cwin, x, y, 0); /* move to point */ - // if (crt.open == TRUE) - // cpix_set (crt.icurx, crt.icury, crt.color); -} - -void -markndc (SGP_ID cwin, double x, double y) -{ - _sgp2_stylus (cwin, x, y, 0); /* move to point */ - - if (crt.open == TRUE) - wrtsymbol (state.marktype, crt.icurx, crt.icury, &crt); - - if (prt.open == TRUE) - wrtsymbol (state.marktype, prt.icurx, prt.icury, &prt); -} - -GRFSTATE * -inqstate (void) -{ - return (&state); -} - -void -gp_set_aspect (int dev, double asp) -{ - if (asp > 0.0) { - if (dev & CRTDEV) - crt.asp = asp; - if (dev & PRTDEV) - prt.asp = asp; - } -} - -void -setlinestyle (int style) -{ - if (style == state.linestyle) - return; - - state.linestyle = style; - - crt.style = style; - prt.style = style; - - // crt_line_style (crt.style); -} - -void -setlinewidth (int wid) -{ - state.linewidth = wid; -} - -DEVICE * -inqdev (int dev) -{ - if (dev & CRTDEV) - return (&crt); - else if (dev & PRTDEV) - return (&prt); - else - return (NULL); -} - -/*===========================================================*/ -/* set text size */ -/*===========================================================*/ -void -_sgp2_set_text ( SGP_ID cwin, - double width, - double height, /* size of character in NDC */ - double textangle, /* text angle */ - int font /* text font */ - ) -{ - double temp; - -#if HAVE_G2_H - g2_set_font_size(cwin->g2_id, (height * cwin->pw_ysize)); -#endif - height = clamp (height, 0.0, 1.0); - width = clamp (width, 0.0, 1.0); - /* textangle = textangle - (2 * PI * (int) (textangle / (2 * PI))); - */ - cspec.width = width; - cspec.height = height; - cspec.textangle = textangle; - cspec.font = font; - - if (textangle > - HALFPI / 2 && textangle < HALFPI / 2) { - cspec.updir = YPLUS; - cspec.textdir = XPLUS; - } else if (textangle > HALFPI / 2 && textangle < 3 * HALFPI / 2) { - cspec.updir = XMINUS; - cspec.textdir = YPLUS; - } else if (textangle > 3 * HALFPI / 2 && textangle < 5 * HALFPI / 2) { - cspec.updir = YMINUS; - cspec.textdir = XMINUS; - } else if (textangle > 5 * HALFPI / 2 && textangle < 7 * HALFPI / 2) { - cspec.updir = XPLUS; - cspec.textdir = YMINUS; - } else { - cspec.updir = YPLUS; - cspec.textdir = XPLUS; - } - - if (cspec.updir == XMINUS || cspec.updir == XPLUS) { - temp = height; - height = width; - width = temp; - } - - crt.icwidth = (int) (width * crt.xsize + 0.5); - crt.icheight = (int) (height * crt.ysize + 0.5); - crt.icwidth = clamp (crt.icwidth, 8, crt.xsize); - crt.icheight = clamp (crt.icheight, 8, crt.ysize); - - prt.icwidth = (int) (width * prt.xsize + 0.5); - prt.icheight = (int) (height * prt.ysize + 0.5); - prt.icwidth = clamp (prt.icwidth, 8, prt.xsize); - prt.icheight = clamp (prt.icheight, 8, prt.ysize); -} - -void -settextclr (int fore, int back) -{ - cspec.fore = fore; - cspec.back = back; - crt.cfore = fore; - crt.cback = back; - prt.cfore = clamp (fore, 0, prt.colormax); - prt.cback = back; -} - -void -setcolor (int fore) -{ - int back; - - state.foregnd = fore; - back = state.backgnd; - crtcolor (crt.mode, &fore, &back); /* set colors on crt */ - crt.color = fore; - prt.color = clamp (fore, 0, prt.colormax); -} - -void -setbackg (int back) -{ - int fore; - - state.backgnd = back; - fore = state.foregnd; - crtcolor (crt.mode, &fore, &back); -} - -/* - * INITMARKER () - * - * Sets the current marker symbol (cross, square, diamond..) - */ -int -initmarker (int marker, int color) -{ - if (marker > NMARKERS || marker < 0) - return(-1); - else { - state.marktype = marker; - state.markcolor = color; - } - return(0); -} /* end initmarker */ - -/* - * SETCHARDIR ( ) - * - * indicates in which direction a string should be printed, e.g.: - * direction = YPLUS -> print on the horizontal from left to right - * direction = YMINUS -> print upside-down characters from right to left - * direction = XMINUS -> print on the vertical from down to up - * direction = XPLUS -> print on the vertical from up to down - */ -int -settextdir ( - int direction /* direction flag */ - ) -{ - - if (direction != XPLUS && - direction != XMINUS && - direction != YPLUS && - direction != YMINUS ) { - printf("Error in character direction: %d\n", direction); - return(-1); - } - cspec.textdir = direction; - charsize (cspec.width, cspec.height); - - return(0); -} /* end setchardir */ - - -void -_sgp2_dev_text (SGP_ID cwin, char *message) -{ -#if HAVE_G2_H - g2_string (cwin->g2_id, cwin->phys_curx, cwin->phys_cury, message); -#endif -} - -/*===========================================================*/ -/* terminate graphics to current device */ -/* close any files, and output any buffers */ -/*===========================================================*/ -void -termgrf2 (void) -{ - if (prt.open == TRUE) { - flushdevice (PRTDEV); - closedevice (PRTDEV); - termdevice (PRTDEV); - } - - if (crt.open == TRUE) { - closedevice (CRTDEV); - } -} - - -void -flushdevice (int dev) -{ - // if (dev & PRTDEV) - // prtline (PRTTERM, 0, 0, 0, 0, 0, 0); /* print contents of printer buffer */ -} diff --git a/libctgraphics/sgpdriver.cpp b/libctgraphics/sgpdriver.cpp new file mode 100644 index 0000000..76e08ef --- /dev/null +++ b/libctgraphics/sgpdriver.cpp @@ -0,0 +1,528 @@ +/***************************************************************************** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg +** +** $Id: sgpdriver.cpp,v 1.1 2000/06/19 19:20:11 kevin Exp $ +** +** This program is free software; you can redistribute it and/or modify +** it under the terms of the GNU General Public License (version 2) as +** published by the Free Software Foundation. +** +** This program is distributed in the hope that it will be useful, +** but WITHOUT ANY WARRANTY; without even the implied warranty of +** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +** GNU General Public License for more details. +** +** You should have received a copy of the GNU General Public License +** along with this program; if not, write to the Free Software +** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +******************************************************************************/ + +/* Device Driver for IBM PC Kevin Rosenberg March 84 */ + +#include +#include +#include +#include "ctsupport.h" +#include "sgp.h" + + +static int init_prt(void); +static void term_prt(void); + +/*===========================================================*/ +/* fundamental device drivers */ +/*===========================================================*/ + +#define XCHARSIZ (1.0 / 80.0) /* size of standard characters */ +#define YCHARSIZ (1.0 / 25.0) /* on screen in NDC */ + +#define CRTASPT (0.75) /* for IBM ECD */ + +/*-------------------*/ +/* print buffer data */ +/*-------------------*/ +#define PRTINIT 1 +#define PRTLIN 2 +#define PRTTERM 3 + +#define PRTSIZE 200 +#define PRTMODE 1 /* Epson 120 dot/in graphic mode */ +#define PRTASPT (120.0 / 72.0) /* dots/in vectical / horizontal */ + +static DEVICE crt, prt; +CHARSPEC cspec; +static GRFSTATE state; + + + +/* NAME + * gp_init Initialize graphics package + * + * SYNOPSIS + * gp_init() + */ + + +int +_sgp2_init_dev (SGP_ID cwin) +{ +#if 0 + initdevice (CRTDEV, GM_ENHANCED, 0, 0); + initdevice (PRTDEV, PRTMODE, (int) (PRTSIZE * PRTASPT), PRTSIZE); + opendevice (CRTDEV); + setlinestyle (LS_SOLID); + setcolor (1); + _sgp2_set_text (XCHARSIZ, YCHARSIZ, 0.0, 0); + setbackg (0); + settextclr (1, 0); + gp_set_aspect (CRTDEV, CRTASPT); + gp_set_aspect (PRTDEV, 1.0); +#endif + + state.xndc = 10.; /* to guarntee a move */ + _sgp2_stylus (cwin, 0.0,0.0,0); /* move to starting corner */ + + return (TRUE); +} + + +/* NAME + * gp_initdev Initializes graphic device + * + * SYNOPSIS + * initdevice (dev, mode, xsize, ysize) + * int dev Device handle + * int mode Mode for device (device specific) + * int xsize Size of x buffer for PRTDEV + * int ysize Size of y buffer for PRTDEV + */ + +int +initdevice (int dev, int mode, int xsize, int ysize) +{ + if (dev & CRTDEV) + { + // crt.dotfunc = crt_wdot; + // crt.linefunc = crt_line; + crt.xmin = 0; + crt.ymin = 0; + switch (crt.mode) + { +#if 0 + case 4: + case 5: + crt.xmax = 319; + crt.xsize = 320; + crt.ymax = 199; + crt.ysize = 200; + crt.colormax = 3; + break; + case GM_640x200: + crt.xmax = 639; + crt.xsize = 640; + crt.ymax = 199; + crt.ysize = 200; + crt.colormax = 1; + break; + case GM_ENHANCED: + case GM_MONOGRF: + crt.xmax = 639; + crt.xsize = 640; + crt.ymax = 349; + crt.ysize = 350; + crt.colormax = 15; + break; + case GM_640x480x16: + crt.xmax = 639; + crt.xsize = 640; + crt.ymax = 479; + crt.ysize = 480; + crt.colormax = 15; + break; + case GM_640x480x256: + crt.xmax = 639; + crt.xsize = 640; + crt.ymax = 479; + crt.ysize = 480; + crt.colormax = 255; + break; + case GM_1024x768x16: + crt.xmax = 1023; + crt.xsize = 1024; + crt.ymax = 767; + crt.ysize = 768; + crt.colormax = 15; + break; + case GM_1024x768x256: + crt.xmax = 1023; + crt.xsize = 1024; + crt.ymax = 767; + crt.ysize = 768; + crt.colormax = 255; + break; +#endif + default: + return (FALSE); + } + // crt_set_mode (crt.mode, TRUE); /* Initialize device */ + } + + if (dev & PRTDEV) { + if (prt.open == TRUE) + closedevice (PRTDEV); + prt.buf = NULL; + if (mode < 0) + prt.mode = PRTMODE; + if (mode > 6) + prt.mode = PRTMODE; + else + prt.mode = mode; + + if (xsize > 1 && ysize > 1) { + prt.xsize = xsize; + prt.ysize = ysize; + prt.xmin = 0; + prt.ymin = 0; + prt.xmax = prt.xsize - 1; + prt.ymax = prt.ysize - 1; + } + + prt.colormax = 1; + // prt.dotfunc = prtdot; + // prt.linefunc = prtline; + + init_prt (); /* Initialize the device */ + } + + return (TRUE); +} + + +/* NAME + * gp_opendev Open device for output + * + * SYNOPSIS + * gp_opendev (dev) + * int dev Device handle + * devices are number in powers of two + */ + +int +opendevice (int dev) +{ + if (dev & CRTDEV) + crt.open = TRUE; + + if (dev & PRTDEV) + prt.open = TRUE; + + return(TRUE); +} + + +/* NAME + * gp_closedev Close device for output + * + * SYNOPSIS + * gp_closedev (dev) + * int dev Device handle + * + * DESCRIPTION + * Temporarily suspends output from going to a device + */ + +void +closedevice (int dev) +{ + if (dev & CRTDEV) /* close crt */ + crt.open = FALSE; + + if (dev & PRTDEV) + prt.open = FALSE; +} + + +void +termdevice (int dev) +{ + if (dev & PRTDEV) + term_prt (); +} + +static int init_prt(void) +{ + return(0); +} + + +static void term_prt(void) +{ +} + +/*===========================================================*/ +/* stylus draws a line to the absolute point x,y in NDC's */ +/* t=0 for move, t=1 for draw */ +/*===========================================================*/ +void +_sgp2_stylus (SGP_ID cwin, double x, double y, int beam) +{ + int xp, yp; + + if ((state.xndc == x) && (state.yndc == y) && (beam == 0)) + return; /* no need to move */ + + state.xndc = x; /* save current beam location */ + state.yndc = y; + + if (cwin != NULL) { + xp = (int) (x * cwin->pw_xsize + 0.5); + yp = (int) (y * cwin->pw_ysize + 0.5); +#if HAVE_G2_H + if (beam != 0) + g2_line (cwin->g2_id, (double) cwin->phys_curx, (double) cwin->phys_cury, (double) xp, (double) yp); +#endif + cwin->phys_curx = xp; + cwin->phys_cury = yp; + } +} + +void +pntndc (SGP_ID cwin, double x, double y) +{ + _sgp2_stylus (cwin, x, y, 0); /* move to point */ + // if (crt.open == TRUE) + // cpix_set (crt.icurx, crt.icury, crt.color); +} + +void +markndc (SGP_ID cwin, double x, double y) +{ + _sgp2_stylus (cwin, x, y, 0); /* move to point */ + + if (crt.open == TRUE) + wrtsymbol (state.marktype, crt.icurx, crt.icury, &crt); + + if (prt.open == TRUE) + wrtsymbol (state.marktype, prt.icurx, prt.icury, &prt); +} + +GRFSTATE * +inqstate (void) +{ + return (&state); +} + +void +gp_set_aspect (int dev, double asp) +{ + if (asp > 0.0) { + if (dev & CRTDEV) + crt.asp = asp; + if (dev & PRTDEV) + prt.asp = asp; + } +} + +void +setlinestyle (int style) +{ + if (style == state.linestyle) + return; + + state.linestyle = style; + + crt.style = style; + prt.style = style; + + // crt_line_style (crt.style); +} + +void +setlinewidth (int wid) +{ + state.linewidth = wid; +} + +DEVICE * +inqdev (int dev) +{ + if (dev & CRTDEV) + return (&crt); + else if (dev & PRTDEV) + return (&prt); + else + return (NULL); +} + +/*===========================================================*/ +/* set text size */ +/*===========================================================*/ +void +_sgp2_set_text ( SGP_ID cwin, + double width, + double height, /* size of character in NDC */ + double textangle, /* text angle */ + int font /* text font */ + ) +{ + double temp; + +#if HAVE_G2_H + g2_set_font_size(cwin->g2_id, (height * cwin->pw_ysize)); +#endif + height = clamp (height, 0.0, 1.0); + width = clamp (width, 0.0, 1.0); + /* textangle = textangle - (2 * PI * (int) (textangle / (2 * PI))); + */ + cspec.width = width; + cspec.height = height; + cspec.textangle = textangle; + cspec.font = font; + + if (textangle > - HALFPI / 2 && textangle < HALFPI / 2) { + cspec.updir = YPLUS; + cspec.textdir = XPLUS; + } else if (textangle > HALFPI / 2 && textangle < 3 * HALFPI / 2) { + cspec.updir = XMINUS; + cspec.textdir = YPLUS; + } else if (textangle > 3 * HALFPI / 2 && textangle < 5 * HALFPI / 2) { + cspec.updir = YMINUS; + cspec.textdir = XMINUS; + } else if (textangle > 5 * HALFPI / 2 && textangle < 7 * HALFPI / 2) { + cspec.updir = XPLUS; + cspec.textdir = YMINUS; + } else { + cspec.updir = YPLUS; + cspec.textdir = XPLUS; + } + + if (cspec.updir == XMINUS || cspec.updir == XPLUS) { + temp = height; + height = width; + width = temp; + } + + crt.icwidth = (int) (width * crt.xsize + 0.5); + crt.icheight = (int) (height * crt.ysize + 0.5); + crt.icwidth = clamp (crt.icwidth, 8, crt.xsize); + crt.icheight = clamp (crt.icheight, 8, crt.ysize); + + prt.icwidth = (int) (width * prt.xsize + 0.5); + prt.icheight = (int) (height * prt.ysize + 0.5); + prt.icwidth = clamp (prt.icwidth, 8, prt.xsize); + prt.icheight = clamp (prt.icheight, 8, prt.ysize); +} + +void +settextclr (int fore, int back) +{ + cspec.fore = fore; + cspec.back = back; + crt.cfore = fore; + crt.cback = back; + prt.cfore = clamp (fore, 0, prt.colormax); + prt.cback = back; +} + +void +setcolor (int fore) +{ + int back; + + state.foregnd = fore; + back = state.backgnd; + crtcolor (crt.mode, &fore, &back); /* set colors on crt */ + crt.color = fore; + prt.color = clamp (fore, 0, prt.colormax); +} + +void +setbackg (int back) +{ + int fore; + + state.backgnd = back; + fore = state.foregnd; + crtcolor (crt.mode, &fore, &back); +} + +/* + * INITMARKER () + * + * Sets the current marker symbol (cross, square, diamond..) + */ +int +initmarker (int marker, int color) +{ + if (marker > NMARKERS || marker < 0) + return(-1); + else { + state.marktype = marker; + state.markcolor = color; + } + return(0); +} /* end initmarker */ + +/* + * SETCHARDIR ( ) + * + * indicates in which direction a string should be printed, e.g.: + * direction = YPLUS -> print on the horizontal from left to right + * direction = YMINUS -> print upside-down characters from right to left + * direction = XMINUS -> print on the vertical from down to up + * direction = XPLUS -> print on the vertical from up to down + */ +int +settextdir ( + int direction /* direction flag */ + ) +{ + + if (direction != XPLUS && + direction != XMINUS && + direction != YPLUS && + direction != YMINUS ) { + printf("Error in character direction: %d\n", direction); + return(-1); + } + cspec.textdir = direction; + charsize (cspec.width, cspec.height); + + return(0); +} /* end setchardir */ + + +void +_sgp2_dev_text (SGP_ID cwin, char *message) +{ +#if HAVE_G2_H + g2_string (cwin->g2_id, cwin->phys_curx, cwin->phys_cury, message); +#endif +} + +/*===========================================================*/ +/* terminate graphics to current device */ +/* close any files, and output any buffers */ +/*===========================================================*/ +void +termgrf2 (void) +{ + if (prt.open == TRUE) { + flushdevice (PRTDEV); + closedevice (PRTDEV); + termdevice (PRTDEV); + } + + if (crt.open == TRUE) { + closedevice (CRTDEV); + } +} + + +void +flushdevice (int dev) +{ + // if (dev & PRTDEV) + // prtline (PRTTERM, 0, 0, 0, 0, 0, 0); /* print contents of printer buffer */ +}