X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=include%2Fsgp.h;h=a873d18d16e5c5529c3c5a51369903e730ea36d6;hp=ee95681a6a2ede5f5835ddf4a270d24f5eb1a8ca;hb=bfcc769cf8019eabc8c65c07257c8dbee4b4c977;hpb=b5857e74e5735455b5ef11cbea5044ae7b2e8a0d diff --git a/include/sgp.h b/include/sgp.h index ee95681..a873d18 100644 --- a/include/sgp.h +++ b/include/sgp.h @@ -1,8 +1,15 @@ /***************************************************************************** +** FILE IDENTIFICATION +** +** Name: sgp.h +** Purpose: Header file for Simple Graphics Package +** Author: Kevin Rosenberg +** Date Started: 1984 +** ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: sgp.h,v 1.9 2000/06/15 19:07:10 kevin Exp $ +** $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 @@ -18,20 +25,19 @@ ** 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" -#include "kmath.h" - #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" @@ -39,225 +45,251 @@ extern "C" { } #endif -/* 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 sgp_window_st { - int pw_xsize; /* Physical Window size */ - int pw_ysize; - char title[256]; - int g2_id; - 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 view[4]; /* Viewport array for clip_rect() */ - double curx; /* Current stylus position in world coords */ - double cury; - int recalc_mc_to_ndc; - int recalc_ndc_to_mc; - GRFMTX_2D wc_to_ndc_x; /* World coord to NDC matrix */ - GRFMTX_2D mc_to_ndc_x; /* Master to NDC */ - GRFMTX_2D ndc_to_mc_x; /* NDC to Master */ - GRFMTX_2D ctm_2_x; /* Current transfromation matrix */ - - int phys_curx; - int phys_cury; +#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 }; -typedef struct sgp_window_st SGP_WINDOW; -typedef struct sgp_window_st *SGP_ID; - -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 */ + +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 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 */ + +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, }; -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 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 device_st DEVICE; -typedef struct charsp_st CHARSPEC; -typedef struct state_st GRFSTATE; - -struct point {double x, y, z;}; - - -/* 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 - -/*-------------------------------------------------------------------------*/ - -/* circle.cpp */ -void sgp2_draw_circle(const double r); -void sgp2_draw_arc(double start, double stop, const double r); - -/* ctm.cpp */ -void ctm_xlat_pre_2(double x, double y); -void ctm_xlat_post_2(double x, double y); -void ctm_scale_pre_2(double sx, double sy); -void ctm_scale_post_2(double sx, double sy); -void ctm_rotate_pre_2(double theta); -void ctm_rotate_post_2(double theta); -void ctm_shear_pre_2(double shrx, double shry); -void ctm_shear_post_2(double shrx, double shry); -void xlat_gmtx_2(GRFMTX_2D m, double x, double y); -void scale_gmtx_2(GRFMTX_2D m, double sx, double sy); -void shear_gmtx_2(GRFMTX_2D m, double shrx, double shry); -void rotate_gmtx_2(GRFMTX_2D m, double theta); -void ident_gmtx_2(GRFMTX_2D m); -void mult_gmtx_2(GRFMTX_2D a, GRFMTX_2D b, GRFMTX_2D c); -void invert_gmtx_2(GRFMTX_2D a, GRFMTX_2D b); -double determ_gmtx_2(GRFMTX_2D a); - -/* drawbox.cpp */ -void sgp2_draw_rect (double xmin, double ymin, double xmax, double ymax); - -/* sgp.cpp */ -SGP_ID sgp2_init (int xsize, int ysize, const char *title); -void sgp2_close (SGP_ID gid); -void sgp2_set_active_win (SGP_ID); -SGP_ID sgp2_get_active_win (void); -void sgp2_clear (void); -void sgp2_window(double xmin, double ymin, double xmax, double ymax); -void sgp2_viewport(double xmin, double ymin, double xmax, double ymax); -void sgp2_frame_vpt(void); -void calc_wc_to_ndc(void); -void calc_ndc_to_mc(void); -void wc_to_ndc(double xw, double yw, double *xn, double *yn); -void ndc_to_wc(double xn, double yn, double *xw, double *yw); -void sgp2_color(int icol); -void sgp2_line_style(int style); -void sgp2_line_abs(double x, double y); -void sgp2_move_abs(double x, double y); -void sgp2_line_rel(double x, double y); -void sgp2_move_rel(double x, double y); -void sgp2_draw_text(char *message); -void sgp2_polyline_abs(double x[], double y[], int n); -void sgp2_mark_abs(double x, double y); -void sgp2_mark_rel(double x, double y); -void sgp2_point_abs(double x, double y); -void sgp2_point_rel(double x, double y); -void charsize(double wid, double height); -void textangle(double angle); -void ctm_clr_2(void); -void ctm_get_2(GRFMTX_2D m); -void ctm_set_2(GRFMTX_2D m); -void ctm_pre_mult_2(GRFMTX_2D m); -void ctm_post_mult_2(GRFMTX_2D m); - -/* sgpdrive.cpp */ -int _sgp2_init_dev(SGP_ID gid); -int initdevice(int dev, int mode, int xsize, int ysize); -int opendevice(int dev); -void closedevice(int dev); -void termdevice(int dev); -void _sgp2_stylus(SGP_ID gid, double x, double y, int beam); -void pntndc (SGP_ID gid, double x, double y); -void markndc (SGP_ID gid, double x, double y); -GRFSTATE *inqstate(void); -void gp_set_aspect(int dev, double asp); -void setlinestyle(int style); -void setlinewidth(int wid); -DEVICE *inqdev(int dev); -void _sgp2_set_text(SGP_ID gid, double width, double height, double textangle, int font); -void settextclr(int fore, int back); -void setcolor(int fore); -void setbackg(int back); -int initmarker(int marker, int color); -int settextdir(int direction); -void _sgp2_dev_text(SGP_ID gid, char *message); -void termgrf2(void); -void flushdevice(int dev); - -/* sgptext.cpp */ -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