~ubuntu-branches/ubuntu/utopic/tcm/utopic

« back to all changes in this revision

Viewing changes to src/ui/grafport.h

  • Committer: Bazaar Package Importer
  • Author(s): Otavio Salvador
  • Date: 2003-07-03 20:08:21 UTC
  • Revision ID: james.westby@ubuntu.com-20030703200821-se4xtqx25e5miczi
Tags: upstream-2.20
Import upstream version 2.20

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//------------------------------------------------------------------------------
 
2
// 
 
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).
 
6
//
 
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.
 
11
//
 
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.
 
16
//
 
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
 
20
// 02111-1307, USA.
 
21
//-----------------------------------------------------------------------------
 
22
#ifndef _GRAFPORT_H 
 
23
#define _GRAFPORT_H
 
24
 
 
25
#include "rectangle.h"
 
26
#include "lstring.h"
 
27
#include "xfont.h"
 
28
#include "linestyle.h"
 
29
#include "fillstyle.h"
 
30
#include "llist.h"
 
31
#include "color.h"
 
32
#include "dpoint.h"
 
33
 
 
34
/// (abstract) grafport class (primitive drawing functions).
 
35
class Grafport {
 
36
/*@Doc: {\large {\bf scope:} GUI} */
 
37
public:
 
38
        ///
 
39
        Grafport();
 
40
        ///
 
41
        virtual ~Grafport();
 
42
 
 
43
        ///
 
44
        virtual bool DrawsXor() {return False;}
 
45
 
 
46
// Sizes, refreshment.
 
47
        ///
 
48
        virtual void ClearArea(double x, double y,
 
49
                double wd, double ht)=0;
 
50
        ///
 
51
        virtual void UpdateSize(double, double) {;}
 
52
        ///
 
53
        virtual double GetWidth() {return 0;}
 
54
        ///
 
55
        virtual double GetHeight() {return 0;}
 
56
        ///
 
57
        virtual void Redraw(double, double, double, double,
 
58
                double, double) {;}
 
59
 
 
60
// Fonts
 
61
        /// Make this the current font.
 
62
        virtual void SetFont(XFont *f) {font = f;}
 
63
        /// Get the current font.
 
64
        XFont *GetFont() {return font;}
 
65
 
 
66
// Colors
 
67
        ///
 
68
        virtual void SetBackgroundColor(const char *colorName)
 
69
                {backgroundColor = colorName;}
 
70
        ///
 
71
        virtual void SetBackgroundColor(const string *colorName)
 
72
                {backgroundColor = *colorName;}
 
73
        ///
 
74
        virtual void SetForegroundColor(const char *colorName)
 
75
                {foregroundColor = colorName;}
 
76
        ///
 
77
        virtual void SetForegroundColor(const string *colorName) 
 
78
                {foregroundColor = *colorName;}
 
79
        ///
 
80
        const string *GetBackgroundColor() {return &backgroundColor;}
 
81
        ///
 
82
        const string *GetForegroundColor() {return &foregroundColor;}
 
83
 
 
84
        ///
 
85
        List<Color *> *GetColors() {return colors;}
 
86
 
 
87
// Line styles.
 
88
        ///
 
89
        void SetLineStyle(LineStyle::Type s) {lineStyle=s;}
 
90
        ///
 
91
        LineStyle::Type GetLineStyle() {return lineStyle;}
 
92
 
 
93
// Fill styles.
 
94
        ///
 
95
        void SetFillStyle(FillStyle::Type s) {fillStyle=s;}
 
96
        ///
 
97
        FillStyle::Type GetFillStyle() {return fillStyle;}
 
98
 
 
99
// Line width.
 
100
        ///
 
101
        virtual void SetLineWidth(unsigned n) {lineWidth=n;}
 
102
        ///
 
103
        unsigned GetLineWidth() {return lineWidth;}
 
104
 
 
105
/// Zooming in/out.
 
106
        /// set zoom value.
 
107
        void SetZoomValue(double newValue) {zoomValue = newValue;}
 
108
        ///
 
109
        double GetZoomValue() {return zoomValue;}
 
110
        ///
 
111
        double Zoom(double x) {return x * zoomValue;}
 
112
        ///
 
113
        double ZoomCorrect(double x) {return x / zoomValue;}
 
114
 
 
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 
 
118
        // zoomed.
 
119
 
 
120
// Drawing Rectangles.
 
121
        ///
 
122
        virtual void DrawRectangle(double x, double y,
 
123
                double wd, double ht)=0;
 
124
        ///
 
125
        virtual void FillRectangle(double x, double y,
 
126
                double wd, double ht)=0;
 
127
 
 
128
        /// Draw list of n rectangles.
 
129
        void DrawRectangles(const Rectangle *rects, int n);
 
130
        ///
 
131
        void FillRectangles(const Rectangle *rects, int n);
 
132
 
 
133
        /// Draw dashed rectangle (not zoomed, not printed)
 
134
        virtual void DrawEditDashedRectangle(double, double, double, double) {;}
 
135
        ///
 
136
        virtual void DrawUnzoomedRectangle(double, double, double, double) = 0;
 
137
 
 
138
// Drawing Strings
 
139
        /// Draw string with topleft at (x,y)
 
140
        virtual void DrawStringLeft(double x, double y,
 
141
                const char *str)=0;
 
142
 
 
143
        /// Draw string centered at (x,y)
 
144
        virtual void DrawStringCentered(double x, double y,
 
145
                const char *str)=0;
 
146
 
 
147
        /// Draw string with topright at (x,y)
 
148
        virtual void DrawStringRight(double x, double y,
 
149
                const char *str)=0;
 
150
 
 
151
        /// Draw string with topleft underlined at (x,y)
 
152
        virtual void DrawStringLeftUnderlined(double x, double y,
 
153
                const char *str)=0;
 
154
 
 
155
        /// Draw string centered underlined at (x,y)
 
156
        virtual void DrawStringCenteredUnderlined(double x, double y,
 
157
                const char *str)=0;
 
158
 
 
159
        /// Draw string with topright underlined at (x,y)
 
160
        virtual void DrawStringRightUnderlined(double x, double y,
 
161
                const char *str)=0;
 
162
 
 
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);
 
