diff options
author | frosch <frosch@openttd.org> | 2013-07-06 12:18:20 +0000 |
---|---|---|
committer | frosch <frosch@openttd.org> | 2013-07-06 12:18:20 +0000 |
commit | 290fbd2231a04b4ab56db86630161bb720bac62b (patch) | |
tree | 9ac39981f3795d9f276a95623780352c64788168 /src | |
parent | e3bb1d8c7380e14abdc95597d5df3e50d6247c5f (diff) | |
download | openttd-290fbd2231a04b4ab56db86630161bb720bac62b.tar.xz |
(svn r25564) -Add: a simple clipping rule to decide whether a string without linebreaks is visible before computing the layouting. This skips around 2/3 of layout computations in usual-sized list-like windows.
Diffstat (limited to 'src')
-rw-r--r-- | src/gfx.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/gfx.cpp b/src/gfx.cpp index 7584ff0db..2cb9d0ebf 100644 --- a/src/gfx.cpp +++ b/src/gfx.cpp @@ -521,9 +521,22 @@ static int DrawLayoutLine(ParagraphLayout::Line *line, int y, int left, int righ * will be drawn in the right direction. * @param underline Whether to underline what has been drawn or not. * @param fontsize The size of the initial characters. + * @return In case of left or center alignment the right most pixel we have drawn to. + * In case of right alignment the left most pixel we have drawn to. */ int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) { + /* The string may contain control chars to change the font, just use the biggest font for clipping. */ + int max_height = max(max(FONT_HEIGHT_SMALL, FONT_HEIGHT_NORMAL), max(FONT_HEIGHT_LARGE, FONT_HEIGHT_MONO)); + + /* Funny glyphs may extent outside the usual bounds, so relax the clipping somewhat. */ + int extra = max_height / 2; + + if (_cur_dpi->top + _cur_dpi->height + extra < top || _cur_dpi->top > top + max_height + extra || + _cur_dpi->left + _cur_dpi->width + extra < left || _cur_dpi->left > right + extra) { + return 0; + } + Layouter layout(str, INT32_MAX, colour, fontsize); if (layout.Length() == 0) return 0; @@ -543,6 +556,8 @@ int DrawString(int left, int right, int top, const char *str, TextColour colour, * will be drawn in the right direction. * @param underline Whether to underline what has been drawn or not. * @param fontsize The size of the initial characters. + * @return In case of left or center alignment the right most pixel we have drawn to. + * In case of right alignment the left most pixel we have drawn to. */ int DrawString(int left, int right, int top, StringID str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize) { |