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.
49 Painter(): drawing_enabled_(true) {}
50 /// possible line widths
52 line_thin, //< thin line
53 line_thick //< thick line
56 /// possible line styles
58 line_solid, //< solid line
59 line_onoffdash //< dashes with spaces
64 /// draw a line from point to point
69 line_style = line_solid,
70 line_width = line_thin) = 0;
73 * lines - draw a set of lines
74 * @param xp array of points' x co-ords
75 * @param yp array of points' y co-ords
76 * @param np size of the points array
83 line_style = line_solid,
84 line_width = line_thin) = 0;
87 virtual void rectangle(
91 line_style = line_solid,
92 line_width = line_thin) = 0;
94 /// draw a filled rectangle
95 virtual void fillRectangle(
103 unsigned int w, unsigned int h,
112 /// draw a filled rectangle with the shape of a 3D button
113 virtual void button(int x, int y,
116 /// draw an image from the image cache
117 virtual void image(int x, int y,
119 graphics::Image const & image) = 0;
121 /// draw a string at position x, y (y is the baseline)
123 * \return the width of the drawn text.
125 virtual int text(int x, int y,
126 docstring const & str, LyXFont const & f) = 0;
128 void setDrawingEnabled(bool drawing_enabled = true)
129 { drawing_enabled_ = drawing_enabled; }
132 * Draw a string at position x, y (y is the baseline)
133 * This is just for fast drawing
134 * \return the width of the drawn text.
136 virtual int text(int x, int y,
137 char_type const * str, size_t l, LyXFont const & f) = 0;
139 /// draw a char at position x, y (y is the baseline)
141 * \return the width of the drawn text.
143 virtual int text(int x, int y, char_type c, LyXFont const & f) = 0;
146 * Draw a string and enclose it inside a rectangle. If
147 * back color is specified, the background is cleared with
148 * the given color. If frame is specified, a thin frame is drawn
149 * around the text with the given color.
151 void rectText(int x, int baseline,
152 docstring const & str,
153 LyXFont const & font,
157 /// draw a string and enclose it inside a button frame
158 void buttonText(int x,
159 int baseline, docstring const & s, LyXFont const & font);
162 /// check the font, and if set, draw an underline
163 void underline(LyXFont const & f,
164 int x, int y, int width);
166 /// draw a bevelled button border
167 void buttonFrame(int x, int y, int w, int h);
169 /// Indicate wether real screen drawing shall be done or not.
170 bool isDrawingEnabled() const { return drawing_enabled_; }
174 bool drawing_enabled_;
177 } // namespace frontend