]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
'using namespace std' instead of 'using std::xxx'
[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(int x1, int y1, int x2, int y2, ColorCode,
82                 line_style = line_solid, line_width = line_thin) = 0;
83
84         /**
85          * lines -  draw a set of lines
86          * @param xp array of points' x co-ords
87          * @param yp array of points' y co-ords
88          * @param np size of the points array
89          */
90         virtual void lines(int const * xp, int const * yp, int np, ColorCode,
91                 line_style = line_solid, line_width = line_thin) = 0;
92
93         /// draw a rectangle
94         virtual void rectangle(int x, int y, int w, int h, ColorCode,
95                 line_style = line_solid, line_width = line_thin) = 0;
96
97         /// draw a filled rectangle
98         virtual void fillRectangle(int x, int y, int w, int h, ColorCode) = 0;
99
100         /// draw an arc
101         virtual void arc(int x, int y, unsigned int w, unsigned int h,
102                 int a1, int a2, ColorCode) = 0;
103
104         /// draw a pixel
105         virtual void point(int x, int y, ColorCode) = 0;
106
107         /// draw a filled rectangle with the shape of a 3D button
108         virtual void button(int x, int y, int w, int h, bool mouseHover) = 0;
109
110         /// draw an image from the image cache
111         virtual void image(int x, int y, int w, int h,
112                 graphics::Image const & image) = 0;
113
114         /// draw a string at position x, y (y is the baseline)
115         /**
116         * \return the width of the drawn text.
117         */
118         virtual int text(int x, int y, docstring const & str, FontInfo const & f) = 0;
119
120         void setDrawingEnabled(bool drawing_enabled)
121         { drawing_enabled_ = drawing_enabled; }
122
123         /// Indicate wether real screen drawing shall be done or not.
124         bool isDrawingEnabled() const { return drawing_enabled_; }
125
126         /// draw a char at position x, y (y is the baseline)
127         /**
128         * \return the width of the drawn text.
129         */
130         virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
131
132         /**
133          * Draw a string and enclose it inside a rectangle. If
134          * back color is specified, the background is cleared with
135          * the given color. If frame is specified, a thin frame is drawn
136          * around the text with the given color.
137          */
138         virtual void rectText(int x, int baseline, docstring const & str,
139                 FontInfo const & font, ColorCode back, ColorCode frame) = 0;
140
141         /// draw a string and enclose it inside a button frame
142         virtual void buttonText(int x, int baseline, docstring const & s,
143                 FontInfo const & font, bool mouseHover) = 0;
144
145         /// draw a character of a preedit string for cjk support.
146         virtual int preeditText(int x, int y,
147                 char_type c, FontInfo const & f, preedit_style style) = 0;
148
149         /// start monochrome painting mode, i.e. map every color into [min,max]
150         virtual void enterMonochromeMode(ColorCode const & min, 
151                 ColorCode const & max) = 0;
152         /// leave monochrome painting mode
153         virtual void leaveMonochromeMode() = 0;
154
155 private:
156         ///
157         bool drawing_enabled_;
158 };
159
160 } // namespace frontend
161 } // namespace lyx
162
163 #endif // PAINTER_H