]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
header cleanup.
[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 Color_color;
21 class Font;
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         /// possible character styles of preedit string.
70         /// This is used for CJK input method support.
71         enum preedit_style {
72                 preedit_default, //< when unselecting, no cursor and dashed underline.
73                 preedit_selecting, //< when selecting.
74                 preedit_cursor //< with cursor.
75         };
76
77         virtual ~Painter() {}
78
79         /// draw a line from point to point
80         virtual void line(
81                 int x1, int y1,
82                 int x2, int y2,
83                 Color_color,
84                 line_style = line_solid,
85                 line_width = line_thin) = 0;
86
87         /**
88          * lines -  draw a set of lines
89          * @param xp array of points' x co-ords
90          * @param yp array of points' y co-ords
91          * @param np size of the points array
92          */
93         virtual void lines(
94                 int const * xp,
95                 int const * yp,
96                 int np,
97                 Color_color,
98                 line_style = line_solid,
99                 line_width = line_thin) = 0;
100
101         /// draw a rectangle
102         virtual void rectangle(
103                 int x, int y,
104                 int w, int h,
105                 Color_color,
106                 line_style = line_solid,
107                 line_width = line_thin) = 0;
108
109         /// draw a filled rectangle
110         virtual void fillRectangle(
111                 int x, int y,
112                 int w, int h,
113                 Color_color) = 0;
114
115         /// draw an arc
116         virtual void arc(
117                 int x, int y,
118                 unsigned int w, unsigned int h,
119                 int a1, int a2,
120                 Color_color) = 0;
121
122         /// draw a pixel
123         virtual void point(
124                 int x, int y,
125                 Color_color) = 0;
126
127         /// draw a filled rectangle with the shape of a 3D button
128         virtual void button(int x, int y,
129                 int w, int h, bool mouseHover);
130
131         /// draw an image from the image cache
132         virtual void image(int x, int y,
133                 int w, int h,
134                 graphics::Image const & image) = 0;
135
136         /// draw a string at position x, y (y is the baseline)
137         /**
138         * \return the width of the drawn text.
139         */
140         virtual int text(int x, int y,
141                 docstring const & str, Font const & f) = 0;
142
143         void setDrawingEnabled(bool drawing_enabled = true)
144         { drawing_enabled_ = drawing_enabled; }
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, Font 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                 Font const & font,
161                 Color_color back,
162                 Color_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                 Font const & font, bool mouseHover);
167
168         /// draw a character of a preedit string for cjk support.
169         int preeditText(int x, int y,
170                 char_type c, Font const & f, preedit_style style);
171
172 protected:
173         /// check the font, and if set, draw an underline
174         void underline(Font const & f,
175                 int x, int y, int width);
176
177         /// check the font, and if set, draw an dashed underline
178         void dashedUnderline(Font const & f,
179                 int x, int y, int width);
180
181         /// draw a bevelled button border
182         void buttonFrame(int x, int y, int w, int h);
183
184         /// Indicate wether real screen drawing shall be done or not.
185         bool isDrawingEnabled() const { return drawing_enabled_; }
186
187 private:
188         ///
189         bool drawing_enabled_;
190 };
191
192 } // namespace frontend
193 } // namespace lyx
194
195 #endif // PAINTER_H