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