]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
06544896d8161e2d1ee89f57fdc8e1386c556aec
[lyx.git] / src / frontends / Painter.C
1 /**
2  * \file Painter.C
3  * Read the file COPYING
4  *
5  * \author unknown
6  * \author John Levon 
7  *
8  * Full author contact details are available in file CREDITS
9  */
10
11 #include <config.h>
12
13 #ifdef __GNUG__
14 #pragma implementation
15 #endif
16
17 #include "Painter.h"
18 #include "lyxfont.h"
19 #include "WorkArea.h"
20 #include "frontends/font_metrics.h"
21  
22 using std::max;
23  
24 Painter & Painter::button(int x, int y, int w, int h)
25 {
26         fillRectangle(x, y, w, h, LColor::buttonbg);
27         buttonFrame(x, y, w, h);
28         return * this;
29 }
30
31
32 Painter & Painter::buttonFrame(int x, int y, int w, int h)
33 {
34         //  Width of a side of the button
35         int const d = 2;
36
37         fillRectangle(x, y, w, d, LColor::top);
38         fillRectangle(x, (y + h - d), w, d, LColor::bottom);
39  
40         // Now a couple of trapezoids
41         int x1[4], y1[4];
42  
43         x1[0] = x + d;   y1[0] = y + d;
44         x1[1] = x + d;   y1[1] = (y + h - d);
45         x1[2] = x;     y1[2] = y + h;
46         x1[3] = x;     y1[3] = y;
47         fillPolygon(x1, y1, 4, LColor::left);
48
49         x1[0] = (x + w - d); y1[0] = y + d;
50         x1[1] = (x + w - d); y1[1] = (y + h - d);
51         x1[2] = x + w; y1[2] = (y + h - d);
52         x1[3] = x + w; y1[3] = y;
53         fillPolygon(x1, y1, 4, LColor::right);
54
55         return *this;
56 }
57
58
59 Painter & Painter::rectText(int x, int baseline, 
60         string const & str, 
61         LyXFont const & font,
62         LColor::color back,
63         LColor::color frame)
64 {
65         int width;
66         int ascent;
67         int descent;
68
69         font_metrics::rectText(str, font, width, ascent, descent);
70  
71         if (frame != LColor::none) {
72                 rectangle(x, baseline - ascent, width, ascent + descent, frame);
73         }
74  
75         if (back != LColor::none) {
76                 fillRectangle(x + 1, baseline - ascent + 1, width - 1, 
77                               ascent + descent - 1, back);
78         }
79  
80         text(x + 3, baseline, str, font);
81         return *this;
82 }
83
84
85 Painter & Painter::buttonText(int x, int baseline,
86         string const & str, 
87         LyXFont const & font)
88 {
89         int width;
90         int ascent;
91         int descent;
92
93         font_metrics::buttonText(str, font, width, ascent, descent);
94  
95         button(x, baseline - ascent, width, descent + ascent);
96         text(x + 4, baseline, str, font);
97         return *this;
98 }
99
100
101 void Painter::underline(LyXFont const & f, int x, int y, int width)
102 {
103         int const below = max(font_metrics::maxDescent(f) / 2, 2);
104         int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
105  
106         if (height < 2) {
107                 line(x, y + below, x + width, y + below, f.color());
108         } else {
109                 fillRectangle(x, y + below, width, below + height,
110                               f.color());
111         }
112 }