]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
096e4abfd6fcad34aa8b6235e3a2cb4fb103957b
[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 #include "WorkArea.h"
17
18 #include "LColor.h"
19 #include "lyxfont.h"
20
21 using std::max;
22 using std::string;
23
24
25 void Painter::button(int x, int y, int w, int h)
26 {
27         fillRectangle(x, y, w, h, LColor::buttonbg);
28         buttonFrame(x, y, w, h);
29 }
30
31
32 void 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         for (int i = 0 ; i < d ; ++i) {
41                 line(x + i, y + i, 
42                      x + i, y + h - 1 - i, LColor::left);
43                 line(x + w - 1 - i, y + i + 1, 
44                      x + w - 1 - i, y + h - 1 - i, LColor::right);
45         }
46 }
47
48
49 void Painter::rectText(int x, int y,
50         string const & str,
51         LyXFont const & font,
52         LColor_color back,
53         LColor_color frame)
54 {
55         int width;
56         int ascent;
57         int descent;
58
59         font_metrics::rectText(str, font, width, ascent, descent);
60
61         if (back != LColor::none)
62                 fillRectangle(x + 1, y - ascent + 1, width - 1,
63                               ascent + descent - 1, back);
64
65         if (frame != LColor::none)
66                 rectangle(x, y - ascent, width, ascent + descent, frame);
67
68         text(x + 3, y, str, font);
69 }
70
71
72 void Painter::buttonText(int x, int y, string const & str, LyXFont const & font)
73 {
74         int width;
75         int ascent;
76         int descent;
77
78         font_metrics::buttonText(str, font, width, ascent, descent);
79
80         button(x, y - ascent, width, descent + ascent);
81         text(x + 4, y, str, font);
82 }
83
84
85 void Painter::underline(LyXFont const & f, int x, int y, int width)
86 {
87         int const below = max(font_metrics::maxDescent(f) / 2, 2);
88         int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
89
90         if (height < 2)
91                 line(x, y + below, x + width, y + below, f.color());
92         else
93                 fillRectangle(x, y + below, width, below + height, f.color());
94 }