]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
* src/frontends/qt4/GuiSelection.C
[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  * Caution: All char_type and docstring arguments of the text drawing
48  * methods of this class are no UCS4 chars or strings if the font is a
49  * symbol font. They simply denote the code points of the font instead.
50  * You have to keep this in mind when you implement the methods in a
51  * frontend. You must not pass these parameters to a unicode conversion
52  * function in particular.
53  */
54 class Painter {
55 public:
56         Painter(): drawing_enabled_(true) {}
57         /// possible line widths
58         enum line_width {
59                 line_thin, //< thin line
60                 line_thick //< thick line
61         };
62
63         /// possible line styles
64         enum line_style {
65                 line_solid, //< solid line
66                 line_onoffdash //< dashes with spaces
67         };
68
69         virtual ~Painter() {}
70
71         /// draw a line from point to point
72         virtual void line(
73                 int x1, int y1,
74                 int x2, int y2,
75                 LColor_color,
76                 line_style = line_solid,
77                 line_width = line_thin) = 0;
78
79         /**
80          * lines -  draw a set of lines
81          * @param xp array of points' x co-ords
82          * @param yp array of points' y co-ords
83          * @param np size of the points array
84          */
85         virtual void lines(
86                 int const * xp,
87                 int const * yp,
88                 int np,
89                 LColor_color,
90                 line_style = line_solid,
91                 line_width = line_thin) = 0;
92
93         /// draw a rectangle
94         virtual void rectangle(
95                 int x, int y,
96                 int w, int h,
97                 LColor_color,
98                 line_style = line_solid,
99                 line_width = line_thin) = 0;
100
101         /// draw a filled rectangle
102         virtual void fillRectangle(
103                 int x, int y,
104                 int w, int h,
105                 LColor_color) = 0;
106
107         /// draw an arc
108         virtual void arc(
109                 int x, int y,
110                 unsigned int w, unsigned int h,
111                 int a1, int a2,
112                 LColor_color) = 0;
113
114         /// draw a pixel
115         virtual void point(
116                 int x, int y,
117                 LColor_color) = 0;
118
119         /// draw a filled rectangle with the shape of a 3D button
120         virtual void button(int x, int y,
121                 int w, int h, bool mouseHover);
122
123         /// draw an image from the image cache
124         virtual void image(int x, int y,
125                 int w, int h,
126                 graphics::Image const & image) = 0;
127
128         /// draw a string at position x, y (y is the baseline)
129         /**
130         * \return the width of the drawn text.
131         */
132         virtual int text(int x, int y,
133                 docstring const & str, LyXFont const & f) = 0;
134
135         void setDrawingEnabled(bool drawing_enabled = true)
136         { drawing_enabled_ = drawing_enabled; }
137
138         /**
139          * Draw a string at position x, y (y is the baseline)
140          * This is just for fast drawing
141          * \return the width of the drawn text.
142          */
143         virtual int text(int x, int y,
144                 char_type const * str, size_t l, LyXFont const & f) = 0;
145
146         /// draw a char at position x, y (y is the baseline)
147         /**
148         * \return the width of the drawn text.
149         */
150         virtual int text(int x, int y, char_type c, LyXFont const & f) = 0;
151
152         /**
153          * Draw a string and enclose it inside a rectangle. If
154          * back color is specified, the background is cleared with
155          * the given color. If frame is specified, a thin frame is drawn
156          * around the text with the given color.
157          */
158         void rectText(int x, int baseline,
159                 docstring const & str,
160                 LyXFont const & font,
161                 LColor_color back,
162                 LColor_color frame);
163
164         /// draw a string and enclose it inside a button frame
165         void buttonText(int x, int baseline, docstring const & s,
166                 LyXFont const & font, bool mouseHover);
167
168 protected:
169         /// check the font, and if set, draw an underline
170         void underline(LyXFont const & f,
171                 int x, int y, int width);
172
173         /// draw a bevelled button border
174         void buttonFrame(int x, int y, int w, int h);
175
176         /// Indicate wether real screen drawing shall be done or not.
177         bool isDrawingEnabled() const { return drawing_enabled_; }
178
179 private:
180         ///
181         bool drawing_enabled_;
182 };
183
184 } // namespace frontend
185 } // namespace lyx
186
187 #endif // PAINTER_H