forked from Smorodov/Multitarget-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgport.h
More file actions
323 lines (252 loc) · 8.46 KB
/
gport.h
File metadata and controls
323 lines (252 loc) · 8.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
#ifndef GPORTH
#define GPORTH
#ifdef __BORLANDC__
// Undefine __MINMAX_DEFINED so that min and max are correctly defined
#ifdef __MINMAX_DEFINED
#undef __MINMAX_DEFINED
#endif
// Ignore "Cannot create precompiled header: code in header" message
// generated when compiling string.cc
#pragma warn -pch
#endif
#include <iostream>
#include <fstream>
#include <string>
#ifdef __BORLANDC__
#pragma warn .pch
#endif
#include "gdefs.h"
// System specific includes here
#if GPORT_WINDOWS
#endif
#if GPORT_MAC
// #include <Printing.h>
#endif
enum GPortDevice {devScreen, devPrinter, devPicture, devPostscript};
/* Note that we always draw using the following coordinate system:
(0,0)--------->(+x,0)
|
|
|
\/
(+y,0)
Hence the origin is the top left hand corner, and y goes down rather than up.
This is typical for drawing to a window. Some systems have other coordinate
systems (such as Postscript). We make the translation internally.
*/
// A point
class GPoint
{
public:
GPoint () { SetPoint (0, 0); };
GPoint (const GPoint &p) { X = p.X; Y = p.Y; };
GPoint (const int x, const int y) { SetPoint (x, y); };
virtual int GetX () const { return X; };
virtual int GetY () const { return Y; };
virtual void Offset (const int xoff, const int yoff) { X += xoff; Y += yoff; };
virtual void SetPoint (const int x, const int y) { X = x; Y = y; };
virtual void SetX (int x) { X = x; };
virtual void SetY (int y) { Y = y; };
int operator== (const GPoint &p) { return (int) ( (X == p.X) && ( Y == p.Y)); };
int operator!= (const GPoint &p) { return (int) ( (X != p.X) || ( Y != p.Y)); };
protected:
int X;
int Y;
};
// A rectangle
class GRect
{
public:
GRect () { left = top = right = bottom = 0; };
GRect (const int l, const int t, const int r, const int b) { SetRect (l, t, r, b); };
virtual int GetLeft () const { return left; };
virtual int GetTop () const { return top; };
virtual int GetRight () const { return right; };
virtual int GetBottom () const { return bottom; };
virtual int GetWidth () const { return right - left; };
virtual int GetHeight () const { return bottom - top; };
virtual void Inset (const int dx, const int dy) { left += dx; right -= dx; top += dy; bottom -= dy; };
virtual void Offset (const int dx, const int dy) { left += dx; right += dx; top += dy; bottom += dy; };
virtual bool PointInRect (GPoint &pt)
{
return (((pt.GetX() >= left) && (pt.GetX() <= right)) &&
((pt.GetY() >= top) && (pt.GetY() <= bottom)));
}
virtual void SetLeft (const int l) {left = l; };
virtual void SetTop (const int t) {top = t; };
virtual void SetRight (const int r) {right = r; };
virtual void SetBottom (const int b) {bottom = b; };
virtual void SetRect (const int l, const int t, const int r, const int b)
{ left = l; top = t; right = r; bottom = b; };
virtual void SetRectWH (const int l, const int t, const int w, const int h)
{ left = l; top = t; right = l + w; bottom = t + h; };
protected:
int left, top, right, bottom;
};
// Base class for system specific fonts
class GBaseFont
{
public:
GBaseFont ();
virtual ~GBaseFont () {};
virtual std::string GetName () { return description; };
virtual std::string GetDescription () { return description; };
virtual int GetSize () { return size; };
virtual bool IsBold () { return bold; };
virtual bool IsItalic () { return italic; };
private:
std::string description;
std::string name;
int size;
bool bold;
bool italic;
};
typedef GBaseFont *GBaseFontPtr;
typedef GBaseFont GFont ; // for now
typedef GFont *GFontPtr;
// Windows needs the two handles for screen and printer fonts
// Mac just sets things
// Postscript writes to the postscript stream
// Virtual class to encapsulate printing
class GBasePrinter
{
public:
GBasePrinter () {};
virtual ~GBasePrinter () {};
virtual void PrinterSetup () = 0;
virtual void AbortPrinting () = 0;
virtual void EndDoc ();
virtual bool EndPage ();
virtual void GetPrintingRect (GRect &r) = 0;
virtual void GetPhysicalPageRect (GRect &r) = 0;
virtual bool StartPage () = 0;
virtual bool StartDoc (char *jobname) = 0; // "GBasePrinter"
};
// Windows port VPort
// Mac port VPort
// Postscript - just write to file
// Encapsulates the complete graphics system (screen drawing, picture files,
// printing, clipboard).
class GBasePort
{
public:
GBasePort () { Device = devScreen; PenWidth = 1;};
virtual ~GBasePort() {};
virtual void DrawArc (const GPoint &pt, const int radius,
const double startAngleDegrees, const double endAngleDegrees) = 0;
virtual void DrawCircle (const GPoint &pt, const int radius) = 0;
virtual void DrawLine (const int x1, const int y1, const int x2, const int y2) = 0;
virtual void DrawLinePts (const GPoint &pt1, const GPoint &pt2)
{ DrawLine (pt1.GetX(), pt1.GetY(), pt2.GetX(), pt2.GetY()); };
virtual void DrawRect (const GRect &r) = 0;
virtual void DrawText (const int x, const int y, const char *s) = 0;
// Display
virtual GPortDevice GetCurrentDevice () { return Device; };
virtual void GetDisplayRect (GRect &r) { r = DisplayRect; };
virtual void SetDisplayRect (GRect &r) { DisplayRect = r; };
// Pen
virtual int GetPenWidth () { return PenWidth; };
virtual void SetPenWidth (int w) { PenWidth = w; };
// Fonts
virtual void SetCurrentFont (GBaseFont &font) = 0;
// Pictures
virtual void StartPicture (char *pictFileName) = 0;
virtual void EndPicture () = 0;
// Groups
virtual void BeginGroup () = 0;
virtual void EndGroup () = 0;
// Printing
virtual void GetPrintingRect (GRect &r) = 0;
// Colour
virtual void SetFillColorRGB (int /*r*/, int /*g*/, int /*b*/) {};
protected:
// list of fonts
// printer class
//pens
int PenWidth;
// Device info
GPortDevice Device;
GRect DisplayRect;
};
// Mac
// Win
// Postscript
class GPostscriptPort : public GBasePort
{
public:
GPostscriptPort ();
virtual ~GPostscriptPort () {};
virtual void DrawArc (const GPoint &pt, const int radius,
const double startAngleDegrees, const double endAngleDegrees);
virtual void DrawCircle (const GPoint &pt, const int radius);
virtual void DrawLine (const int x1, const int y1, const int x2, const int y2);
virtual void DrawRect (const GRect &r);
virtual void DrawText (const int x, const int y, const char *text);
virtual void FillCircle (const GPoint &pt, const int radius);
// Pen
virtual void SetPenWidth (int w);
// Fonts
virtual void SetCurrentFont (GBaseFont &font);
// Pictures
virtual void StartPicture (char *pictFileName);
virtual void EndPicture ();
// Groups
virtual void BeginGroup () {};
virtual void EndGroup () {};
// Printing
virtual void GetPrintingRect (GRect &r);
virtual void SetFillColorRGB (int r, int g, int b)
{
fill_r = (double)r/255.0;
fill_g = (double)g/255.0;
fill_b = (double)b/255.0;
};
protected:
std::ofstream PostscriptStream;
std::string DocumentFonts;
double fill_r, fill_g, fill_b;
};
class GMacPort : public GBasePort
{
public:
// Groups
virtual void BeginGroup ();
virtual void EndGroup ();
protected:
};
class SVGPort : public GBasePort
{
public:
SVGPort ();
virtual void DrawArc (const GPoint &/*pt*/, const int /*radius*/,
const double /*startAngleDegrees*/, const double /*endAngleDegrees*/) {};
virtual void DrawCircle (const GPoint &pt, const int radius);
virtual void DrawLine (const int x1, const int y1, const int x2, const int y2);
virtual void DrawRect (const GRect &r);
virtual void DrawText (const int x, const int y, const char *text);
// Pen
virtual void SetPenWidth (int /*w*/) {};
// Fonts
virtual void SetCurrentFont (GBaseFont &font);
// Pictures
virtual void StartPicture (char *pictFileName);
virtual void EndPicture ();
// Groups
virtual void BeginGroup () {};
virtual void EndGroup () {};
// Printing
virtual void GetPrintingRect (GRect &r);
protected:
std::ofstream svgStream;
std::string fontString;
};
#ifndef USE_VC2
extern GBasePort *Port; // for now
#endif
#ifdef __BORLANDC__
// Redefine __MINMAX_DEFINED so Windows header files compile
#ifndef __MINMAX_DEFINED
#define __MINMAX_DEFINED
#endif
#endif
#endif