Debian Codegraph @

include/sgp.h

raw
1 /*****************************************************************************
2 ** FILE IDENTIFICATION
3 **
4 ** Name: sgp.h
5 ** Purpose: Header file for Simple Graphics Package
6 ** Author: Kevin Rosenberg
7 ** Date Started: 1984
8 **
9 ** This is part of the CTSim program
10 ** Copyright (c) 1983-2009 Kevin Rosenberg
11 **
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.
15 **
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.
20 **
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 ******************************************************************************/
25
26 #ifndef __H_SGP
27 #define __H_SGP
28
29 #if HAVE_CONFIG_H
30 #include "config.h"
31 #endif
32
33 #include "transformmatrix.h"
34
35 #ifdef HAVE_WXWINDOWS
36 #include <wx/wx.h>
37 #include <wx/font.h>
38 #endif
39
40 #if HAVE_G2_H
41 extern "C" {
42 #include "g2.h"
43 #include "g2_X11.h"
44 }
45 #endif
46
47 #include <string>
48
49 class SGPDriver {
50 private:
51 int m_iPhysicalXSize;
52 int m_iPhysicalYSize;
53 std::string m_sWindowTitle;
54 int m_idDriver;
55
56 #ifdef HAVE_WXWINDOWS
57 wxDC* m_pDC;
58 #endif
59 int m_idG2;
60
61 public:
62 enum {
63 SGPDRIVER_WXWINDOWS = 1,
64 SGPDRIVER_G2 = 2,
65 SGPDRIVER_OPENGL = 4,
66 };
67
68 #ifdef HAVE_WXWINDOWS
69 SGPDriver (wxDC* pDC, int xsize = 640, int ysize = 480);
70 #endif
71
72 SGPDriver (const char* szWinTitle = "", int xsize = 640, int ysize = 480);
73
74 ~SGPDriver ();
75
76 int getPhysicalXSize () const
77 { return m_iPhysicalXSize; }
78
79 int getPhysicalYSize () const
80 { return m_iPhysicalYSize; }
81
82 const std::string& getWindowTitle () const
83 { return m_sWindowTitle; }
84
85 bool isWX () const
86 { return (m_idDriver & SGPDRIVER_WXWINDOWS ? true : false); }
87
88 bool isG2 () const
89 { return (m_idDriver & SGPDRIVER_G2 ? true : false); }
90
91 int idG2 () const
92 { return m_idG2; }
93
94 #ifdef HAVE_WXWINDOWS
95 wxDC* idWX () const
96 { return m_pDC; }
97
98 void setDC (wxDC* dc)
99 { m_pDC = dc; }
100 #endif
101 };
102
103
104 class SGP_RGBColor;
105 class SGP {
106 private:
107 int m_iPhysicalXSize; // Physical Window size
108 int m_iPhysicalYSize;
109 SGPDriver m_driver;
110
111 double xw_min; // Window extents
112 double yw_min;
113 double xw_max;
114 double yw_max;
115 double xv_min; // Viewport extents
116 double yv_min;
117 double xv_max;
118 double yv_max;
119 double viewNDC[4]; // Viewport array for clip_rect()
120
121 int m_iCurrentPhysicalX;
122 int m_iCurrentPhysicalY;
123 double m_dCurrentWorldX;
124 double m_dCurrentWorldY;
125 double m_dTextAngle;
126 int m_iTextPointSize;
127 bool m_bRecalcTransform;
128 double m_dPointsPerPixel; // points (72pt/in) per screen pixel;
129 int m_iLinestyle;
130 int m_iMarker;
131
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
139
140 void calc_transform ();
141
142 static SGP_RGBColor s_aRGBColor[];
143 static int s_iRGBColorCount;
144
145 #if HAVE_WXWINDOWS
146 wxPen m_pen;
147 wxFont* m_pFont;
148
149 void initFromDC (wxDC* pDC);
150 #endif
151
152 public:
153 enum { // linestyles
154 LS_NOLINE = 0,
155 LS_SOLID = 0xffff,
156 LS_DASH1 = 0xff00,
157 LS_DASH2 = 0xf0f0,
158 LS_DASH3 = 0xcccc,
159 LS_DASH4 = 0xff3e,
160 LS_DOTTED = 0xaaaa,
161 };
162
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
175 };
176 enum { MARK_COUNT = 11, };
177 static const unsigned char MARKER_BITMAP[MARK_COUNT][5];
178
179 SGP (const SGPDriver& driver);
180 ~SGP();
181
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);
196
197 void eraseWindow ();
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();
201
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);
212
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;}
220
221 void ctmClear ();
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);
234
235 void stylusNDC (double x, double y, bool beam);
236 void pointNDC (double x, double y);
237 void markerNDC (double x, double y);
238
239 #if HAVE_WXWINDOWS
240 void setDC (wxDC* pDC);
241 #endif
242 };
243
244
245 enum {
246 C_BLACK = 0, // color codes
247 C_BLUE = 1,
248 C_GREEN = 2,
249 C_CYAN = 3,
250 C_RED = 4,
251 C_MAGENTA = 5,
252 C_BROWN = 6,
253 C_GRAY = 7,
254 C_LTGRAY = 8,
255 C_LTBLUE = 9,
256 C_LTGREEN = 10,
257 C_LTCYAN = 11,
258 C_LTRED = 12,
259 C_LTMAGENTA = 13,
260 C_YELLOW = 14,
261 C_WHITE = 15,
262 };
263
264 enum RasterOp {
265 RO_AND = 1,
266 RO_AND_INVERT,
267 RO_AND_REVERSE,
268 RO_CLEAR,
269 RO_COPY,
270 RO_EQUIV,
271 RO_INVERT,
272 RO_NAND,
273 RO_NOR,
274 RO_NO_OP,
275 RO_OR,
276 RO_OR_INVERT,
277 RO_OR_REVERSE,
278 RO_SET,
279 RO_SRC_INVERT,
280 RO_XOR,
281 };
282
283
284 class SGP_RGBColor {
285 private:
286 short int r;
287 short int g;
288 short int b;
289
290 public:
291 SGP_RGBColor (int r, int g, int b)
292 : r(r), g(g), b(b)
293 {}
294
295 int getRed () const
296 { return r; }
297
298 int getGreen () const
299 { return g; }
300
301 int getBlue () const
302 { return b; }
303
304 };
305
306 #endif