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