]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
3bf36843d603641771e0301c99351062b1102e40
[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 an arc
116         virtual void arc(
117                 int x, int y,
118                 unsigned int w, unsigned int h,
119                 int a1, int a2,
120                 LColor_color) = 0;
121
122         /// draw a pixel
123         virtual void point(
124                 int x, int y,
125                 LColor_color) = 0;
126
127         /// draw a filled rectangle with the shape of a 3D button
128         virtual void button(int x, int y,
129                 int w, int h);
130
131         /// draw an image from the image cache
132         virtual void image(int x, int y,
133                 int w, int h,
134                 lyx::graphics::Image const & image) = 0;
135
136         /// draw a string at position x, y (y is the baseline)
137         virtual void text(int x, int y,
138                 std::string const & str, LyXFont const & f) = 0;
139
140         /**
141          * Draw a string at position x, y (y is the baseline)
142          * This is just for fast drawing
143          */
144         virtual void text(int x, int y,
145                 char const * str, size_t l,
146                 LyXFont const & f) = 0;
147
148         /// draw a char at position x, y (y is the baseline)
149         virtual void text(int x, int y,
150                           lyx::char_type c, LyXFont const & f) = 0;
151
152         /**
153          * Draw a string and enclose it inside a rectangle. If
154          * back color is specified, the background is cleared with
155          * the given color. If frame is specified, a thin frame is drawn
156          * around the text with the given color.
157          */
158         virtual void rectText(int x, int baseline,
159                 std::string const & str,
160                 LyXFont const & font,
161                 LColor_color back,
162                 LColor_color frame);
163
164         /// draw a string and enclose it inside a button frame
165         virtual void buttonText(int x,
166                 int baseline, std::string const & s,
167                 LyXFont const & font);
168
169 protected:
170         /// check the font, and if set, draw an underline
171         virtual void underline(LyXFont const & f,
172                 int x, int y, int width);
173
174         /// draw a bevelled button border
175         virtual void buttonFrame(int x, int y, int w, int h);
176 };
177
178 } // namespace frontend
179 } // namespace lyx
180
181 #endif // PAINTER_H