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
71 /// draw a line from point to point
76 line_style = line_solid,
77 line_width = line_thin) = 0;
80 * lines - draw a set of lines
81 * @param xp array of points' x co-ords
82 * @param yp array of points' y co-ords
83 * @param np size of the points array
90 line_style = line_solid,
91 line_width = line_thin) = 0;
94 virtual void rectangle(
98 line_style = line_solid,
99 line_width = line_thin) = 0;
101 /// draw a filled rectangle
102 virtual void fillRectangle(
110 unsigned int w, unsigned int h,
119 /// draw a filled rectangle with the shape of a 3D button
120 virtual void button(int x, int y,
123 /// draw an image from the image cache
124 virtual void image(int x, int y,
126 graphics::Image const & image) = 0;
128 /// draw a string at position x, y (y is the baseline)
130 * \return the width of the drawn text.
132 virtual int text(int x, int y,
133 docstring const & str, LyXFont const & f) = 0;
135 void setDrawingEnabled(bool drawing_enabled = true)
136 { drawing_enabled_ = drawing_enabled; }
139 * Draw a string at position x, y (y is the baseline)
140 * This is just for fast drawing
141 * \return the width of the drawn text.
143 virtual int text(int x, int y,
144 char_type const * str, size_t l, LyXFont const & f) = 0;
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, LyXFont 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,
160 LyXFont const & font,
164 /// draw a string and enclose it inside a button frame
165 void buttonText(int x,
166 int baseline, docstring const & s, LyXFont const & font);
169 /// check the font, and if set, draw an underline
170 void underline(LyXFont const & f,
171 int x, int y, int width);
173 /// draw a bevelled button border
174 void buttonFrame(int x, int y, int w, int h);
176 /// Indicate wether real screen drawing shall be done or not.
177 bool isDrawingEnabled() const { return drawing_enabled_; }
181 bool drawing_enabled_;
184 } // namespace frontend