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