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