-typedef struct raster_st RASTER;
-
-/*-------------------------------------------------------------------------*/
-
-
-/* circle.c */
-void circle(const double r);
-void drawarc(double start, double stop, const double r);
-/* 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);
-/* 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 SGP {
+private:
+ int m_iPhysicalXSize; // Physical Window size
+ int m_iPhysicalYSize;
+ const 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 ();
+
+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 (double start, double stop, const double r);
+ 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 setMarker (int idMarker, int color);
+
+ 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);
+};