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