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