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.
18 #include "support/strfwd.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_medium, //< medium line
62 line_thick //< thick line
65 /// possible line styles
67 line_solid, //< solid line
68 line_onoffdash //< dashes with spaces
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, line_width = line_thin) = 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 line_style = line_solid, line_width = line_thin) = 0;
95 virtual void rectangle(int x, int y, int w, int h, Color,
96 line_style = line_solid, line_width = line_thin) = 0;
98 /// draw a filled rectangle
99 virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
102 virtual void arc(int x, int y, unsigned int w, unsigned int h,
103 int a1, int a2, Color) = 0;
106 virtual void point(int x, int y, Color) = 0;
108 /// draw a filled rectangle with the shape of a 3D button
109 virtual void button(int x, int y, int w, int h, bool mouseHover) = 0;
111 /// draw an image from the image cache
112 virtual void image(int x, int y, int w, int h,
113 graphics::Image const & image) = 0;
115 /// draw a string at position x, y (y is the baseline)
117 * \return the width of the drawn text.
119 virtual int text(int x, int y, docstring const & str, FontInfo const & f) = 0;
121 void setDrawingEnabled(bool drawing_enabled)
122 { drawing_enabled_ = drawing_enabled; }
124 /// Indicate wether real screen drawing shall be done or not.
125 bool isDrawingEnabled() const { return drawing_enabled_; }
127 /// draw a char at position x, y (y is the baseline)
129 * \return the width of the drawn text.
131 virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
134 * Draw a string and enclose it inside a rectangle. If
135 * back color is specified, the background is cleared with
136 * the given color. If frame is specified, a thin frame is drawn
137 * around the text with the given color.
139 virtual void rectText(int x, int baseline, docstring const & str,
140 FontInfo const & font, Color back, Color frame) = 0;
142 /// draw a string and enclose it inside a button frame
143 virtual void buttonText(int x, int baseline, docstring const & s,
144 FontInfo const & font, bool mouseHover) = 0;
146 /// draw a character of a preedit string for cjk support.
147 virtual int preeditText(int x, int y,
148 char_type c, FontInfo const & f, preedit_style style) = 0;
150 /// start monochrome painting mode, i.e. map every color into [min,max]
151 virtual void enterMonochromeMode(Color const & min,
152 Color const & max) = 0;
153 /// leave monochrome painting mode
154 virtual void leaveMonochromeMode() = 0;
155 /// draws a wavy line that can be used for underlining.
156 virtual void wavyHorizontalLine(int x, int y, int width, ColorCode col) = 0;
159 bool drawing_enabled_;
162 } // namespace frontend