3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
14 #include "frontends/Painter.h"
16 #include "frontends/FontMetrics.h"
28 void Painter::button(int x, int y, int w, int h, bool mouseHover)
31 fillRectangle(x, y, w, h, Color_buttonhoverbg);
33 fillRectangle(x, y, w, h, Color_buttonbg);
34 buttonFrame(x, y, w, h);
38 void Painter::buttonFrame(int x, int y, int w, int h)
40 line(x, y, x, y + h - 1, Color_buttonframe);
41 line(x - 1 + w, y, x - 1 + w, y + h - 1, Color_buttonframe);
42 line(x, y - 1, x - 1 + w, y - 1, Color_buttonframe);
43 line(x, y + h - 1, x - 1 + w, y + h - 1, Color_buttonframe);
47 void Painter::rectText(int x, int y,
48 docstring const & str,
57 FontMetrics const & fm = theFontMetrics(font);
58 fm.rectText(str, width, ascent, descent);
60 if (back != Color_none)
61 fillRectangle(x + 1, y - ascent + 1, width - 1,
62 ascent + descent - 1, back);
64 if (frame != Color_none)
65 rectangle(x, y - ascent, width, ascent + descent, frame);
67 text(x + 3, y, str, font);
71 void Painter::buttonText(int x, int y, docstring const & str,
72 Font const & font, bool mouseHover)
78 FontMetrics const & fm = theFontMetrics(font);
79 fm.buttonText(str, width, ascent, descent);
81 button(x + 1, y - ascent, width - 2, descent + ascent, mouseHover);
82 text(x + 4, y - 1, str, font);
86 int Painter::preeditText(int x, int y, char_type c,
87 Font const & font, preedit_style style)
89 Font temp_font = font;
90 FontMetrics const & fm = theFontMetrics(font);
91 int ascent = fm.maxAscent();
92 int descent = fm.maxDescent();
93 int height = ascent + descent;
94 int width = fm.width(c);
98 // default unselecting mode.
99 fillRectangle(x, y - height + 1, width, height, Color_background);
100 dashedUnderline(font, x, y - descent + 1, width);
102 case preedit_selecting:
103 // We are in selecting mode: white text on black background.
104 fillRectangle(x, y - height + 1, width, height, Color_black);
105 temp_font.setColor(Color_white);
108 // The character comes with a cursor.
109 fillRectangle(x, y - height + 1, width, height, Color_background);
110 underline(font, x, y - descent + 1, width);
113 text(x, y - descent + 1, c, temp_font);
119 void Painter::underline(Font const & f, int x, int y, int width)
121 FontMetrics const & fm = theFontMetrics(f);
123 int const below = max(fm.maxDescent() / 2, 2);
124 int const height = max((fm.maxDescent() / 4) - 1, 1);
127 line(x, y + below, x + width, y + below, f.color());
129 fillRectangle(x, y + below, width, below + height, f.color());
133 void Painter::dashedUnderline(Font const & f, int x, int y, int width)
135 FontMetrics const & fm = theFontMetrics(f);
137 int const below = max(fm.maxDescent() / 2, 2);
138 int height = max((fm.maxDescent() / 4) - 1, 1);
143 for (int n = 0; n < height; ++n)
144 line(x, y + below + n, x + width, y + below + n, f.color(), line_onoffdash);
147 } // namespace frontend