4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
10 * Full author contact details are available in file CREDITS.
16 #include "ColorCode.h"
18 #include "support/docstring.h"
24 namespace graphics { class Image; }
29 * Painter - A painter class to encapsulate all graphics parameters and operations
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.
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.
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
46 * Note that the methods return *this for convenience.
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.
57 Painter(): drawing_enabled_(true) {}
58 /// possible line widths
60 line_thin, //< thin line
61 line_thick //< thick line
64 /// possible line styles
66 line_solid, //< solid line
67 line_onoffdash //< dashes with spaces
70 /// possible character styles of preedit string.
71 /// This is used for CJK input method support.
73 preedit_default, //< when unselecting, no cursor and dashed underline.
74 preedit_selecting, //< when selecting.
75 preedit_cursor //< with cursor.
80 /// draw a line from point to point
85 line_style = line_solid,
86 line_width = line_thin) = 0;
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
99 line_style = line_solid,
100 line_width = line_thin) = 0;
103 virtual void rectangle(
107 line_style = line_solid,
108 line_width = line_thin) = 0;
110 /// draw a filled rectangle
111 virtual void fillRectangle(
119 unsigned int w, unsigned int h,
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);
132 /// draw an image from the image cache
133 virtual void image(int x, int y,
135 graphics::Image const & image) = 0;
137 /// draw a string at position x, y (y is the baseline)
139 * \return the width of the drawn text.
141 virtual int text(int x, int y,
142 docstring const & str, FontInfo const & f) = 0;
144 void setDrawingEnabled(bool drawing_enabled = true)
145 { drawing_enabled_ = drawing_enabled; }
147 /// draw a char at position x, y (y is the baseline)
149 * \return the width of the drawn text.
151 virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
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.
159 void rectText(int x, int baseline,
160 docstring const & str,
161 FontInfo const & font,
165 /// draw a string and enclose it inside a button frame
166 void buttonText(int x, int baseline, docstring const & s,
167 FontInfo const & font, bool mouseHover);
169 /// draw a character of a preedit string for cjk support.
170 int preeditText(int x, int y,
171 char_type c, FontInfo const & f, preedit_style style);
174 /// check the font, and if set, draw an underline
175 void underline(FontInfo const & f,
176 int x, int y, int width);
178 /// check the font, and if set, draw an dashed underline
179 void dashedUnderline(FontInfo const & f,
180 int x, int y, int width);
182 /// draw a bevelled button border
183 void buttonFrame(int x, int y, int w, int h);
185 /// Indicate wether real screen drawing shall be done or not.
186 bool isDrawingEnabled() const { return drawing_enabled_; }
190 bool drawing_enabled_;
193 } // namespace frontend