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"
15 #include "frontends/FontMetrics.h"
23 static int max(int a, int b) { return a > b ? a : b; }
26 void Painter::button(int x, int y, int w, int h, bool mouseHover)
29 fillRectangle(x, y, w, h, Color_buttonhoverbg);
31 fillRectangle(x, y, w, h, Color_buttonbg);
32 buttonFrame(x, y, w, h);
36 void Painter::buttonFrame(int x, int y, int w, int h)
38 line(x, y, x, y + h - 1, Color_buttonframe);
39 line(x - 1 + w, y, x - 1 + w, y + h - 1, Color_buttonframe);
40 line(x, y - 1, x - 1 + w, y - 1, Color_buttonframe);
41 line(x, y + h - 1, x - 1 + w, y + h - 1, Color_buttonframe);
45 void Painter::rectText(int x, int y,
46 docstring const & str,
47 FontInfo const & font,
55 FontMetrics const & fm = theFontMetrics(font);
56 fm.rectText(str, width, ascent, descent);
58 if (back != Color_none)
59 fillRectangle(x + 1, y - ascent + 1, width - 1,
60 ascent + descent - 1, back);
62 if (frame != Color_none)
63 rectangle(x, y - ascent, width, ascent + descent, frame);
65 text(x + 3, y, str, font);
69 void Painter::buttonText(int x, int y, docstring const & str,
70 FontInfo const & font, bool mouseHover)
76 FontMetrics const & fm = theFontMetrics(font);
77 fm.buttonText(str, width, ascent, descent);
79 button(x + 1, y - ascent, width - 2, descent + ascent, mouseHover);
80 text(x + 4, y - 1, str, font);
84 int Painter::preeditText(int x, int y, char_type c,
85 FontInfo const & font, preedit_style style)
87 FontInfo temp_font = font;
88 FontMetrics const & fm = theFontMetrics(font);
89 int ascent = fm.maxAscent();
90 int descent = fm.maxDescent();
91 int height = ascent + descent;
92 int width = fm.width(c);
96 // default unselecting mode.
97 fillRectangle(x, y - height + 1, width, height, Color_background);
98 dashedUnderline(font, x, y - descent + 1, width);
100 case preedit_selecting:
101 // We are in selecting mode: white text on black background.
102 fillRectangle(x, y - height + 1, width, height, Color_black);
103 temp_font.setColor(Color_white);
106 // The character comes with a cursor.
107 fillRectangle(x, y - height + 1, width, height, Color_background);
108 underline(font, x, y - descent + 1, width);
111 text(x, y - descent + 1, c, temp_font);
117 void Painter::underline(FontInfo const & f, int x, int y, int width)
119 FontMetrics const & fm = theFontMetrics(f);
121 int const below = max(fm.maxDescent() / 2, 2);
122 int const height = max((fm.maxDescent() / 4) - 1, 1);
125 line(x, y + below, x + width, y + below, f.color());
127 fillRectangle(x, y + below, width, below + height, f.color());
131 void Painter::dashedUnderline(FontInfo const & f, int x, int y, int width)
133 FontMetrics const & fm = theFontMetrics(f);
135 int const below = max(fm.maxDescent() / 2, 2);
136 int height = max((fm.maxDescent() / 4) - 1, 1);
141 for (int n = 0; n < height; ++n)
142 line(x, y + below + n, x + width, y + below + n, f.color(), line_onoffdash);
145 } // namespace frontend