]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
PrefLanguageUi.ui: change a string
[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
18 namespace lyx {
19
20 class FontInfo;
21
22 namespace graphics { class Image; }
23
24 namespace frontend {
25
26 /**
27  * Painter - A painter class to encapsulate all graphics parameters and operations
28  *
29  * Every graphics operation in LyX should be made by this class. The
30  * painter is used for drawing on the WorkArea, and is passed around
31  * during draw operations.
32  *
33  * It hides low level windows system parameters so insets and other
34  * clients don't have to worry about them and we can control graphics and
35  * GUI toolkit dependent drawing functions inside this single class.
36  *
37  * The intention for a toolkit is that it uses these methods to paint
38  * onto a backing pixmap. Only when expose events arrive via the event
39  * queue (perhaps generated via Screen::expose), does the copy onto
40  * the actual WorkArea widget take place. Paints are wrapped in (possibly
41  * recursive) calls to start() and end() to facilitate the backing pixmap
42  * management.
43  *
44  * Note that the methods return *this for convenience.
45  *
46  * Caution: All char_type and docstring arguments of the text drawing
47  * methods of this class are no UCS4 chars or strings if the font is a
48  * symbol font. They simply denote the code points of the font instead.
49  * You have to keep this in mind when you implement the methods in a
50  * frontend. You must not pass these parameters to a unicode conversion
51  * function in particular.
52  */
53 class Painter {
54 public:
55         Painter() : drawing_enabled_(true) {}
56
57         float line_width;
58         static const float thin_line;
59
60         /// possible line styles
61         enum line_style {
62                 line_solid, //< solid line
63                 line_onoffdash //< dashes with spaces
64         };
65
66         /// possible character styles of preedit string.
67         /// This is used for CJK input method support.
68         enum preedit_style {
69                 preedit_default, //< when unselecting, no cursor and dashed underline.
70                 preedit_selecting, //< when selecting.
71                 preedit_cursor //< with cursor.
72         };
73
74         virtual ~Painter() {}
75
76         /// draw a line from point to point
77         virtual void line(int x1, int y1, int x2, int y2, Color,
78                 line_style = line_solid, float line_width = thin_line) = 0;
79
80         /**
81          * lines -  draw a set of lines
82          * @param xp array of points' x co-ords
83          * @param yp array of points' y co-ords
84          * @param np size of the points array
85          */
86         virtual void lines(int const * xp, int const * yp, int np, Color,
87                 line_style = line_solid, float line_width = thin_line) = 0;
88
89         /// draw a rectangle
90         virtual void rectangle(int x, int y, int w, int h, Color,
91                 line_style = line_solid, float line_width = thin_line) = 0;
92
93         /// draw a filled rectangle
94         virtual void fillRectangle(int x, int y, int w, int h, Color) = 0;
95
96         /// draw an arc
97         virtual void arc(int x, int y, unsigned int w, unsigned int h,
98                 int a1, int a2, Color) = 0;
99
100         /// draw a pixel
101         virtual void point(int x, int y, Color) = 0;
102
103         /// draw a filled rectangle with the shape of a 3D button
104         virtual void button(int x, int y, int w, int h, bool mouseHover) = 0;
105
106         /// draw an image from the image cache
107         virtual void image(int x, int y, int w, int h,
108                 graphics::Image const & image) = 0;
109
110         /// draw a string at position x, y (y is the baseline)
111         /**
112         * \return the width of the drawn text.
113         */
114         virtual int text(int x, int y, docstring const & str, FontInfo const & f) = 0;
115
116         void setDrawingEnabled(bool drawing_enabled)
117         { drawing_enabled_ = drawing_enabled; }
118
119         /// Indicate wether real screen drawing shall be done or not.
120         bool isDrawingEnabled() const { return drawing_enabled_; }
121
122         /// draw a char at position x, y (y is the baseline)
123         /**
124         * \return the width of the drawn text.
125         */
126         virtual int text(int x, int y, char_type c, FontInfo const & f) = 0;
127
128         /// draw the underbar, strikeout, uuline and uwave font attributes
129         virtual void textDecoration(FontInfo const & f, int x, int y, int width) = 0;
130
131         /**
132          * Draw a string and enclose it inside a rectangle. If
133          * back color is specified, the background is cleared with
134          * the given color. If frame is specified, a thin frame is drawn
135          * around the text with the given color.
136          */
137         virtual void rectText(int x, int baseline, docstring const & str,
138                 FontInfo const & font, Color back, Color frame) = 0;
139
140         /// draw a string and enclose it inside a button frame
141         virtual void buttonText(int x, int baseline, docstring const & s,
142                 FontInfo const & font, bool mouseHover) = 0;
143
144         /// draw a character of a preedit string for cjk support.
145         virtual int preeditText(int x, int y,
146                 char_type c, FontInfo const & f, preedit_style style) = 0;
147
148         /// start monochrome painting mode, i.e. map every color into [min,max]
149         virtual void enterMonochromeMode(Color const & min, 
150                 Color const & max) = 0;
151         /// leave monochrome painting mode
152         virtual void leaveMonochromeMode() = 0;
153         /// draws a wavy line that can be used for underlining.
154         virtual void wavyHorizontalLine(int x, int y, int width, ColorCode col) = 0;
155 private:
156         ///
157         bool drawing_enabled_;
158 };
159
160 } // namespace frontend
161 } // namespace lyx
162
163 #endif // PAINTER_H