]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
Remove obsolete (and false) comment.
[lyx.git] / src / frontends / Painter.h
1 // -*- C++ -*-
2 /**
3  * \file Painter.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author unknown
8  * \author John Levon
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef PAINTER_H
14 #define PAINTER_H
15
16 #include "support/strfwd.h"
17 #include "support/types.h"
18
19 namespace lyx {
20
21 class Font;
22 class FontInfo;
23
24 namespace graphics { class Image; }
25
26 namespace frontend {
27
28 /**
29  * Painter - A painter class to encapsulate all graphics parameters and operations
30  *
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.
34  *
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.
38  *
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.
42  *
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.
49  */
50 class Painter {
51 public:
52         Painter(double pixel_ratio, bool devel_mode)
53                 : pixel_ratio_(pixel_ratio), devel_mode_(devel_mode) {}
54
55         static const int thin_line;
56
57         /// possible line styles
58         enum line_style {
59                 line_solid, //< solid line
60                 line_solid_aliased, //< solid line, no anti-aliasing (used as a
61                                     // workaround to painting issues)
62                 line_onoffdash //< dashes with spaces
63         };
64
65         /// possible fill styles
66         enum fill_style {
67                 fill_none,
68                 fill_oddeven,
69                 fill_winding
70         };
71
72         /// possible character styles of preedit string.
73         /// This is used for CJK input method support.
74         enum preedit_style {
75                 preedit_default, //< when unselecting, no cursor and dashed underline.
76                 preedit_selecting, //< when selecting.
77                 preedit_cursor //< with cursor.
78         };
79
80         virtual ~Painter() {}
81
82         /// draw a line from point to point
83         virtual void line(int x1, int y1, int x2, int y2, Color,
84                 line_style = line_solid, int line_width = thin_line) = 0;
85
86         /**
87          * lines -  draw a set of lines
88          * @param xp array of points' x co-ords
89          * @param yp array of points' y co-ords
90          * @param np size of the points array
91          */
92         virtual void lines(int const * xp, int const * yp, int np, Color,
93                 fill_style = fill_none, line_style = line_solid,
94                 int line_width = thin_line) = 0;
95
96         /**
97          * path -  draw a path with bezier curves
98          * @param xp array of points' x co-ords
99          * @param yp array of points' y co-ords
100          * @param c1x array of first control points' x co-ords
101          * @param c1y array of first control points' y co-ords
102          * @param c2x array of second control points' x co-ords
103          * @param c2y array of second control points' y co-ords
104          * @param np size of the points array
105          */
106         virtual void path(int const * xp, int const * yp,
107                 int const * c1x, int const * c1y,
108                 int const * c2x, int const * c2y,
109                 int np, Color,
110                 fill_style = fill_none, line_style = line_solid,
111                 int line_width = thin_line) = 0;
112
113         /// draw a rectangle
114         virtual void rectangle(int x, int y, int w, int h, Color,
115                 line_style = line_solid, int line_width = thin_line) = 0;
116
117         /// draw a filled rectangle
118         virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
119
120         /// draw an arc
121         virtual void arc(int x, int y, unsigned int w, unsigned int h,
122                 int a1, int a2, Color) = 0;
123
124         /// draw a pixel
125         virtual void point(int x, int y, Color) = 0;
126
127         /// draw an image from the image cache
128         virtual void image(int x, int y, int w, int h,
129                 graphics::Image const & image) = 0;
130
131         /// draw a string at position x, y (y is the baseline).
132         virtual void text(int x, int y, docstring const & str, FontInfo const & f) = 0;
133
134         /// draw a char at position x, y (y is the baseline)
135         virtual void text(int x, int y, char_type c, FontInfo const & f) = 0;
136
137         /** draw a string at position x, y (y is the baseline). The
138          * text direction is enforced by the \c Font.
139          */
140         virtual void text(int x, int y, docstring const & str, Font const & f,
141                       double wordspacing, double textwidth) = 0;
142
143         /** draw a string at position x, y (y is the baseline), but
144          * make sure that the part between \c from and \c to is in
145          * \c other color. The text direction is enforced by the \c Font.
146          */
147         virtual void text(int x, int y, docstring const & str, Font const & f,
148                           Color other, size_type from, size_type to,
149                       double wordspacing, double textwidth) = 0;
150
151         // Returns true if the painter does not actually paint.
152         virtual bool isNull() const = 0;
153
154         double pixelRatio() const { return pixel_ratio_; }
155
156         double develMode() const { return devel_mode_; }
157
158         /// draw the underbar, strikeout, xout, uuline and uwave font attributes
159         virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
160
161         /**
162          * Draw a string and enclose it inside a rectangle. If
163          * back color is specified, the background is cleared with
164          * the given color. If frame is specified, a thin frame is drawn
165          * around the text with the given color.
166          */
167         virtual void rectText(int x, int baseline, docstring const & str,
168                 FontInfo const & font, Color back, Color frame) = 0;
169
170         /// draw a string and enclose it inside a button frame
171         virtual void buttonText(int x, int baseline, docstring const & s,
172                 FontInfo const & font, Color back, Color frame, int offset) = 0;
173
174         /// draw a character of a preedit string for cjk support.
175         virtual int preeditText(int x, int y,
176                 char_type c, FontInfo const & f, preedit_style style) = 0;
177
178         /// start monochrome painting mode, i.e. map every color into [min,max]
179         virtual void enterMonochromeMode(Color const & min,
180                 Color const & max) = 0;
181         /// leave monochrome painting mode
182         virtual void leaveMonochromeMode() = 0;
183         /// draws a wavy line that can be used for underlining.
184         virtual void wavyHorizontalLine(int x, int y, int width, ColorCode col) = 0;
185 private:
186         /// Ratio between physical pixels and device-independent pixels
187         double pixel_ratio_;
188         /// True when developer more is on at application-level.
189         bool devel_mode_;
190 };
191
192 } // namespace frontend
193 } // namespace lyx
194
195 #endif // PAINTER_H