]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
enable Font cache only for MacOSX and inline width() for other platform.
[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 "LColor.h"
17
18 #include "support/docstring.h"
19
20
21 class LyXFont;
22
23 namespace lyx {
24 namespace graphics {
25         class Image;
26 }
27
28 namespace frontend {
29
30 /**
31  * Painter - A painter class to encapsulate all graphics parameters and operations
32  *
33  * Every graphics operation in LyX should be made by this class. The
34  * painter is used for drawing on the WorkArea, and is passed around
35  * during draw operations.
36  *
37  * It hides low level windows system parameters so insets and other
38  * clients don't have to worry about them and we can control graphics and
39  * GUI toolkit dependent drawing functions inside this single class.
40  *
41  * The intention for a toolkit is that it uses these methods to paint
42  * onto a backing pixmap. Only when expose events arrive via the event
43  * queue (perhaps generated via Screen::expose), does the copy onto
44  * the actual WorkArea widget take place. Paints are wrapped in (possibly
45  * recursive) calls to start() and end() to facilitate the backing pixmap
46  * management.
47  *
48  * Note that the methods return *this for convenience.
49  */
50 class Painter {
51 public:
52         /// possible line widths
53         enum line_width {
54                 line_thin, //< thin line
55                 line_thick //< thick line
56         };
57
58         /// possible line styles
59         enum line_style {
60                 line_solid, //< solid line
61                 line_onoffdash //< dashes with spaces
62         };
63
64         virtual ~Painter() {}
65
66         /// begin painting
67         virtual void start() {}
68
69         /// end painting
70         virtual void end() {}
71
72         /// return the width of the work area in pixels
73         virtual int paperWidth() const = 0;
74         /// return the height of the work area in pixels
75         virtual int paperHeight() const = 0;
76
77         /// draw a line from point to point
78         virtual void line(
79                 int x1, int y1,
80                 int x2, int y2,
81                 LColor_color,
82                 line_style = line_solid,
83                 line_width = line_thin) = 0;
84
85         /**
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
90          */
91         virtual void lines(
92                 int const * xp,
93                 int const * yp,
94                 int np,
95                 LColor_color,
96                 line_style = line_solid,
97                 line_width = line_thin) = 0;
98
99         /// draw a rectangle
100         virtual void rectangle(
101                 int x, int y,
102                 int w, int h,
103                 LColor_color,
104                 line_style = line_solid,
105                 line_width = line_thin) = 0;
106
107         /// draw a filled rectangle
108         virtual void fillRectangle(
109                 int x, int y,
110                 int w, int h,
111                 LColor_color) = 0;
112
113         /// draw an arc
114         virtual void arc(
115                 int x, int y,
116                 unsigned int w, unsigned int h,
117                 int a1, int a2,
118                 LColor_color) = 0;
119
120         /// draw a pixel
121         virtual void point(
122                 int x, int y,
123                 LColor_color) = 0;
124
125         /// draw a filled rectangle with the shape of a 3D button
126         virtual void button(int x, int y,
127                 int w, int h);
128
129         /// draw an image from the image cache
130         virtual void image(int x, int y,
131                 int w, int h,
132                 lyx::graphics::Image const & image) = 0;
133
134         /// draw a string at position x, y (y is the baseline)
135         virtual void text(int x, int y,
136                 lyx::docstring const & str, LyXFont const & f) = 0;
137
138         /**
139          * Draw a string at position x, y (y is the baseline)
140          * This is just for fast drawing
141          */
142         virtual void text(int x, int y,
143                 lyx::char_type const * str, size_t l,
144                 LyXFont const & f) = 0;
145
146         /// draw a char at position x, y (y is the baseline)
147         virtual void text(int x, int y,
148                           lyx::char_type c, LyXFont const & f) = 0;
149
150         /**
151          * Draw a string and enclose it inside a rectangle. If
152          * back color is specified, the background is cleared with
153          * the given color. If frame is specified, a thin frame is drawn
154          * around the text with the given color.
155          */
156         virtual void rectText(int x, int baseline,
157                 lyx::docstring const & str,
158                 LyXFont const & font,
159                 LColor_color back,
160                 LColor_color frame);
161
162         /// draw a string and enclose it inside a button frame
163         virtual void buttonText(int x,
164                 int baseline, lyx::docstring const & s,
165                 LyXFont const & font);
166
167 protected:
168         /// check the font, and if set, draw an underline
169         virtual void underline(LyXFont const & f,
170                 int x, int y, int width);
171
172         /// draw a bevelled button border
173         virtual void buttonFrame(int x, int y, int w, int h);
174 };
175
176 } // namespace frontend
177 } // namespace lyx
178
179 #endif // PAINTER_H