1
//------------------------------------------------------------------------------
3
// This file is part of Toolkit for Conceptual Modeling (TCM).
4
// (c) copyright 1995, Vrije Universiteit Amsterdam.
5
// Author: Frank Dehne (frank@cs.vu.nl).
7
// TCM is free software; you can redistribute it and/or modify
8
// it under the terms of the GNU General Public License as published by
9
// the Free Software Foundation; either version 2 of the License, or
10
// (at your option) any later version.
12
// TCM is distributed in the hope that it will be useful,
13
// but WITHOUT ANY WARRANTY; without even the implied warranty of
14
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
// GNU General Public License for more details.
17
// You should have received a copy of the GNU General Public License
18
// along with TCM; if not, write to the Free Software
19
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21
//-----------------------------------------------------------------------------
25
#include "rectangle.h"
28
#include "linestyle.h"
29
#include "fillstyle.h"
34
/// (abstract) grafport class (primitive drawing functions).
36
/*@Doc: {\large {\bf scope:} GUI} */
44
virtual bool DrawsXor() {return False;}
46
// Sizes, refreshment.
48
virtual void ClearArea(double x, double y,
49
double wd, double ht)=0;
51
virtual void UpdateSize(double, double) {;}
53
virtual double GetWidth() {return 0;}
55
virtual double GetHeight() {return 0;}
57
virtual void Redraw(double, double, double, double,
61
/// Make this the current font.
62
virtual void SetFont(XFont *f) {font = f;}
63
/// Get the current font.
64
XFont *GetFont() {return font;}
68
virtual void SetBackgroundColor(const char *colorName)
69
{backgroundColor = colorName;}
71
virtual void SetBackgroundColor(const string *colorName)
72
{backgroundColor = *colorName;}
74
virtual void SetForegroundColor(const char *colorName)
75
{foregroundColor = colorName;}
77
virtual void SetForegroundColor(const string *colorName)
78
{foregroundColor = *colorName;}
80
const string *GetBackgroundColor() {return &backgroundColor;}
82
const string *GetForegroundColor() {return &foregroundColor;}
85
List<Color *> *GetColors() {return colors;}
89
void SetLineStyle(LineStyle::Type s) {lineStyle=s;}
91
LineStyle::Type GetLineStyle() {return lineStyle;}
95
void SetFillStyle(FillStyle::Type s) {fillStyle=s;}
97
FillStyle::Type GetFillStyle() {return fillStyle;}
101
virtual void SetLineWidth(unsigned n) {lineWidth=n;}
103
unsigned GetLineWidth() {return lineWidth;}
107
void SetZoomValue(double newValue) {zoomValue = newValue;}
109
double GetZoomValue() {return zoomValue;}
111
double Zoom(double x) {return x * zoomValue;}
113
double ZoomCorrect(double x) {return x / zoomValue;}
115
// All draw functions, except those called 'Edit', are printable
116
// (are exported to Postscript etc.)
117
// All draw functions, except those called 'Edit' or 'Unzoomed' are
120
// Drawing Rectangles.
122
virtual void DrawRectangle(double x, double y,
123
double wd, double ht)=0;
125
virtual void FillRectangle(double x, double y,
126
double wd, double ht)=0;
128
/// Draw list of n rectangles.
129
void DrawRectangles(const Rectangle *rects, int n);
131
void FillRectangles(const Rectangle *rects, int n);
133
/// Draw dashed rectangle (not zoomed, not printed)
134
virtual void DrawEditDashedRectangle(double, double, double, double) {;}
136
virtual void DrawUnzoomedRectangle(double, double, double, double) = 0;
139
/// Draw string with topleft at (x,y)
140
virtual void DrawStringLeft(double x, double y,
143
/// Draw string centered at (x,y)
144
virtual void DrawStringCentered(double x, double y,
147
/// Draw string with topright at (x,y)
148
virtual void DrawStringRight(double x, double y,
151
/// Draw string with topleft underlined at (x,y)
152
virtual void DrawStringLeftUnderlined(double x, double y,
155
/// Draw string centered underlined at (x,y)
156
virtual void DrawStringCenteredUnderlined(double x, double y,
159
/// Draw string with topright underlined at (x,y)
160
virtual void DrawStringRightUnderlined(double x, double y,
163
/// Draws n-line string centered (underlined?) at (x,y),
164
/// returns cursor position.
165
Point DrawStringsCentered(double x, double y,
166
const string *str, bool ul, int cursor=0);
168
/// draw n-line string left aligned, returns cursor position.
169
Point DrawStringsLeft(double topLeftx, double topLefty,
170
const string *str, bool ul, int cursor=0);
172
/// draw n-line string right aligned, return cursor position.
173
Point DrawStringsRight(double topRightx, double topRighty,
174
const string *str, bool ul, int cursor=0);
176
/// return cursor place closest to hitX, hitY.
177
unsigned CursorPosition(double x, double y,
178
const string *str, double hitX, double hitY);
181
virtual void DrawUnzoomedStringLeft(double, double, const char *)=0;
183
virtual void DrawUnzoomedStringCentered(double, double, const char *)=0;
186
/// Draw a line from (x1,y1) to (x2,y2).
187
void DrawLine(double x1, double y1,
188
double x2, double y2);
190
/// Draw a B�zier curve with 4 points.
191
void DrawCurve(const DPoint *p);
193
/// not zoomed not printed.
194
virtual void DrawEditLine(double, double, double, double) {;}
196
/// not zoomed or printed. Uses special dot pattern.
197
virtual void DrawEditDottedGridLine(double, double, double, double) {;}
199
virtual void DrawEditDottedLine(double, double, double, double) {;}
201
/// not zoomed or printed.
202
virtual void DrawEditPoint(double, double) {;}
205
virtual void DrawUnzoomedLine(double, double, double, double) = 0;
209
virtual void DrawPoint(double x, double y)=0;
213
virtual void DrawEllipse(double x, double y,
214
double wd, double ht)=0;
216
virtual void FillEllipse(double x, double y,
217
double wd, double ht)=0;
220
/// Draw an arc. (x,y) = top left of the corresponding ellipse,
221
/// (w,h) = size of the corresponding ellipse, arc1 = start angle,
222
/// arc2 = end angle (�, 3 o'clock position = 0, counterclockwise)
223
void DrawArc(double x, double y,
224
double w, double h, int arc1, int arc2);
226
virtual void FillSegment(double x, double y,
227
double wd, double ht, int arc1, int arc2)=0;
230
/// Draw a closed polygon with n edges.
231
virtual void DrawPolygon(const Point *points, int n) = 0;
232
/// Draw an open polygon between points[0]...points[n-1] with n-1
234
void DrawOpenPolygon(const DPoint *points, int n);
236
virtual void FillPolygon(const Point *plist, int n)=0;
238
virtual void FillPolygon(const DPoint *plist, int n)=0;
240
// Drawing text edit cursors.
241
/// Draw active cursor sign.
242
virtual void DrawActiveCaret(double, double) {;}
244
/// Draw deactive cursor sign.
245
virtual void DrawDeactiveCaret(double, double) {;}
249
Point CursorPosition(double x, double y, const string *buf,
253
Color *LookupColor(const string *colorName);
255
Color *LookupColor(const char *colorName);
257
void AddColor(const string *colorName, unsigned long pixel);
259
void AddColor(const char *colorName, unsigned long pixel);
261
void AddColor(Color *c);
264
virtual void InitColors();
267
void RecalcPolygon(const Point *points, int nrPoints,
268
Point *newPoints, int d);
270
/// Draw an arc (one line, neglect line style DUAL).
271
virtual void DrawSimpleArc(double x, double y,
272
double w, double h, int arc1, int arc2) = 0;
273
/// Draw an open polygon (one line, neglect line style DUAL).
274
virtual void DrawSimplePolygon(const DPoint *points, int n)
276
/// Draw a curve (one line, neglect line style DUAL).
277
virtual void DrawSimpleCurve(const DPoint *points) = 0;
286
/// Current background color.
287
string backgroundColor;
289
/// Current foreground color.
290
string foregroundColor;
292
/// current line width.
295
/// current line style.
296
LineStyle::Type lineStyle;
298
/// current fill style.
299
FillStyle::Type fillStyle;
301
/// current zoom value.
307
/// a cache for the colors.
308
List<Color *> *colors;