]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
Extracted from r14281
[lyx.git] / src / frontends / Painter.C
1 /**
2  * \file Painter.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author unknown
7  * \author John Levon
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "Painter.h"
15 #include "font_metrics.h"
16
17 #include "LColor.h"
18 #include "lyxfont.h"
19
20 using std::max;
21 using std::string;
22
23 namespace lyx {
24 namespace frontend {
25
26 void Painter::button(int x, int y, int w, int h)
27 {
28         fillRectangle(x, y, w, h, LColor::buttonbg);
29         buttonFrame(x, y, w, h);
30 }
31
32
33 void Painter::buttonFrame(int x, int y, int w, int h)
34 {
35         //  Width of a side of the button
36         int const d = 2;
37
38         fillRectangle(x, y, w, d, LColor::top);
39         fillRectangle(x, y + h - d, w, d, LColor::bottom);
40
41         for (int i = 0 ; i < d ; ++i) {
42                 line(x + i, y + i,
43                      x + i, y + h - 1 - i, LColor::left);
44                 line(x + w - 1 - i, y + i + 1,
45                      x + w - 1 - i, y + h - 1 - i, LColor::right);
46         }
47 }
48
49
50 void Painter::rectText(int x, int y,
51         string const & str,
52         LyXFont const & font,
53         LColor_color back,
54         LColor_color frame)
55 {
56         int width;
57         int ascent;
58         int descent;
59
60         font_metrics::rectText(str, font, width, ascent, descent);
61
62         if (back != LColor::none)
63                 fillRectangle(x + 1, y - ascent + 1, width - 1,
64                               ascent + descent - 1, back);
65
66         if (frame != LColor::none)
67                 rectangle(x, y - ascent, width, ascent + descent, frame);
68
69         text(x + 3, y, str, font);
70 }
71
72
73 void Painter::buttonText(int x, int y, string const & str, LyXFont const & font)
74 {
75         int width;
76         int ascent;
77         int descent;
78
79         font_metrics::buttonText(str, font, width, ascent, descent);
80
81         button(x, y - ascent, width, descent + ascent);
82         text(x + 4, y, str, font);
83 }
84
85
86 void Painter::underline(LyXFont const & f, int x, int y, int width)
87 {
88         int const below = max(font_metrics::maxDescent(f) / 2, 2);
89         int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
90
91         if (height < 2)
92                 line(x, y + below, x + width, y + below, f.color());
93         else
94                 fillRectangle(x, y + below, width, below + height, f.color());
95 }
96
97 } // namespace frontend
98 } // namespace lyx