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