]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
323cc0e715f7a7a3a8426a240df1eb6c4701e5e3
[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         // Now a couple of trapezoids
41         int x1[4], y1[4];
42
43         x1[0] = x + d;   y1[0] = y + d;
44         x1[1] = x + d;   y1[1] = (y + h - d);
45         x1[2] = x;     y1[2] = y + h;
46         x1[3] = x;     y1[3] = y;
47         fillPolygon(x1, y1, 4, LColor::left);
48
49         x1[0] = (x + w - d); y1[0] = y + d;
50         x1[1] = (x + w - d); y1[1] = (y + h - d);
51         x1[2] = x + w; y1[2] = (y + h - d);
52         x1[3] = x + w; y1[3] = y;
53         fillPolygon(x1, y1, 4, LColor::right);
54 }
55
56
57 void Painter::rectText(int x, int baseline,
58         string const & str,
59         LyXFont const & font,
60         LColor_color back,
61         LColor_color frame)
62 {
63         int width;
64         int ascent;
65         int descent;
66
67         font_metrics::rectText(str, font, width, ascent, descent);
68
69         if (back != LColor::none) {
70                 fillRectangle(x + 1, baseline - ascent + 1, width - 1,
71                               ascent + descent - 1, back);
72         }
73
74         if (frame != LColor::none) {
75                 rectangle(x, baseline - ascent, width, ascent + descent, frame);
76         }
77
78         text(x + 3, baseline, str, font);
79 }
80
81
82 void Painter::buttonText(int x, int baseline,
83         string const & str,
84         LyXFont const & font)
85 {
86         int width;
87         int ascent;
88         int descent;
89
90         font_metrics::buttonText(str, font, width, ascent, descent);
91
92         button(x, baseline - ascent, width, descent + ascent);
93         text(x + 4, baseline, str, font);
94 }
95
96
97 void Painter::underline(LyXFont const & f, int x, int y, int width)
98 {
99         int const below = max(font_metrics::maxDescent(f) / 2, 2);
100         int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
101
102         if (height < 2) {
103                 line(x, y + below, x + width, y + below, f.color());
104         } else {
105                 fillRectangle(x, y + below, width, below + height,
106                               f.color());
107         }
108 }