]> git.lyx.org Git - lyx.git/blob - src/PainterBase.C
use anon namespace, somewhat better comp. handling of minipages, not quite there yet
[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 #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 PainterBase & PainterBase::rectText(int x, int baseline, 
94                                     string const & str, 
95                                     LyXFont const & font,
96                                     LColor::color back,
97                                     LColor::color frame, bool draw,
98                                     int & width, int & ascent, int & descent)
99 {
100         static int const d = 2;
101         width = lyxfont::width(str, font) + d * 2 + 2;
102         ascent = lyxfont::maxAscent(font) + d;
103         descent = lyxfont::maxDescent(font) + d;
104
105         if (!draw) return *this;
106
107         rectangle(x, baseline - ascent, width, ascent + descent, frame);
108         fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
109                       ascent + descent - 1, back);
110         text(x + d, baseline, str, font);
111         return *this;
112 }
113
114
115 PainterBase & PainterBase::buttonText(int x, int baseline,
116                                       string const & str, 
117                                       LyXFont const & font, bool draw,
118                                       int & width, int & ascent, int & descent)
119 {
120         width = lyxfont::width(str, font) + 8;
121         ascent = lyxfont::maxAscent(font) + 3;
122         descent = lyxfont::maxDescent(font) + 3;
123
124         if (!draw) return *this;
125
126         button(x, baseline - ascent, width, descent + ascent);
127         text(x + 4, baseline, str, font);
128         return *this;
129 }