]> git.lyx.org Git - lyx.git/blob - src/PainterBase.C
cosmetics
[lyx.git] / src / PainterBase.C
1 /* This file is part of
2  * ======================================================
3  * 
4  *           LyX, The Document Processor
5  *       
6  *          Copyright 1998-2001 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 #include "font.h"
20
21 int PainterBase::dummy1 = 0;
22 int PainterBase::dummy2 = 0;
23 int PainterBase::dummy3 = 0;
24
25 int PainterBase::paperMargin() const
26 {
27         return 20;
28 }
29
30
31 int PainterBase::paperWidth() const
32 {
33         return owner.workWidth();
34 }
35
36
37 int PainterBase::paperHeight() const
38 {
39         return owner.height();
40 }
41
42
43 PainterBase & PainterBase::circle(int x, int y, unsigned int d,
44                                   LColor::color col)
45 {
46         return ellipse(x, y, d, d, col);
47 }
48
49
50 PainterBase & PainterBase::ellipse(int x, int y,
51                                    unsigned int w, unsigned int h,
52                                    LColor::color col)
53 {
54         return arc(x, y, w, h, 0, 0, col);
55 }
56
57
58 PainterBase & PainterBase::button(int x, int y, int w, int h)
59 {
60         fillRectangle(x, y, w, h, LColor::buttonbg);
61         buttonFrame(x, y, w, h);
62         return * this;
63 }
64
65
66 PainterBase & PainterBase::buttonFrame(int x, int y, int w, int h)
67 {
68         //  Width of a side of the button
69         int d = 2;
70
71         fillRectangle(x, y, w, d, LColor::top);
72         fillRectangle(x, (y+h-d), w, d, LColor::bottom);
73  
74         // Now a couple of trapezoids
75         int x1[4], y1[4];
76  
77         x1[0] = x+d;   y1[0] = y+d;
78         x1[1] = x+d;   y1[1] = (y+h-d);
79         x1[2] = x;     y1[2] = y+h;
80         x1[3] = x;     y1[3] = y;
81         fillPolygon(x1, y1, 4, LColor::left);
82
83         x1[0] = (x+w-d); y1[0] = y+d;
84         x1[1] = (x+w-d); y1[1] = (y+h-d);
85         x1[2] = x+w; y1[2] = (y+h-d);
86         x1[3] = x+w; y1[3] = y;
87         fillPolygon(x1, y1, 4, LColor::right);
88
89         return *this;
90 }
91
92
93 #if 0
94 PainterBase & PainterBase::rectText(int x, int baseline, 
95                                     string const & str, 
96                                     LyXFont const & font,
97                                     LColor::color back,
98                                     LColor::color frame, bool draw,
99                                     int & width, int & ascent, int & descent)
100 {
101 #if 0
102         static int const d = 2;
103         width = lyxfont::width(str, font) + d * 2 + 2;
104         ascent = lyxfont::maxAscent(font) + d;
105         descent = lyxfont::maxDescent(font) + d;
106 #else
107         lyxfont::rectText(str, font, width, axcent, descent);
108 #endif
109         if (!draw) return *this;
110
111         rectangle(x, baseline - ascent, width, ascent + descent, frame);
112         fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
113                       ascent + descent - 1, back);
114 #if 0
115         text(x + d, baseline, str, font);
116 #else
117         text(x + 2, baseline, str, font);
118 #endif
119         return *this;
120 }
121
122
123 PainterBase & PainterBase::buttonText(int x, int baseline,
124                                       string const & str, 
125                                       LyXFont const & font, bool draw,
126                                       int & width, int & ascent, int & descent)
127 {
128 #if 0
129         width = lyxfont::width(str, font) + 8;
130         ascent = lyxfont::maxAscent(font) + 3;
131         descent = lyxfont::maxDescent(font) + 3;
132 #else
133         lyxfont::buttonText(str, font, width, ascent, descent);
134 #endif
135         if (!draw) return *this;
136
137         button(x, baseline - ascent, width, descent + ascent);
138         text(x + 4, baseline, str, font);
139         return *this;
140 }
141 #else
142 PainterBase & PainterBase::rectText(int x, int baseline, 
143                                     string const & str, 
144                                     LyXFont const & font,
145                                     LColor::color back,
146                                     LColor::color frame)
147 {
148         int width;
149         int ascent;
150         int descent;
151         
152         lyxfont::rectText(str, font, width, ascent, descent);
153         rectangle(x, baseline - ascent, width, ascent + descent, frame);
154         fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
155                       ascent + descent - 1, back);
156         text(x + 3, baseline, str, font);
157         return *this;
158 }
159
160
161 PainterBase & PainterBase::buttonText(int x, int baseline,
162                                       string const & str, 
163                                       LyXFont const & font)
164 {
165         int width;
166         int ascent;
167         int descent;
168         
169         lyxfont::buttonText(str, font, width, ascent, descent);
170         button(x, baseline - ascent, width, descent + ascent);
171         text(x + 4, baseline, str, font);
172         return *this;
173 }
174 #endif