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