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