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