r187: *** empty log message ***
[ctsim.git] / include / sgp.h
index d913ede25d3f2ed589f39fdd3021104585d80e46..a873d18d16e5c5529c3c5a51369903e730ea36d6 100644 (file)
@@ -1,24 +1,15 @@
 /*****************************************************************************
-**  This is part of the CTSim program
-**  Copyright (C) 1983-2000 Kevin Rosenberg
-**
-**  $Id: sgp.h,v 1.6 2000/05/11 14:07:00 kevin Exp $
-**  $Log: sgp.h,v $
-**  Revision 1.6  2000/05/11 14:07:00  kevin
-**  Added support for Windows NT
+** FILE IDENTIFICATION
 **
-**  Revision 1.5  2000/05/07 12:46:19  kevin
-**  made c++ compatible
+**      Name:         sgp.h
+**      Purpose:      Header file for Simple Graphics Package
+**      Author:       Kevin Rosenberg
+**      Date Started: 1984
 **
-**  Revision 1.4  2000/04/30 19:17:35  kevin
-**  Set up include files for conditional INTERACTIVE_GRAPHICS
-**
-**  Revision 1.3  2000/04/28 18:35:21  kevin
-**  removed unused files
-**
-**  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
 **  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"
-#include "kmath.h"
+#if HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include "transformmatrix.h"
+
+#ifdef HAVE_WXWINDOWS
+#include <wx/wx.h>
+#endif
 
-#ifdef __cplusplus
+#if HAVE_G2_H
 extern "C" {
-#endif /* __cplusplus */
-
-
-/* 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 */
+#include "g2.h"
+#include "g2_X11.h"
+}
+#endif
+
+#include <string>
+
+
+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;
-
-/*-------------------------------------------------------------------------*/
-
-
-/* circle.c */
-void circle(const double r);
-void drawarc(double start, double stop, const double r);
-/* ctm.c */
-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.c */
-void drawbox(double xmin, double ymin, double xmax, double ymax);
-/* sgp.c */
-void gp_init_2(void);
-void window2(double xmin, double ymin, double xmax, double ymax);
-void window_2(double xmin, double ymin, double xmax, double ymax);
-void viewprt2(double xmin, double ymin, double xmax, double ymax);
-void viewport_2(double xmin, double ymin, double xmax, double ymax);
-void framevpt(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 color(int icol);
-void linestyle(int style);
-void line_abs_2(double x, double y);
-void lineabs2(double x, double y);
-void move_abs_2(double x, double y);
-void moveabs2(double x, double y);
-void line_rel_2(double x, double y);
-void linerel2(double x, double y);
-void move_rel_2(double x, double y);
-void moverel2(double x, double y);
-void draw_text(char *message);
-void drawtext(char *message);
-void polylnabs2(double x[], double y[], int n);
-void markabs2(double x, double y);
-void markrel2(double x, double y);
-void pntabs2(double x, double y);
-void pntrel2(double x, double y);
-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.c */
-int initgrf2(void);
-int initdevice(int dev, int mode, int xsize, int ysize);
-int opendevice(int dev);
-void closedevice(int dev);
-void termdevice(int dev);
-void stylus(double x, double y, int beam);
-void pntndc(double x, double y);
-void markndc(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 settext(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 charsize(double wid, double height);
-void textangle(double angle);
-void drivtext(char *message);
-void termgrf2(void);
-void 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);
-
-#ifdef __cplusplus
-}
-#endif /* __cplusplus */
 
+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