1 /*****************************************************************************
5 ** Purpose: Header file for Simple Graphics Package
6 ** Author: Kevin Rosenberg
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2009 Kevin Rosenberg
12 ** This program is free software; you can redistribute it and/or modify
13 ** it under the terms of the GNU General Public License (version 2) as
14 ** published by the Free Software Foundation.
16 ** This program is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ** GNU General Public License for more details.
21 ** You should have received a copy of the GNU General Public License
22 ** along with this program; if not, write to the Free Software
23 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 ******************************************************************************/
33 #include "transformmatrix.h"
53 std::string m_sWindowTitle;
63 SGPDRIVER_WXWINDOWS = 1,
69 SGPDriver (wxDC* pDC, int xsize = 640, int ysize = 480);
72 SGPDriver (const char* szWinTitle = "", int xsize = 640, int ysize = 480);
76 int getPhysicalXSize () const
77 { return m_iPhysicalXSize; }
79 int getPhysicalYSize () const
80 { return m_iPhysicalYSize; }
82 const std::string& getWindowTitle () const
83 { return m_sWindowTitle; }
86 { return (m_idDriver & SGPDRIVER_WXWINDOWS ? true : false); }
89 { return (m_idDriver & SGPDRIVER_G2 ? true : false); }
107 int m_iPhysicalXSize; // Physical Window size
108 int m_iPhysicalYSize;
111 double xw_min; // Window extents
115 double xv_min; // Viewport extents
119 double viewNDC[4]; // Viewport array for clip_rect()
121 int m_iCurrentPhysicalX;
122 int m_iCurrentPhysicalY;
123 double m_dCurrentWorldX;
124 double m_dCurrentWorldY;
126 int m_iTextPointSize;
127 bool m_bRecalcTransform;
128 double m_dPointsPerPixel; // points (72pt/in) per screen pixel;
132 // Master coordinates are coordinates before CTM transformation
133 // World coordinates are coordinates defined by setWindow()
134 // Normalized device coordinates range from 0. to 1. in both axes
135 TransformationMatrix2D wc_to_ndc; // World coord to NDC matrix
136 TransformationMatrix2D mc_to_ndc; // Master to NDC
137 TransformationMatrix2D ndc_to_mc; // NDC to Master
138 TransformationMatrix2D m_ctm; // Current transfromation matrix
140 void calc_transform ();
142 static SGP_RGBColor s_aRGBColor[];
143 static int s_iRGBColorCount;
149 void initFromDC (wxDC* pDC);
163 enum { // Codes for marker symbols
164 MARKER_POINT = 0, // small dot
165 MARKER_SQUARE = 1, // empty square
166 MARKER_FSQUARE = 2, // filled square
167 MARKER_DIAMOND = 3, // empty diamond
168 MARKER_FDIAMOND = 4, // filled diamond
169 MARKER_CROSS = 5, // cross
170 MARKER_XCROSS = 6, // x
171 MARKER_CIRCLE = 7, // open circle
172 MARKER_FCIRCLE = 8, // filled circle
173 MARKER_BSQUARE = 9, // big open square
174 MARKER_BDIAMOND = 10, // big open diamond
176 enum { MARK_COUNT = 11, };
177 static const unsigned char MARKER_BITMAP[MARK_COUNT][5];
179 SGP (const SGPDriver& driver);
182 void drawCircle (const double r);
183 void drawArc (const double r, double start, double stop);
184 void drawRect (double xmin, double ymin, double xmax, double ymax);
185 void lineAbs(double x, double y);
186 void moveAbs(double x, double y);
187 void lineRel(double x, double y);
188 void moveRel(double x, double y);
189 void drawText(const char *szMessage);
190 void drawText(const std::string& rsMessage);
191 void polylineAbs(double x[], double y[], int n);
192 void markerAbs (double x, double y);
193 void markerRel(double x, double y);
194 void pointAbs(double x, double y);
195 void pointRel(double x, double y);
198 void setWindow (double xmin, double ymin, double xmax, double ymax);
199 void setViewport (double xmin, double ymin, double xmax, double ymax);
200 void frameViewport();
202 void setColor (int icol);
203 void setLineStyle (int style);
204 void setTextSize (double height);
205 void setTextNDCSize (double height);
206 void setTextPointSize (double height);
207 void setTextAngle (double angle);
208 void setTextColor (int iFGcolor, int iBGcolor);
209 void setPenWidth (int width);
210 void setMarker (int idMarker);
211 void setRasterOp (int ro);
213 void getWindow (double& xmin, double& ymin, double& xmax, double& ymax);
214 void getViewport (double& xmin, double& ymin, double& xmax, double& ymax);
215 void getTextExtent (const char *szText, double* x, double* y);
216 double getCharHeight ();
217 double getCharWidth ();
218 SGPDriver& getDriver() {return m_driver;}
219 const SGPDriver& getDriver() const {return m_driver;}
222 void ctmSet (const TransformationMatrix2D& m);
223 void preTranslate (double x, double y);
224 void postTranslate (double x, double y);
225 void preScale (double sx, double sy);
226 void postScale (double sx, double sy);
227 void preRotate (double theta);
228 void postRotate (double theta);
229 void preShear (double shrx, double shry);
230 void postShear (double shrx, double shry);
231 void transformNDCtoMC (double* x, double* y);
232 void transformMCtoNDC (double* x, double* y);
233 void transformMCtoNDC (double xIn, double yIn, double* xOut, double* yOut);
235 void stylusNDC (double x, double y, bool beam);
236 void pointNDC (double x, double y);
237 void markerNDC (double x, double y);
240 void setDC (wxDC* pDC);
246 C_BLACK = 0, // color codes
291 SGP_RGBColor (int r, int g, int b)
298 int getGreen () const