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