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