]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
small cleanup while looking for a bug.
[lyx.git] / src / frontends / Painter.h
1 // -*- C++ -*-
2 /**
3  * \file Painter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef PAINTER_H
14 #define PAINTER_H
15
16 #include "support/docstring.h"
17
18 namespace lyx {
19
20 class LColor_color;
21 class LyXFont;
22
23 namespace graphics { class Image; }
24
25 namespace frontend {
26
27 /**
28  * Painter - A painter class to encapsulate all graphics parameters and operations
29  *
30  * Every graphics operation in LyX should be made by this class. The
31  * painter is used for drawing on the WorkArea, and is passed around
32  * during draw operations.
33  *
34  * It hides low level windows system parameters so insets and other
35  * clients don't have to worry about them and we can control graphics and
36  * GUI toolkit dependent drawing functions inside this single class.
37  *
38  * The intention for a toolkit is that it uses these methods to paint
39  * onto a backing pixmap. Only when expose events arrive via the event
40  * queue (perhaps generated via Screen::expose), does the copy onto
41  * the actual WorkArea widget take place. Paints are wrapped in (possibly
42  * recursive) calls to start() and end() to facilitate the backing pixmap
43  * management.
44  *
45  * Note that the methods return *this for convenience.
46  */
47 class Painter {
48 public:
49         Painter(): drawing_enabled_(true) {}
50         /// possible line widths
51         enum line_width {
52                 line_thin, //< thin line
53                 line_thick //< thick line
54         };
55
56         /// possible line styles
57         enum line_style {
58                 line_solid, //< solid line
59                 line_onoffdash //< dashes with spaces
60         };
61
62         virtual ~Painter() {}
63
64         /// draw a line from point to point
65         virtual void line(
66                 int x1, int y1,
67                 int x2, int y2,
68                 LColor_color,
69                 line_style = line_solid,
70                 line_width = line_thin) = 0;
71
72         /**
73          * lines -  draw a set of lines
74          * @param xp array of points' x co-ords
75          * @param yp array of points' y co-ords
76          * @param np size of the points array
77          */
78         virtual void lines(
79                 int const * xp,
80                 int const * yp,
81                 int np,
82                 LColor_color,
83                 line_style = line_solid,
84                 line_width = line_thin) = 0;
85
86         /// draw a rectangle
87         virtual void rectangle(
88                 int x, int y,
89                 int w, int h,
90                 LColor_color,
91                 line_style = line_solid,
92                 line_width = line_thin) = 0;
93
94         /// draw a filled rectangle
95         virtual void fillRectangle(
96                 int x, int y,
97                 int w, int h,
98                 LColor_color) = 0;
99
100         /// draw an arc
101         virtual void arc(
102                 int x, int y,
103                 unsigned int w, unsigned int h,
104                 int a1, int a2,
105                 LColor_color) = 0;
106
107         /// draw a pixel
108         virtual void point(
109                 int x, int y,
110                 LColor_color) = 0;
111
112         /// draw a filled rectangle with the shape of a 3D button
113         virtual void button(int x, int y,
114                 int w, int h);
115
116         /// draw an image from the image cache
117         virtual void image(int x, int y,
118                 int w, int h,
119                 graphics::Image const & image) = 0;
120
121         /// draw a string at position x, y (y is the baseline)
122         /**
123         * \return the width of the drawn text.
124         */
125         virtual int text(int x, int y,
126                 docstring const & str, LyXFont const & f) = 0;
127
128         void setDrawingEnabled(bool drawing_enabled = true)
129         { drawing_enabled_ = drawing_enabled; }
130
131         /**
132          * Draw a string at position x, y (y is the baseline)
133          * This is just for fast drawing
134          * \return the width of the drawn text.
135          */
136         virtual int text(int x, int y,
137                 char_type const * str, size_t l, LyXFont const & f) = 0;
138
139         /// draw a char at position x, y (y is the baseline)
140         /**
141         * \return the width of the drawn text.
142         */
143         virtual int text(int x, int y, char_type c, LyXFont const & f) = 0;
144
145         /**
146          * Draw a string and enclose it inside a rectangle. If
147          * back color is specified, the background is cleared with
148          * the given color. If frame is specified, a thin frame is drawn
149          * around the text with the given color.
150          */
151         virtual void rectText(int x, int baseline,
152                 docstring const & str,
153                 LyXFont const & font,
154                 LColor_color back,
155                 LColor_color frame);
156
157         /// draw a string and enclose it inside a button frame
158         virtual void buttonText(int x,
159                 int baseline, docstring const & s, LyXFont const & font);
160
161 protected:
162         /// check the font, and if set, draw an underline
163         virtual void underline(LyXFont const & f,
164                 int x, int y, int width);
165
166         /// draw a bevelled button border
167         virtual void buttonFrame(int x, int y, int w, int h);
168
169         /// Indicate wether real screen drawing shall be done or not.
170         bool isDrawingEnabled() const { return drawing_enabled_; }
171
172 private:
173         ///
174         bool drawing_enabled_;
175 };
176
177 } // namespace frontend
178 } // namespace lyx
179
180 #endif // PAINTER_H