X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Fsgp.h;h=a873d18d16e5c5529c3c5a51369903e730ea36d6;hp=6db81b0029057a402c488e497c24bc19f9f606d4;hb=bfcc769cf8019eabc8c65c07257c8dbee4b4c977;hpb=250602fe7220a1a004c91dd3cfc9cd44ed22e550 diff --git a/include/sgp.h b/include/sgp.h index 6db81b0..a873d18 100644 --- a/include/sgp.h +++ b/include/sgp.h @@ -1,15 +1,15 @@ /***************************************************************************** -** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg +** FILE IDENTIFICATION ** -** $Id: sgp.h,v 1.3 2000/04/28 18:35:21 kevin Exp $ -** $Log: sgp.h,v $ -** Revision 1.3 2000/04/28 18:35:21 kevin -** removed unused files +** Name: sgp.h +** Purpose: Header file for Simple Graphics Package +** Author: Kevin Rosenberg +** Date Started: 1984 ** -** Revision 1.2 2000/04/28 14:14:16 kevin -** *** empty log message *** +** This is part of the CTSim program +** Copyright (C) 1983-2000 Kevin Rosenberg ** +** $Id: sgp.h,v 1.17 2000/09/02 05:10:39 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 @@ -24,284 +24,272 @@ ** along with this program; if not, write to the Free Software ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -/*----------------------------------------------------------------------*/ -/* Standard Graphics Package Header File */ -/*----------------------------------------------------------------------*/ #ifndef __H_SGP #define __H_SGP -#include "kstddef.h" - -/* device names */ - -#define CRTDEV 1 -#define PRTDEV 2 -#define MEMDEV 4 -#define FILEDEV 8 - -/* linestyles */ - -#define LS_NOLINE 0 -#define LS_SOLID 0xffff -#define LS_DASH1 0xff00 -#define LS_DASH2 0xf0f0 -#define LS_DASH3 0xcccc -#define LS_DASH4 0xff3e -#define LS_DOTTED 0xaaaa - -#define MAXDASH 4 -#define MAXCOLOR 63 - -/* data structures */ - -struct device_st { - int open; /* TRUE if device is open for output */ - int xsize, ysize; /* Size of device in pixels */ - int xmin, ymin; /* smallest coordinates */ - int xmax, ymax; /* Maximum coordinates */ - int colormax; /* Maximum color number of device */ - int style; /* Current linestyle of device */ - int width; /* Current width of device */ - int color; /* Current color of device */ - int icurx, icury; /* Current position */ - int icwidth, icheight; /* Size of characters in pixels */ - int cfore, cback; /* Character foregnd & backgnd colors */ - float asp; /* Aspect ratio. Multipy x coord */ - int (*dotfunc)(int x1, int y1, int color); /* Dot function for device */ - int (*linefunc)(int x1, int y1, int x2, int y2, int color); /* Line function for device */ - unsigned int nbytes; /* Size of buffer in bytes */ - char *buf; /* Pointer to buffer */ - unsigned int bufseg, bufoff; /* Buffer memory location */ - int mode; /* Device mode */ +#if HAVE_CONFIG_H +#include "config.h" +#endif + +#include "transformmatrix.h" + +#ifdef HAVE_WXWINDOWS +#include +#endif + +#if HAVE_G2_H +extern "C" { +#include "g2.h" +#include "g2_X11.h" +} +#endif + +#include + + +class SGPDriver { +private: + int m_iPhysicalXSize; + int m_iPhysicalYSize; + string m_sWindowTitle; + int m_idDriver; + +#ifdef HAVE_WXWINDOWS + wxDC* m_pDC; +#endif + int m_idG2; + +public: + enum { + SGPDRIVER_WXWINDOWS = 1, + SGPDRIVER_G2 = 2, + SGPDRIVER_OPENGL = 4, + }; + +#ifdef HAVE_WXWINDOWS + SGPDriver (wxDC* pDC, int xsize = 640, int ysize = 480); +#endif + + SGPDriver (const char* szWinTitle = "", int xsize = 640, int ysize = 480); + + ~SGPDriver (); + + int getPhysicalXSize () const + { return m_iPhysicalXSize; } + + int getPhysicalYSize () const + { return m_iPhysicalYSize; } + + const string& getWindowTitle () const + { return m_sWindowTitle; } + + bool isWX () const + { return (m_idDriver & SGPDRIVER_WXWINDOWS); } + + bool isG2 () const + { return (m_idDriver & SGPDRIVER_G2); } + + int idG2 () const + { return m_idG2; } + +#ifdef HAVE_WXWINDOWS + wxDC* idWX () const + { return m_pDC; } + + void setDC (wxDC* dc) + { m_pDC = dc; } +#endif }; -struct charsp_st { - float width, height; /* size of characters in NDC */ - float textangle; /* text angle in radians */ - float charupangle; /* character up angle */ - int font; /* font for characters */ - int updir, textdir; /* text direct & character orientation */ - int fore, back; /* foreground & background color */ - /* if back = -1, then transparent back */ + +class RGBColor; +class SGP { +private: + int m_iPhysicalXSize; // Physical Window size + int m_iPhysicalYSize; + SGPDriver m_driver; + + double xw_min; // Window extents + double yw_min; + double xw_max; + double yw_max; + double xv_min; // Viewport extents + double yv_min; + double xv_max; + double yv_max; + double viewNDC[4]; // Viewport array for clip_rect() + + int m_iCurrentPhysicalX; + int m_iCurrentPhysicalY; + double m_dCurrentWorldX; + double m_dCurrentWorldY; + double m_dTextAngle; + bool m_bRecalcTransform; + + // Master coordinates are coordinates before CTM transformation + // World coordinates are coordinates defined by setWindow() + // Normalized device coordinates range from 0. to 1. in both axes + TransformationMatrix2D wc_to_ndc; // World coord to NDC matrix + TransformationMatrix2D mc_to_ndc; // Master to NDC + TransformationMatrix2D ndc_to_mc; // NDC to Master + TransformationMatrix2D m_ctm; // Current transfromation matrix + + void calc_transform (); + + static RGBColor s_aRGBColor[]; + static int s_iRGBColorCount; + +#if HAVE_WXWINDOWS + wxPen m_pen; +#endif + +public: + enum { // linestyles + LS_NOLINE = 0, + LS_SOLID = 0xffff, + LS_DASH1 = 0xff00, + LS_DASH2 = 0xf0f0, + LS_DASH3 = 0xcccc, + LS_DASH4 = 0xff3e, + LS_DOTTED = 0xaaaa, + }; + + enum { // Codes for marker symbols + MARK_POINT = 0, // small dot + MARK_SQUARE = 1, // empty square + MARK_FSQUARE = 2, // filled square + MARK_DIAMOND = 3, // empty diamond + MARK_FDIAMOND = 4, // filled diamond + MARK_CROSS = 5, // cross + MARK_XCROSS = 6, // x + MARK_CIRCLE = 7, // open circle + MARK_FCIRCLE = 8, // filled circle + MARK_BSQUARE = 9, // big open square + MARK_BDIAMOND = 10, // big open diamond + }; + static const int MARK_COUNT = 11; + static const unsigned char MARKER_BITMAP[MARK_COUNT][5]; + + SGP (const SGPDriver& driver); + + void drawCircle (const double r); + void drawArc (const double r, double start, double stop); + void drawRect (double xmin, double ymin, double xmax, double ymax); + void lineAbs(double x, double y); + void moveAbs(double x, double y); + void lineRel(double x, double y); + void moveRel(double x, double y); + void drawText(const char *szMessage); + void drawText(const string& rsMessage); + void polylineAbs(double x[], double y[], int n); + void markerAbs (double x, double y); + void markerRel(double x, double y); + void pointAbs(double x, double y); + void pointRel(double x, double y); + + void eraseWindow (); + void setWindow (double xmin, double ymin, double xmax, double ymax); + void setViewport (double xmin, double ymin, double xmax, double ymax); + void frameViewport(); + + void setColor (int icol); + void setLineStyle (int style); + void setTextSize (double height); + void setTextAngle (double angle); + void setTextColor (int iFGcolor, int iBGcolor); + void setPenWidth (int width); + void setMarker (int idMarker, int color); + void setRasterOp (int ro); + + void getWindow (double& xmin, double& ymin, double& xmax, double& ymax); + void getViewport (double& xmin, double& ymin, double& xmax, double& ymax); + void getTextExtent (const char *szText, double* x, double* y); + double getCharHeight (); + + void ctmClear (); + void ctmSet (const TransformationMatrix2D& m); + void preTranslate (double x, double y); + void postTranslate (double x, double y); + void preScale (double sx, double sy); + void postScale (double sx, double sy); + void preRotate (double theta); + void postRotate (double theta); + void preShear (double shrx, double shry); + void postShear (double shrx, double shry); + void transformNDCtoMC (double* x, double* y); + void transformMCtoNDC (double* x, double* y); + void transformMCtoNDC (double xIn, double yIn, double* xOut, double* yOut); + + void stylusNDC (double x, double y, bool beam); + void pointNDC (double x, double y); + void markerNDC (double x, double y); + +#if HAVE_WXWINDOWS + void setDC (wxDC* pDC); +#endif }; -struct state_st { - int foregnd, backgnd; /* current foregound & background colors */ - int linestyle; /* current 16 bit linestyle */ - int linewidth; /* current width of line (in pixels) */ - int marktype; /* current marker type */ - int markcolor; /* current marker color */ - float xndc, yndc; /* current position in NDC */ + +enum { + C_BLACK = 0, // color codes + C_BLUE = 1, + C_GREEN = 2, + C_CYAN = 3, + C_RED = 4, + C_MAGENTA = 5, + C_BROWN = 6, + C_GRAY = 7, + C_LTGRAY = 8, + C_LTBLUE = 9, + C_LTGREEN = 10, + C_LTCYAN = 11, + C_LTRED = 12, + C_LTMAGENTA = 13, + C_YELLOW = 14, + C_WHITE = 15, }; -typedef struct device_st DEVICE; -typedef struct charsp_st CHARSPEC; -typedef struct state_st GRFSTATE; - -struct point {double x, y, z;}; - - -/****************************************************************** - * * - * GRAPH.H * - * * - * Max R. Dursteler Dec 1983 * - * 12405 Village Square Terrace * - * Rockville Md. 20852 * - ****************************************************************** - */ - -/* Constants */ - -/* Flagcodes for motion directions */ -#define XPLUS 001 /* right */ -#define XMINUS 002 /* left */ -#define YPLUS 004 /* up */ -#define YMINUS 010 /* down */ - -/* Codes for marker symbols */ -#define POINT 0 /* small dot */ -#define SQUARE 1 /* empty square */ -#define FSQUARE 2 /* filled square */ -#define DIAMOND 3 /* empty diamond */ -#define FDIAMOND 4 /* filled diamond */ -#define CROSS 5 /* cross */ -#define XCROSS 6 /* x */ -#define CERCLE 7 /* open circle */ -#define FCERCLE 8 /* filled circle */ -#define BSQUARE 9 /* big open square */ -#define BDIAMOND 10 /* big open diamond */ - -#define NMARKERS 11 /* Number of available symbol types */ - -/*-------------------------------------------------------------------------*/ - -#define PSET 0 /* codes for raster merging */ -#define PRESET 1 -#define OR 2 -#define AND 3 -#define XOR 4 - -/*-------------------------------------------------------------------------*/ - -#define X_STKMIN 10 /* joystick specific values */ -#define X_STKMAX 313 -#define Y_STKMIN 10 -#define Y_STKMAX 313 - -#define X_LOCMAX (X_STKMAX - X_STKMIN); /* range from readloc() */ -#define Y_LOCMAX (Y_STKMAX - Y_STKMIN); /* = 0 to LOCMAX */ - -#define JOYSTK1 0 /* device names */ -#define JOYSTK2 1 - -#define BUTT_DONE 2 /* Right joystick button to end a command */ -#define BUTT_START 1 /* Left joystick button to start a command */ -#define BUTT_BOTH 3 /* Both buttons pressed */ - -#define RL_ERROR -1 /* readloc() return codes */ -#define RL_OFF 0 -#define RL_ON 1 - -/*-------------------------------------------------------------------------*/ - -struct raster_st { - int type; - int xmin, ymin; - int xmax, ymax; +enum RasterOp { + RO_AND = 1, + RO_AND_INVERT, + RO_AND_REVERSE, + RO_CLEAR, + RO_COPY, + RO_EQUIV, + RO_INVERT, + RO_NAND, + RO_NOR, + RO_NO_OP, + RO_OR, + RO_OR_INVERT, + RO_OR_REVERSE, + RO_SET, + RO_SRC_INVERT, + RO_XOR, }; -typedef struct raster_st RASTER; - -/*-------------------------------------------------------------------------*/ - -typedef double GRFMTX_2D[3][3]; -typedef double GRFMTX_3D[4][4]; - - -/* circle.c */ -void circle(const double r); -void drawarc(double start, double stop, const double r); -/* cliprect.c */ -int cliprect(double *x1, double *y1, double *x2, double *y2, const double rect[4]); -/* ctm.c */ -int ctm_xlat_pre_2(double x, double y); -int ctm_xlat_post_2(double x, double y); -int ctm_scale_pre_2(double sx, double sy); -int ctm_scale_post_2(double sx, double sy); -int ctm_rotate_pre_2(double theta); -int ctm_rotate_post_2(double theta); -int ctm_shear_pre_2(double shrx, double shry); -int ctm_shear_post_2(double shrx, double shry); -int xlat_gmtx_2(GRFMTX_2D m, double x, double y); -int scale_gmtx_2(GRFMTX_2D m, double sx, double sy); -int shear_gmtx_2(GRFMTX_2D m, double shrx, double shry); -int rotate_gmtx_2(GRFMTX_2D m, double theta); -int ident_gmtx_2(GRFMTX_2D m); -int mult_gmtx_2(GRFMTX_2D a, GRFMTX_2D b, GRFMTX_2D c); -int invert_gmtx_2(GRFMTX_2D a, GRFMTX_2D b); -double determ_gmtx_2(GRFMTX_2D a); -/* drawbox.c */ -int drawbox(double xmin, double ymin, double xmax, double ymax); -/* gp.c */ -int gptrace(int state); -int viewprt3(double xmin, double ymin, double zmin, double xmax, double ymax, double zmax); -int window3(double xmin, double ymin, double xmax, double ymax); -int setproj(int pr, double x, double y, double z); -int setvrp(double x, double y, double z); -int setvpn(double x, double y, double z); -int setvup(double x, double y, double z); -int viewdepth(double front, double back); -int gpfrontclip(int on_off); -int gpbackclip(int on_off); -int calcnper(void); -int calcnpar(void); -int calcrot(double rot[5][5]); -int calcpertrans(void); -int calcpartrans(void); -int matident(double mtx[5][5]); -int matmult(double premtx[5][5], double postmtx[5][5], double result[5][5]); -int crossprod(struct point *v, struct point *w, struct point *result); -int transform(double mtx[5][5], double *x, double *y, double *z); -int homotrans(double mtx[5][5], double *x, double *y, double *z, double *w); -int moveabs3(double x, double y, double z); -int moverel3(double xr, double yr, double zr); -int lineabs3(double x, double y, double z); -int linerel3(double xr, double yr, double zr); -int drawline(double xinput, double yinput, double zinput); -int mastertondc(double *x, double *y, double *z); -int checkchange(void); -int initgrf3(void); -int termgrf3(void); -int matwrite(double mtx[5][5]); -int pyr_edge(double x, double y, double z, int *pos); -int clippyramid(double *x1, double *y1, double *z1, double *x2, double *y2, double *z2, int *accept); -int cube_edge(double x, double y, double z, int *pos); -int clipcube(double *x1, double *y1, double *z1, double *x2, double *y2, double *z2, int *accept); -/* sgp.c */ -int gp_init_2(void); -int window2(double xmin, double ymin, double xmax, double ymax); -int window_2(double xmin, double ymin, double xmax, double ymax); -int viewprt2(double xmin, double ymin, double xmax, double ymax); -int viewport_2(double xmin, double ymin, double xmax, double ymax); -int framevpt(void); -int calc_wc_to_ndc(void); -int calc_ndc_to_mc(void); -int wc_to_ndc(double xw, double yw, double *xn, double *yn); -int ndc_to_wc(double xn, double yn, double *xw, double *yw); -int color(int icol); -int linestyle(int style); -int line_abs_2(double x, double y); -int lineabs2(double x, double y); -int move_abs_2(double x, double y); -int moveabs2(double x, double y); -int line_rel_2(double x, double y); -int linerel2(double x, double y); -int move_rel_2(double x, double y); -int moverel2(double x, double y); -int draw_text(char *message); -int drawtext(char *message); -int polylnabs2(double x[], double y[], int n); -int markabs2(double x, double y); -int markrel2(double x, double y); -int pntabs2(double x, double y); -int pntrel2(double x, double y); -int ctm_clr_2(void); -int ctm_get_2(GRFMTX_2D m); -int ctm_set_2(GRFMTX_2D m); -int ctm_pre_mult_2(GRFMTX_2D m); -int ctm_post_mult_2(GRFMTX_2D m); -/* sgpdrive.c */ -int initgrf2(void); -int initdevice(int dev, int mode, int xsize, int ysize); -int opendevice(int dev); -int closedevice(int dev); -int termdevice(int dev); -void stylus(double x, double y, int beam); -int pntndc(double x, double y); -int markndc(double x, double y); -GRFSTATE *inqstate(void); -int gp_set_aspect(int dev, double asp); -void setlinestyle(int style); -int setlinewidth(int wid); -DEVICE *inqdev(int dev); -int settext(double width, double height, double textangle, int font); -int settextclr(int fore, int back); -int setcolor(int fore); -int setbackg(int back); -int initmarker(int marker, int color); -int settextdir(int direction); -int charsize(double wid, double height); -int textangle(double angle); -int drivtext(char *message); -int termgrf2(void); -int flushdevice(int dev); -/* sgptext.c */ -void wrtsymbol(int sym, int x, int y, DEVICE *dev); -void wrtchar(int ch, int x, int y, CHARSPEC *cspec, DEVICE *dev); -void wrttext(char txtstr[], int x, int y, CHARSPEC *cspec, DEVICE *dev); -void crtcolor(int mode, int *f, int *b); +class RGBColor { + private: + short int r; + short int g; + short int b; + + public: + RGBColor (int r, int g, int b) + : r(r), g(g), b(b) + {} + + int getRed () const + { return r; } + + int getGreen () const + { return g; } + + int getBlue () const + { return b; } + +}; #endif