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/strfwd.h"
17 #include "support/types.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, does the copy onto the actual WorkArea widget take place.
43 * Caution: All char_type and docstring arguments of the text drawing
44 * methods of this class are no UCS4 chars or strings if the font is a
45 * symbol font. They simply denote the code points of the font instead.
46 * You have to keep this in mind when you implement the methods in a
47 * frontend. You must not pass these parameters to a unicode conversion
48 * function in particular.
52 Painter(double pixel_ratio) : drawing_enabled_(true), pixel_ratio_(pixel_ratio) {}
54 static const int thin_line;
56 /// possible line styles
58 line_solid, //< solid line
59 line_solid_aliased, //< solid line, no anti-aliasing (used as a
60 // workaround to painting issues)
61 line_onoffdash //< dashes with spaces
64 /// possible fill styles
71 /// possible character styles of preedit string.
72 /// This is used for CJK input method support.
74 preedit_default, //< when unselecting, no cursor and dashed underline.
75 preedit_selecting, //< when selecting.
76 preedit_cursor //< with cursor.
81 /// draw a line from point to point
82 virtual void line(int x1, int y1, int x2, int y2, Color,
83 line_style = line_solid, int line_width = thin_line) = 0;
86 * lines - draw a set of lines
87 * @param xp array of points' x co-ords
88 * @param yp array of points' y co-ords
89 * @param np size of the points array
91 virtual void lines(int const * xp, int const * yp, int np, Color,
92 fill_style = fill_none, line_style = line_solid,
93 int line_width = thin_line) = 0;
96 * path - draw a path with bezier curves
97 * @param xp array of points' x co-ords
98 * @param yp array of points' y co-ords
99 * @param c1x array of first control points' x co-ords
100 * @param c1y array of first control points' y co-ords
101 * @param c2x array of second control points' x co-ords
102 * @param c2y array of second control points' y co-ords
103 * @param np size of the points array
105 virtual void path(int const * xp, int const * yp,
106 int const * c1x, int const * c1y,
107 int const * c2x, int const * c2y,
109 fill_style = fill_none, line_style = line_solid,
110 int line_width = thin_line) = 0;
113 virtual void rectangle(int x, int y, int w, int h, Color,
114 line_style = line_solid, int line_width = thin_line) = 0;
116 /// draw a filled rectangle
117 virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
120 virtual void arc(int x, int y, unsigned int w, unsigned int h,
121 int a1, int a2, Color) = 0;
124 virtual void point(int x, int y, Color) = 0;
126 /// draw a filled rectangle with the shape of a 3D button
127 virtual void button(int x, int y, int w, int h, bool mouseHover) = 0;
129 /// draw an image from the image cache
130 virtual void image(int x, int y, int w, int h,
131 graphics::Image const & image) = 0;
133 /// draw a string at position x, y (y is the baseline).
134 virtual void text(int x, int y, docstring const & str, FontInfo const & f) = 0;
136 /// draw a char at position x, y (y is the baseline)
137 virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
139 /** draw a string at position x, y (y is the baseline). The
140 * text direction is enforced by the \c Font.
142 virtual void text(int x, int y, docstring const & str, Font const & f,
143 double wordspacing, double textwidth) = 0;
145 /** draw a string at position x, y (y is the baseline), but
146 * make sure that the part between \c from and \c to is in
147 * \c other color. The text direction is enforced by the \c Font.
149 virtual void text(int x, int y, docstring const & str, Font const & f,
150 Color other, size_type from, size_type to,
151 double wordspacing, double textwidth) = 0;
153 void setDrawingEnabled(bool drawing_enabled)
154 { drawing_enabled_ = drawing_enabled; }
156 /// Indicate wether real screen drawing shall be done or not.
157 bool isDrawingEnabled() const { return drawing_enabled_; }
159 double pixelRatio() const { return pixel_ratio_; }
161 /// draw the underbar, strikeout, xout, uuline and uwave font attributes
162 virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
165 * Draw a string and enclose it inside a rectangle. If
166 * back color is specified, the background is cleared with
167 * the given color. If frame is specified, a thin frame is drawn
168 * around the text with the given color.
170 virtual void rectText(int x, int baseline, docstring const & str,
171 FontInfo const & font, Color back, Color frame) = 0;
173 /// draw a string and enclose it inside a button frame
174 virtual void buttonText(int x, int baseline, docstring const & s,
175 FontInfo const & font, bool mouseHover) = 0;
177 /// draw a character of a preedit string for cjk support.
178 virtual int preeditText(int x, int y,
179 char_type c, FontInfo const & f, preedit_style style) = 0;
181 /// start monochrome painting mode, i.e. map every color into [min,max]
182 virtual void enterMonochromeMode(Color const & min,
183 Color const & max) = 0;
184 /// leave monochrome painting mode
185 virtual void leaveMonochromeMode() = 0;
186 /// draws a wavy line that can be used for underlining.
187 virtual void wavyHorizontalLine(int x, int y, int width, ColorCode col) = 0;
190 bool drawing_enabled_;
191 /// Ratio between physical pixels and device-independent pixels
195 } // namespace frontend