]> git.lyx.org Git - lyx.git/blob - src/frontends/Painter.C
6fd9fd166f50083b322053f30263bb699305ecbd
[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 "lyxfont.h"
17 #include "WorkArea.h"
18
19 using std::max;
20
21
22 Painter & Painter::button(int x, int y, int w, int h)
23 {
24         fillRectangle(x, y, w, h, LColor::buttonbg);
25         buttonFrame(x, y, w, h);
26         return * this;
27 }
28
29
30 Painter & Painter::buttonFrame(int x, int y, int w, int h)
31 {
32         //  Width of a side of the button
33         int const d = 2;
34
35         fillRectangle(x, y, w, d, LColor::top);
36         fillRectangle(x, (y + h - d), w, d, LColor::bottom);
37
38         // Now a couple of trapezoids
39         int x1[4], y1[4];
40
41         x1[0] = x + d;   y1[0] = y + d;
42         x1[1] = x + d;   y1[1] = (y + h - d);
43         x1[2] = x;     y1[2] = y + h;
44         x1[3] = x;     y1[3] = y;
45         fillPolygon(x1, y1, 4, LColor::left);
46
47         x1[0] = (x + w - d); y1[0] = y + d;
48         x1[1] = (x + w - d); y1[1] = (y + h - d);
49         x1[2] = x + w; y1[2] = (y + h - d);
50         x1[3] = x + w; y1[3] = y;
51         fillPolygon(x1, y1, 4, LColor::right);
52
53         return *this;
54 }
55
56
57 Painter & 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         return *this;
80 }
81
82
83 Painter & Painter::buttonText(int x, int baseline,
84         string const & str,
85         LyXFont const & font)
86 {
87         int width;
88         int ascent;
89         int descent;
90
91         font_metrics::buttonText(str, font, width, ascent, descent);
92
93         button(x, baseline - ascent, width, descent + ascent);
94         text(x + 4, baseline, str, font);
95         return *this;
96 }
97
98
99 void Painter::underline(LyXFont const & f, int x, int y, int width)
100 {
101         int const below = max(font_metrics::maxDescent(f) / 2, 2);
102         int const height = max((font_metrics::maxDescent(f) / 4) - 1, 1);
103
104         if (height < 2) {
105                 line(x, y + below, x + width, y + below, f.color());
106         } else {
107                 fillRectangle(x, y + below, width, below + height,
108                               f.color());
109         }
110 }