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"
29 void Painter::button(int x, int y, int w, int h, bool mouseHover)
32 fillRectangle(x, y, w, h, Color::buttonhoverbg);
34 fillRectangle(x, y, w, h, Color::buttonbg);
35 buttonFrame(x, y, w, h);
39 void Painter::buttonFrame(int x, int y, int w, int h)
41 line(x, y, x, y + h - 1, Color::buttonframe);
42 line(x - 1 + w, y, x - 1 + w, y + h - 1, Color::buttonframe);
43 line(x, y - 1, x - 1 + w, y - 1, Color::buttonframe);
44 line(x, y + h - 1, x - 1 + w, y + h - 1, Color::buttonframe);
48 void Painter::rectText(int x, int y,
49 docstring const & str,
58 FontMetrics const & fm = theFontMetrics(font);
59 fm.rectText(str, width, ascent, descent);
61 if (back != Color::none)
62 fillRectangle(x + 1, y - ascent + 1, width - 1,
63 ascent + descent - 1, back);
65 if (frame != Color::none)
66 rectangle(x, y - ascent, width, ascent + descent, frame);
68 text(x + 3, y, str, font);
72 void Painter::buttonText(int x, int y, docstring const & str,
73 Font const & font, bool mouseHover)
79 FontMetrics const & fm = theFontMetrics(font);
80 fm.buttonText(str, width, ascent, descent);
82 button(x, y - ascent, width, descent + ascent, mouseHover);
83 text(x + 3, y - 1, str, font);
87 int Painter::preeditText(int x, int y, char_type c,
88 Font const & font, preedit_style style)
90 Font temp_font = font;
91 FontMetrics const & fm = theFontMetrics(font);
92 int ascent = fm.maxAscent();
93 int descent = fm.maxDescent();
94 int height = ascent + descent;
95 int width = fm.width(c);
99 // default unselecting mode.
100 fillRectangle(x, y - height + 1, width, height, Color::background);
101 dashedUnderline(font, x, y - descent + 1, width);
103 case preedit_selecting:
104 // We are in selecting mode: white text on black background.
105 fillRectangle(x, y - height + 1, width, height, Color::black);
106 temp_font.setColor(Color::white);
109 // The character comes with a cursor.
110 fillRectangle(x, y - height + 1, width, height, Color::background);
111 underline(font, x, y - descent + 1, width);
114 text(x, y - descent + 1, c, temp_font);
120 void Painter::underline(Font const & f, int x, int y, int width)
122 FontMetrics const & fm = theFontMetrics(f);
124 int const below = max(fm.maxDescent() / 2, 2);
125 int const height = max((fm.maxDescent() / 4) - 1, 1);
128 line(x, y + below, x + width, y + below, f.color());
130 fillRectangle(x, y + below, width, below + height, f.color());
134 void Painter::dashedUnderline(Font const & f, int x, int y, int width)
136 FontMetrics const & fm = theFontMetrics(f);
138 int const below = max(fm.maxDescent() / 2, 2);
139 int height = max((fm.maxDescent() / 4) - 1, 1);
144 for (int n = 0; n < height; ++n)
145 line(x, y + below + n, x + width, y + below + n, f.color(), line_onoffdash);
148 } // namespace frontend