]> git.lyx.org Git - lyx.git/blob - src/Painter.h
a26baebfc82bf588e288b0e4f366b04e4e5882ec
[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 #define USE_PAINTER 1
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,
98                            string const & str, LyXFont const & f);
99         
100         /** Draw a string at position x, y (y is the baseline)
101             This is just for fast drawing */
102         PainterBase & text(int x, int y, char const * str, int l,
103                            LyXFont const & f);
104         
105         /// Draw a char at position x, y (y is the baseline)
106         PainterBase & text(int x, int y, char c, LyXFont const & f);
107         
108 protected:
109         /**@Support for X only, by now */
110         friend class WorkArea;
111         ///
112         PainterBase & setDisplay(Display * d) { display = d; return *this; }
113         
114         ///
115         PainterBase & setDrawable(Drawable d) { drawable = d; return *this; }
116         
117         /// Get foreground color in ordinary GC
118         GC getGCForeground(LColor::color c);
119         
120         /// Set up GC according to line style
121         GC getGCLinepars(enum line_style, enum line_width, LColor::color c);
122         
123         /// Check the font, and if set, draw an underline
124         void underline(LyXFont const & f, int x, int y, int width);
125         
126         /**@Low level X parameters */
127         ///
128         Display * display;
129         ///
130         Drawable drawable;
131         ///
132         Colormap colormap;
133         
134         /// Caching of ordinary color GCs
135         GC colorGCcache[LColor::ignore + 1];
136         /// Caching of GCs used for lines
137         typedef map<int, GC, less<int> > LineGCCache;
138         ///
139         LineGCCache lineGCcache;
140 };
141 #endif