167
 
 
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);
 
171
 
 
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);
 
175
 
 
176
        /// return cursor place closest to hitX, hitY.
 
177
        unsigned CursorPosition(double x, double y,
 
178
                const string *str, double hitX, double hitY);
 
179
 
 
180
        ///
 
181
        virtual void DrawUnzoomedStringLeft(double, double, const char *)=0;
 
182
        ///
 
183
        virtual void DrawUnzoomedStringCentered(double, double, const char *)=0;
 
184
 
 
185
// Drawing Lines
 
186
        /// Draw a line from (x1,y1) to (x2,y2).
 
187
        void DrawLine(double x1, double y1,
 
188
                double x2, double y2);
 
189
 
 
190
        /// Draw a B�zier curve with 4 points.                          
 
191
        void DrawCurve(const DPoint *p);                                
 
192
 
 
193
        /// not zoomed not printed.
 
194
        virtual void DrawEditLine(double, double, double, double) {;}
 
195
 
 
196
        /// not zoomed or printed. Uses special dot pattern.
 
197
        virtual void DrawEditDottedGridLine(double, double, double, double) {;}
 
198
        ///
 
199
        virtual void DrawEditDottedLine(double, double, double, double) {;}
 
200
 
 
201
        /// not zoomed or printed.
 
202
        virtual void DrawEditPoint(double, double) {;}
 
203
 
 
204
        ///
 
205
        virtual void DrawUnzoomedLine(double, double, double, double) = 0;
 
206
 
 
207
// Drawing Points
 
208
        ///
 
209
        virtual void DrawPoint(double x, double y)=0;
 
210
// Drawing Ellipses
 
211
        // used in lineend.c
 
212
        ///
 
213
        virtual void DrawEllipse(double x, double y,
 
214
                double wd, double ht)=0;
 
215
        /// 
 
216
        virtual void FillEllipse(double x, double y,
 
217
                double wd, double ht)=0;
 
218
 
 
219
// Drawing Arcs
 
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);
 
225
 
 
226
        virtual void FillSegment(double x, double y,    
 
227
                double wd, double ht, int arc1, int arc2)=0;
 
228
 
 
229
// Drawing Polygons
 
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
 
233
        /// edges.
 
234
        void DrawOpenPolygon(const DPoint *points, int n);              
 
235
        ///
 
236
        virtual void FillPolygon(const Point *plist, int n)=0;
 
237
        ///                                                             
 
238
        virtual void FillPolygon(const DPoint *plist, int n)=0; 
 
239
 
 
240
// Drawing text edit cursors.
 
241
        /// Draw active cursor sign.
 
242
        virtual void DrawActiveCaret(double, double) {;}
 
243
 
 
244
        /// Draw deactive cursor sign.
 
245
        virtual void DrawDeactiveCaret(double, double) {;}
 
246
 
 
247
protected:
 
248
        ///
 
249
        Point CursorPosition(double x, double y, const string *buf,
 
250
                int cursor);
 
251
 
 
252
        ///
 
253
        Color *LookupColor(const string *colorName);
 
254
        ///
 
255
        Color *LookupColor(const char *colorName);
 
256
        ///
 
257
        void AddColor(const string *colorName, unsigned long pixel);
 
258
        ///
 
259
        void AddColor(const char *colorName, unsigned long pixel);
 
260
        ///
 
261
        void AddColor(Color *c);
 
262
 
 
263
        ///
 
264
        virtual void InitColors();
 
265
 
 
266
        ///
 
267
        void RecalcPolygon(const Point *points, int nrPoints, 
 
268
                           Point *newPoints, int d);
 
269
 
 
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)     
 
275
                = 0;                                                    
 
276
        /// Draw a curve (one line, neglect line style DUAL).           
 
277
        virtual void DrawSimpleCurve(const DPoint *points) = 0; 
 
278
 
 
279
private:
 
280
        /// Current font.
 
281
        XFont *font;
 
282
 
 
283
        /// Default font.
 
284
        XFont *defaultFont;
 
285
 
 
286
        /// Current background color.
 
287
        string backgroundColor;
 
288
 
 
289
        /// Current foreground color.
 
290
        string foregroundColor;
 
291
 
 
292
        /// current line width.
 
293
        unsigned lineWidth;
 
294
 
 
295
        /// current line style.
 
296
        LineStyle::Type lineStyle;
 
297
 
 
298
        /// current fill style.
 
299
        FillStyle::Type fillStyle;
 
300
 
 
301
        /// current zoom value.
 
302
        double zoomValue;
 
303
 
 
304
        ///
 
305
        string buf;
 
306
 
 
307
        /// a cache for the colors.
 
308
        List<Color *> *colors;
 
309
};
 
310
#endif