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