]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
Remove special code for Qt5 to manage HiDPI. It's not needed anymore and leads to...
[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 (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
44  * management.
45  *
46  * Note that the methods return *this for convenience.
47  *
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.
54  */
55 class Painter {
56 public:
57         Painter(double pixel_ratio) : drawing_enabled_(true), pixel_ratio_(pixel_ratio) {}
58
59         static const int thin_line;
60
61         /// possible line styles
62         enum line_style {
63                 line_solid, //< solid line
64                 line_onoffdash //< dashes with spaces
65         };
66
67         /// possible fill styles
68         enum fill_style {
69                 fill_none,
70                 fill_oddeven,
71                 fill_winding
72         };
73
74         /// possible character styles of preedit string.
75         /// This is used for CJK input method support.
76         enum preedit_style {
77                 preedit_default, //< when unselecting, no cursor and dashed underline.
78                 preedit_selecting, //< when selecting.
79                 preedit_cursor //< with cursor.
80         };
81
82         virtual ~Painter() {}
83
84         /// draw a line from point to point
85         virtual void line(int x1, int y1, int x2, int y2, Color,
86                 line_style = line_solid, int line_width = thin_line) = 0;
87
88         /**
89          * lines -  draw a set of lines
90          * @param xp array of points' x co-ords
91          * @param yp array of points' y co-ords
92          * @param np size of the points array
93          */
94         virtual void lines(int const * xp, int const * yp, int np, Color,
95                 fill_style = fill_none, line_style = line_solid,
96                 int line_width = thin_line) = 0;
97
98         /**
99          * path -  draw a path with bezier curves
100          * @param xp array of points' x co-ords
101          * @param yp array of points' y co-ords
102          * @param c1x array of first control points' x co-ords
103          * @param c1y array of first control points' y co-ords
104          * @param c2x array of second control points' x co-ords
105          * @param c2y array of second control points' y co-ords
106          * @param np size of the points array
107          */
108         virtual void path(int const * xp, int const * yp,
109                 int const * c1x, int const * c1y,
110                 int const * c2x, int const * c2y,
111                 int np, Color,
112                 fill_style = fill_none, line_style = line_solid,
113                 int line_width = thin_line) = 0;
114
115         /// draw a rectangle
116         virtual void rectangle(int x, int y, int w, int h, Color,
117                 line_style = line_solid, int line_width = thin_line) = 0;
118
119         /// draw a filled rectangle
120         virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
121
122         /// draw an arc
123         virtual void arc(int x, int y, unsigned int w, unsigned int h,
124                 int a1, int a2, Color) = 0;
125
126         /// draw a pixel
127         virtual void point(int x, int y, Color) = 0;
128
129         /// draw a filled rectangle with the shape of a 3D button
130         virtual void button(int x, int y, int w, int h, bool mouseHover) = 0;
131
132         /// draw an image from the image cache
133         virtual void image(int x, int y, int w, int h,
134                 graphics::Image const & image) = 0;
135
136         /** draw a string at position x, y (y is the baseline). The
137          * text direction is given by \c rtl.
138          * \return the width of the drawn text.
139          */
140         virtual int text(int x, int y, docstring const & str, FontInfo const & f,
141                      bool rtl = false, double wordspacing = 0.0) = 0;
142
143         /** draw a string at position x, y (y is the baseline). The
144          * text direction is enforced by the \c Font.
145          * \return the width of the drawn text.
146          */
147         virtual int text(int x, int y, docstring const & str, Font const & f,
148                      double wordspacing = 0.0) = 0;
149
150         /** draw a string at position x, y (y is the baseline), but
151          * make sure that the part between \c from and \c to is in
152          * \c other color. The text direction is enforced by the \c Font.
153          * \return the width of the drawn text.
154          */
155         virtual int text(int x, int y, docstring const & str, Font const & f,
156                      Color other, size_type from, size_type to,
157                      double const wordspacing) = 0;
158
159         void setDrawingEnabled(bool drawing_enabled)
160         { drawing_enabled_ = drawing_enabled; }
161
162         /// Indicate wether real screen drawing shall be done or not.
163         bool isDrawingEnabled() const { return drawing_enabled_; }
164
165         double pixelRatio() const { return pixel_ratio_; }
166
167         /// draw a char at position x, y (y is the baseline)
168         /**
169         * \return the width of the drawn text.
170         */
171         virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
172
173         /// draw the underbar, strikeout, uuline and uwave font attributes
174         virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
175
176         /**
177          * Draw a string and enclose it inside a rectangle. If
178          * back color is specified, the background is cleared with
179          * the given color. If frame is specified, a thin frame is drawn
180          * around the text with the given color.
181          */
182         virtual void rectText(int x, int baseline, docstring const & str,
183                 FontInfo const & font, Color back, Color frame) = 0;
184
185         /// draw a string and enclose it inside a button frame
186         virtual void buttonText(int x, int baseline, docstring const & s,
187                 FontInfo const & font, bool mouseHover) = 0;
188
189         /// draw a character of a preedit string for cjk support.
190         virtual int preeditText(int x, int y,
191                 char_type c, FontInfo const & f, preedit_style style) = 0;
192
193         /// start monochrome painting mode, i.e. map every color into [min,max]
194         virtual void enterMonochromeMode(Color const & min, 
195                 Color const & max) = 0;
196         /// leave monochrome painting mode
197         virtual void leaveMonochromeMode() = 0;
198         /// draws a wavy line that can be used for underlining.
199         virtual void wavyHorizontalLine(int x, int y, int width, ColorCode col) = 0;
200 private:
201         ///
202         bool drawing_enabled_;
203         /// Ratio between physical pixels and device-independent pixels
204         double pixel_ratio_;
205 };
206
207 } // namespace frontend
208 } // namespace lyx
209
210 #endif // PAINTER_H