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