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 "support/docstring.h"
23 namespace graphics { class Image; }
28 * Painter - A painter class to encapsulate all graphics parameters and operations
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.
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.
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
45 * Note that the methods return *this for convenience.
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.
56 Painter(): drawing_enabled_(true) {}
57 /// possible line widths
59 line_thin, //< thin line
60 line_thick //< thick line
63 /// possible line styles
65 line_solid, //< solid line
66 line_onoffdash //< dashes with spaces
69 /// possible character styles of preedit string.
70 /// This is used for CJK input method support.
72 preedit_default, //< when unselecting, no cursor and dashed underline.
73 preedit_selecting, //< when selecting.
74 preedit_cursor //< with cursor.
79 /// draw a line from point to point
84 line_style = line_solid,
85 line_width = line_thin) = 0;
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
98 line_style = line_solid,
99 line_width = line_thin) = 0;
102 virtual void rectangle(
106 line_style = line_solid,
107 line_width = line_thin) = 0;
109 /// draw a filled rectangle
110 virtual void fillRectangle(
118 unsigned int w, unsigned int h,
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);
131 /// draw an image from the image cache
132 virtual void image(int x, int y,
134 graphics::Image const & image) = 0;
136 /// draw a string at position x, y (y is the baseline)
138 * \return the width of the drawn text.
140 virtual int text(int x, int y,
141 docstring const & str, Font const & f) = 0;
143 void setDrawingEnabled(bool drawing_enabled = true)
144 { drawing_enabled_ = drawing_enabled; }
146 /// draw a char at position x, y (y is the baseline)
148 * \return the width of the drawn text.
150 virtual int text(int x, int y, char_type c, Font const & f) = 0;
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.
158 void rectText(int x, int baseline,
159 docstring const & str,
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);
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);
173 /// check the font, and if set, draw an underline
174 void underline(Font const & f,
175 int x, int y, int width);
177 /// check the font, and if set, draw an dashed underline
178 void dashedUnderline(Font const & f,
179 int x, int y, int width);
181 /// draw a bevelled button border
182 void buttonFrame(int x, int y, int w, int h);
184 /// Indicate wether real screen drawing shall be done or not.
185 bool isDrawingEnabled() const { return drawing_enabled_; }
189 bool drawing_enabled_;
192 } // namespace frontend