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