]> git.lyx.org Git - lyx.git/blob - src/PainterBase.h
b6a47568f9349ad8710fd248f34f701fb90060ea
[lyx.git] / src / PainterBase.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *          Copyright 1998-2000 The LyX Team
8  *
9  *======================================================*/
10
11 #ifndef PAINTERBASE_H
12 #define PAINTERBASE_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include "LString.h"
19 #include "LColor.h"
20
21 class WorkArea;
22 class LyXFont;
23
24 /** A painter class to encapsulate all graphics parameters and operations
25    
26     Every graphics operation in LyX should be made by this class. It will 
27     be initialized and managed by the Screen class, and will be passed
28     as a parameter to inset.
29  
30     It hides low level windows system parameters so insets and other
31     clients don't have to worry about them and we can control graphics and
32     GUI toolkit dependent drawing functions inside this single class.
33  
34  */
35 class PainterBase {
36 protected:
37         ///
38         static int dummy1, dummy2, dummy3;
39 public:
40         ///
41         enum line_width {
42                 ///
43                 line_thin,
44                 ///
45                 line_thick
46         };
47
48         ///
49         enum line_style {
50                 ///
51                 line_solid,
52                 ///
53                 line_doubledash,
54                 ///
55                 line_onoffdash
56         };
57
58         ///
59         explicit PainterBase(WorkArea & wa) : owner(wa) {}
60         
61         ///
62         virtual ~PainterBase() {}
63
64         /** Screen geometry */
65         ///
66         int paperMargin() const;
67         ///
68         int paperWidth() const;
69         
70         /**@Basic drawing routines */
71         /// Draw a line from point to point
72         virtual PainterBase & line(
73                 int x1, int y1, int x2, int y2, 
74                 LColor::color = LColor::foreground,
75                 enum line_style = line_solid,
76                 enum line_width = line_thin) = 0;
77
78         /** Draw the lines between the lines in xp and yp.
79             xp and yp are arrays of points, and np is the
80             number of them. */
81         virtual PainterBase & lines(
82                 int const * xp, int const * yp, int np,
83                 LColor::color = LColor::foreground,
84                 enum line_style = line_solid,
85                 enum line_width = line_thin) = 0;
86
87         /// Here xp and yp are arrays of points
88         virtual PainterBase & fillPolygon(
89                 int const * xp, int const * yp,
90                 int np,
91                 LColor::color =LColor::foreground) = 0;
92
93         /// Draw lines from x1,y1 to x2,y2. They are arrays
94         virtual PainterBase & segments(
95                 int const * x1, int const * y1, 
96                 int const * x2, int const * y2, int ns,
97                 LColor::color = LColor::foreground,
98                 enum line_style = line_solid,
99                 enum line_width = line_thin) = 0;
100         
101         /// Draw a rectangle 
102         virtual PainterBase & rectangle(
103                 int x, int y, int w, int h,
104                 LColor::color = LColor::foreground,
105                 enum line_style = line_solid,
106                 enum line_width = line_thin) = 0;
107         
108         /// Draw a circle, d is the diameter, not the radious
109         virtual PainterBase & circle(
110                 int x, int y, unsigned int d,
111                 LColor::color = LColor::foreground);
112
113         /// Draw an ellipse
114         virtual PainterBase & ellipse(
115                 int x, int y,
116                 unsigned int w, unsigned int h,
117                 LColor::color = LColor::foreground);
118         
119         /// Draw an arc
120         virtual PainterBase & arc(
121                 int x, int y,
122                 unsigned int w, unsigned int h, 
123                 int a1, int a2,
124                 LColor::color = LColor::foreground) = 0;
125         
126         /// Draw a pixel
127         virtual PainterBase & point(
128                 int x, int y,
129                 LColor::color = LColor::foreground) = 0;
130         
131         /// Fill a rectangle
132         virtual PainterBase & fillRectangle(
133                 int x, int y, int w, int h,
134                 LColor::color = LColor::background) = 0;
135         
136         /// A filled rectangle with the shape of a 3D button
137         virtual PainterBase & button(int x, int y, int w, int h);
138
139         /// 
140         virtual PainterBase & buttonFrame(int x, int y, int w, int h);
141         
142         /**@Image stuff */
143         
144         /// For the figure inset
145         // This can't be part of the base since we don't know what window
146         // system we will be useing, or if are going to use pixmaps at all.
147         //virtual PainterBase & pixmap(int x, int y, Pixmap bitmap)=0;
148
149         
150         /**@String functions */
151         
152         /// Draw a string at position x, y (y is the baseline)
153         virtual PainterBase & text(int x, int y,
154                                    string const &str, LyXFont const & f) = 0;
155
156         /** Draw a string at position x, y (y is the baseline)
157             This is just for fast drawing */
158         virtual PainterBase & text(int x, int y, char const * str, int l,
159                        LyXFont const & f) = 0;
160
161         /// Draw a char at position x, y (y is the baseline)
162         virtual PainterBase & text(int x, int y, char c, LyXFont const & f)=0;
163         
164         /** Draws a string and encloses it inside a rectangle. Returns
165             the size of the rectangle. If draw is false, we only calculate
166             the size. */
167         virtual PainterBase & rectText(int x, int baseline, 
168                            string const & string, 
169                            LyXFont const & font,
170                            LColor::color back,
171                            LColor::color frame, bool draw = true,
172                            int & width = PainterBase::dummy1,
173                            int & ascent = PainterBase::dummy2, 
174                            int & descent = PainterBase::dummy3);
175
176         /** Draw a string and encloses it inside a button frame. Returns
177             the size of the frame. If draw is false, we only calculate
178             the size. */
179         virtual PainterBase & buttonText(int x, int baseline, string const & s,
180                              LyXFont const & font, bool draw = true,
181                              int & width = PainterBase::dummy1,
182                              int & ascent = PainterBase::dummy2, 
183                              int & descent = PainterBase::dummy3);
184 protected:
185         WorkArea & owner;
186 };
187
188 #endif