]> git.lyx.org Git - lyx.git/blob - src/Painter.h
06468b33ba26acfe2ec452f3dd919663e96b611c
[lyx.git] / src / Painter.h
1 // -*- C++ -*-
2 /* This file is part of
3  * ======================================================
4  * 
5  *           LyX, The Document Processor
6  *       
7  *          Copyright 1995-2000 The LyX Team
8  *
9  * ======================================================*/
10
11 #ifndef PAINTER_H
12 #define PAINTER_H
13
14 #ifdef __GNUG__
15 #pragma interface
16 #endif
17
18 #include "config.h"
19 #include "LString.h"
20
21 // This is only included to provide stuff for the non-public sections
22 #include <X11/Xlib.h>
23
24 #include <map>
25 #include "PainterBase.h"
26 #include "LColor.h"
27
28 class LyXFont;
29 class WorkArea;
30
31 /** An inplementation for the X Window System. Xlib.
32     
33     Classes similar to this one can be made for gtk+, Qt, etc.
34 */
35 class Painter : public PainterBase {
36 public:
37         /// Constructor 
38         explicit Painter(WorkArea &);
39         
40         /// Destructor
41         ~Painter();
42         
43         /**@Basic drawing routines */
44         /// Draw a line from point to point
45         PainterBase & line(int x1, int y1, int x2, int y2, 
46                            LColor::color = LColor::foreground,
47                            enum line_style = line_solid,
48                            enum line_width = line_thin);
49         
50         /// Here xp and yp are arrays of points
51         PainterBase & lines(int const * xp, int const * yp, int np,
52                             LColor::color = LColor::foreground,
53                             enum line_style = line_solid,
54                             enum line_width = line_thin);
55         
56         /// Here xp and yp are arrays of points
57         PainterBase & fillPolygon(int const * xp, int const * yp, int np,
58                                   LColor::color = LColor::foreground);
59         
60         /// Draw lines from x1,y1 to x2,y2. They are arrays
61         PainterBase & segments(int const * x1, int const * y1, 
62                                int const * x2, int const * y2, int ns,
63                                LColor::color = LColor::foreground,
64                                enum line_style = line_solid,
65                                enum line_width = line_thin);
66         
67         /// Draw a rectangle 
68         PainterBase & rectangle(int x, int y, int w, int h,
69                                 LColor::color = LColor::foreground,
70                                 enum line_style = line_solid,
71                                 enum line_width = line_thin);
72         
73         /// Draw an arc
74         PainterBase & arc(int x, int y, unsigned int w, unsigned int h, 
75                           int a1, int a2,
76                           LColor::color = LColor::foreground);
77         
78         /// Draw a pixel
79         PainterBase & point(int x, int y, LColor::color = LColor::foreground);
80         
81         /// Fill a rectangle
82         PainterBase & fillRectangle(int x, int y, int w, int h,
83                                     LColor::color = LColor::background);
84         
85         /**@Image stuff */
86         
87         /// For the figure inset
88         PainterBase & pixmap(int x, int y, int w, int h, Pixmap bitmap);
89         
90         /**@String functions */
91         
92         /// Draw a string at position x, y (y is the baseline)
93         PainterBase & text(int x, int y,
94                            string const & str, LyXFont const & f);
95         
96         /** Draw a string at position x, y (y is the baseline)
97             This is just for fast drawing */
98         PainterBase & text(int x, int y, char const * str, int l,
99                            LyXFont const & f);
100         
101         /// Draw a char at position x, y (y is the baseline)
102         PainterBase & text(int x, int y, char c, LyXFont const & f);
103         
104 protected:
105         /**@Support for X only, by now */
106         friend class WorkArea;
107         ///
108         PainterBase & setDisplay(Display * d) { display = d; return *this; }
109         
110         /// Get foreground color in ordinary GC
111         GC getGCForeground(LColor::color c);
112         
113         /// Set up GC according to line style
114         GC getGCLinepars(enum line_style, enum line_width, LColor::color c);
115         
116         /// Check the font, and if set, draw an underline
117         void underline(LyXFont const & f, int x, int y, int width);
118         
119         /**@Low level X parameters */
120         ///
121         Display * display;
122
123         ///
124         Drawable drawable() const;
125                 
126         ///
127         Colormap colormap;
128         
129         /// Caching of ordinary color GCs
130         GC colorGCcache[LColor::ignore + 1];
131         /// Caching of GCs used for lines
132         typedef std::map<int, GC> LineGCCache;
133         ///
134         LineGCCache lineGCcache;
135 };
136 #endif