]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.h
namespace grfx -> lyx::graphics
[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
17 #include "LString.h"
18 #include "LColor.h"
19
20 class LyXFont;
21
22 namespace lyx {
23 namespace graphics {
24         class Image;
25 }
26 }
27
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 Painter & line(
78                 int x1, int y1,
79                 int x2, int y2,
80                 LColor::color = LColor::foreground,
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 Painter & lines(
91                 int const * xp,
92                 int const * yp,
93                 int np,
94                 LColor::color = LColor::foreground,
95                 line_style = line_solid,
96                 line_width = line_thin) = 0;
97
98         /// draw a rectangle
99         virtual Painter & rectangle(
100                 int x, int y,
101                 int w, int h,
102                 LColor::color = LColor::foreground,
103                 line_style = line_solid,
104                 line_width = line_thin) = 0;
105
106         /// draw a filled rectangle
107         virtual Painter & fillRectangle(
108                 int x, int y,
109                 int w, int h,
110                 LColor::color) = 0;
111
112         /// draw a filled (irregular) polygon
113         virtual Painter & fillPolygon(
114                 int const * xp,
115                 int const * yp,
116                 int np,
117                 LColor::color = LColor::foreground) = 0;
118
119         /// draw an arc
120         virtual Painter & arc(
121                 int x, int y,
122                 unsigned int w, unsigned int h,
123                 int a1, int a2,
124                 LColor::color = LColor::foreground) = 0;
125
126         /// draw a pixel
127         virtual Painter & point(
128                 int x, int y,
129                 LColor::color = LColor::foreground) = 0;
130
131         /// draw a filled rectangle with the shape of a 3D button
132         virtual Painter & button(int x, int y,
133                 int w, int h);
134
135         /// draw an image from the image cache
136         virtual Painter & image(int x, int y,
137                 int w, int h,
138                 lyx::graphics::Image const & image) = 0;
139
140         /// draw a string at position x, y (y is the baseline)
141         virtual Painter & text(int x, int y,
142                 string const & str, LyXFont const & f) = 0;
143
144         /**
145          * Draw a string at position x, y (y is the baseline)
146          * This is just for fast drawing
147          */
148         virtual Painter & text(int x, int y,
149                 char const * str, size_t l,
150                 LyXFont const & f) = 0;
151
152         /// draw a char at position x, y (y is the baseline)
153         virtual Painter & text(int x, int y,
154                 char c, LyXFont const & f) = 0;
155
156         /**
157          * Draw a string and enclose it inside a rectangle. If
158          * back color is specified, the background is cleared with
159          * the given color. If frame is specified, a thin frame is drawn
160          * around the text with the given color.
161          */
162         Painter & rectText(int x, int baseline,
163                 string const & string,
164                 LyXFont const & font,
165                 LColor::color back = LColor::none,
166                 LColor::color frame = LColor::none);
167
168         /// draw a string and enclose it inside a button frame
169         Painter & buttonText(int x,
170                 int baseline, string const & s,
171                 LyXFont const & font);
172
173 protected:
174         /// check the font, and if set, draw an underline
175         void underline(LyXFont const & f,
176                 int x, int y, int width);
177
178         /// draw a bevelled button border
179         Painter & buttonFrame(int x, int y, int w, int h);
180 };
181
182 #endif // PAINTER_H