]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
cleanup after svn hang-up, #undef CursorShape. Should be compilable ganin now.
[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 lyx::docstring;
21
22 using std::max;
23 using std::string;
24
25 namespace lyx {
26 namespace frontend {
27
28 void Painter::button(int x, int y, int w, int h)
29 {
30         fillRectangle(x, y, w, h, LColor::buttonbg);
31         buttonFrame(x, y, w, h);
32 }
33
34
35 void Painter::buttonFrame(int x, int y, int w, int h)
36 {
37         //  Width of a side of the button
38         int const d = 2;
39
40         fillRectangle(x, y, w, d, LColor::top);
41         fillRectangle(x, y + h - d, w, d, LColor::bottom);
42
43         for (int i = 0 ; i < d ; ++i) {
44                 line(x + i, y + i,
45                      x + i, y + h - 1 - i, LColor::left);
46                 line(x + w - 1 - i, y + i + 1,
47                      x + w - 1 - i, y + h - 1 - i, LColor::right);
48         }
49 }
50
51
52 void Painter::rectText(int x, int y,
53         docstring const & str,
54         LyXFont const & font,
55         LColor_color back,
56         LColor_color frame)
57 {
58         int width;
59         int ascent;
60         int descent;
61
62         font_metrics::rectText(str, font, width, ascent, descent);
63
64         if (back != LColor::none)
65                 fillRectangle(x + 1, y - ascent + 1, width - 1,
66                               ascent + descent - 1, back);
67
68         if (frame != LColor::none)
69                 rectangle(x, y - ascent, width, ascent + descent, frame);
70
71         text(x + 3, y, str, font);
72 }
73
74
75 void Painter::buttonText(int x, int y, docstring const & str, LyXFont const & font)
76 {
77         int width;
78         int ascent;
79         int descent;
80
81         font_metrics::buttonText(str, font, width, ascent, descent);
82
83         button(x, y - ascent, width, descent + ascent);
84         text(x + 4, y, str, font);
85 }
86
87
88 void Painter::underline(LyXFont const & f, int x, int y, int width)
89 {
90         int const below = max(font_metrics::maxDescent(f) / 2, 2);
91         int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
92
93         if (height < 2)
94                 line(x, y + below, x + width, y + below, f.color());
95         else
96                 fillRectangle(x, y + below, width, below + height, f.color());
97 }
98
99 } // namespace frontend
100 } // namespace lyx