]> git.lyx.org Git - lyx.git/blob - src/PainterBase.C
e5c1c52d258dd4eab6005495078f938026bb45c7
[lyx.git] / src / PainterBase.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1998-2000 The LyX Team
7  *
8  *======================================================*/
9
10 #include <config.h>
11
12 #ifdef __GNUG__
13 #pragma implementation
14 #endif
15
16 #include "PainterBase.h"
17 #include "lyxfont.h"
18 #include "WorkArea.h"
19
20
21 int PainterBase::dummy1 = 0;
22 int PainterBase::dummy2 = 0;
23 int PainterBase::dummy3 = 0;
24
25 int PainterBase::paperMargin()
26 {
27         return 20;
28 }
29
30
31 int PainterBase::paperWidth()
32 {
33         return owner.workWidth();
34 }
35
36
37 int PainterBase::width(string const & s, LyXFont const & f)
38 {
39         return f.stringWidth(s);
40 }
41
42
43 int PainterBase::width(char const * s, int l, LyXFont const & f)
44 {
45         return f.textWidth(s, l);
46 }
47
48
49 int PainterBase::width(char c, LyXFont const & f)
50 {
51         return f.width(c);
52 }
53
54
55 PainterBase & PainterBase::circle(int x, int y, unsigned int d,
56                                   LColor::color col)
57 {
58         return ellipse(x, y, d, d, col);
59 }
60
61
62 PainterBase & PainterBase::ellipse(int x, int y,
63                                    unsigned int w, unsigned int h,
64                                    LColor::color col)
65 {
66         return arc(x, y, w, h, 0, 0, col);
67 }
68
69
70 PainterBase & PainterBase::button(int x, int y, int w, int h)
71 {
72         fillRectangle(x, y, w, h, LColor::buttonbg);
73         buttonFrame(x, y, w, h);
74         return * this;
75 }
76
77
78 PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h)
79 {
80         //  Width of a side of the button
81         int d = 2;
82
83         fillRectangle(x, y, w, d, LColor::top);
84         fillRectangle(x, (y+h-d), w, d, LColor::bottom);
85  
86         // Now a couple of trapezoids
87         int x1[4], y1[4];
88  
89         x1[0] = x+d;   y1[0] = y+d;
90         x1[1] = x+d;   y1[1] = (y+h-d);
91         x1[2] = x;     y1[2] = y+h;
92         x1[3] = x;     y1[3] = y;
93         fillPolygon(x1, y1, 4, LColor::left);
94
95         x1[0] = (x+w-d); y1[0] = y+d;
96         x1[1] = (x+w-d); y1[1] = (y+h-d);
97         x1[2] = x+w; y1[2] = (y+h-d);
98         x1[3] = x+w; y1[3] = y;
99         fillPolygon(x1, y1, 4, LColor::right);
100
101         return *this;
102 }
103
104
105 PainterBase & PainterBase::rectText(int x, int baseline, 
106                                     string const & str, 
107                                     LyXFont const & font,
108                                     LColor::color back,
109                                     LColor::color frame, bool draw,
110                                     int & width, int & ascent, int & descent)
111 {
112         static int const d = 2;
113         width = this->width(str, font) + d * 2 + 2;
114         ascent = font.maxAscent() + d;
115         descent = font.maxDescent() + d;
116
117         if (!draw) return *this;
118
119         rectangle(x, baseline - ascent, width, ascent + descent, frame);
120         fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
121                       ascent + descent - 1, back);
122         text(x + d, baseline, str, font);
123         return *this;
124 }
125
126
127 PainterBase & PainterBase::buttonText(int x, int baseline,
128                                       string const & str, 
129                                       LyXFont const & font, bool draw,
130                                       int & width, int & ascent, int & descent)
131 {
132         width = this->width(str, font) + 8;
133         ascent = font.maxAscent() + 3;
134         descent = font.maxDescent() + 3;
135
136         if (!draw) return *this;
137
138         button(x, baseline - ascent, width, descent + ascent);
139         text(x + 4, baseline, str, font);
140         return *this;
141 }