]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
* src/frontends/qt4/GuiSelection.C
[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, bool mouseHover)
30 {
31         if (mouseHover)
32                 fillRectangle(x, y, w, h, LColor::buttonhoverbg);
33         else
34                 fillRectangle(x, y, w, h, LColor::buttonbg);
35         buttonFrame(x, y, w, h);
36 }
37
38
39 void Painter::buttonFrame(int x, int y, int w, int h)
40 {
41         line(x, y, x, y + h - 1, LColor::buttonframe);
42         line(x - 1 + w, y, x - 1 + w, y + h - 1, LColor::buttonframe);
43         line(x, y - 1, x - 1 + w, y - 1, LColor::buttonframe);
44         line(x, y + h - 1, x - 1 + w, y + h - 1, LColor::buttonframe);
45 }
46
47
48 void Painter::rectText(int x, int y,
49         docstring const & str,
50         LyXFont const & font,
51         LColor_color back,
52         LColor_color frame)
53 {
54         int width;
55         int ascent;
56         int descent;
57
58         FontMetrics const & fm = theFontMetrics(font);
59         fm.rectText(str, 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, docstring const & str, 
73         LyXFont const & font, bool mouseHover)
74 {
75         int width;
76         int ascent;
77         int descent;
78
79         FontMetrics const & fm = theFontMetrics(font);
80         fm.buttonText(str, width, ascent, descent);
81
82         button(x, y - ascent, width, descent + ascent, mouseHover);
83         text(x + 3, y - 1, str, font);
84 }
85
86
87 void Painter::underline(LyXFont const & f, int x, int y, int width)
88 {
89         FontMetrics const & fm = theFontMetrics(f);
90
91         int const below = max(fm.maxDescent() / 2, 2);
92         int const height = max((fm.maxDescent() / 4) - 1, 1);
93
94         if (height < 2)
95                 line(x, y + below, x + width, y + below, f.color());
96         else
97                 fillRectangle(x, y + below, width, below + height, f.color());
98 }
99
100 } // namespace frontend
101 } // namespace lyx