making bold text in menus render correctly

This commit is contained in:
Thomas Baumhauer 2009-02-07 13:00:40 +00:00
parent 7d2cd05b8b
commit ff17bf1df3
3 changed files with 15 additions and 6 deletions

View File

@ -853,13 +853,19 @@ SDL_Rect line_size(const std::string& line, int font_size, int style)
return res;
}
std::string make_text_ellipsis(const std::string &text, int font_size, int max_width, bool with_tags)
std::string make_text_ellipsis(const std::string &text, int font_size,
int max_width, bool with_tags, bool parse_for_style)
{
static const std::string ellipsis = "...";
if(line_width(with_tags ? text : del_tags(text), font_size) <= max_width)
SDL_Color unused_color;
int unused_int;
int style = TTF_STYLE_NORMAL;
if(parse_for_style) parse_markup(text.begin(), text.end(), &unused_int, &unused_color, &style);
if(line_width(with_tags ? text : del_tags(text), font_size, style) <= max_width)
return text;
if(line_width(ellipsis, font_size) > max_width)
if(line_width(ellipsis, font_size, style) > max_width)
return "";
std::string current_substring;
@ -871,7 +877,7 @@ std::string make_text_ellipsis(const std::string &text, int font_size, int max_w
tmp.append(itor.substr().first, itor.substr().second);
tmp += ellipsis;
if (line_width(with_tags ? tmp : del_tags(tmp), font_size) > max_width) {
if (line_width(with_tags ? tmp : del_tags(tmp), font_size, style) > max_width) {
return current_substring + ellipsis;
}

View File

@ -112,8 +112,11 @@ SDL_Rect line_size(const std::string& line, int font_size, int style=TTF_STYLE_N
///
/// If the text excedes the specified max width, end it with an ellipsis (...)
/// The with_tags can probably always be set to false
/// If parse_for_style is true we look for the style of the text (bold, etc.)
/// before deleting its tags.
///
std::string make_text_ellipsis(const std::string& text, int font_size, int max_width, bool with_tags = true);
std::string make_text_ellipsis(const std::string& text, int font_size, int max_width,
bool with_tags = true, bool parse_for_style = false);
/// structure which will hide all current floating labels, and cause floating labels

View File

@ -913,7 +913,7 @@ void menu::draw_row(const size_t row_index, const SDL_Rect& rect, ROW_TYPE type)
const std::string to_show =
(use_ellipsis_ && !has_wrap) ?
font::make_text_ellipsis(str, style_->get_font_size(),
loc.w - (xpos - rect.x) - 2*style_->get_thickness(), false)
loc.w - (xpos - rect.x) - 2*style_->get_thickness(), false, true)
: str;
const SDL_Rect& text_size = font::text_area(str,style_->get_font_size());
const size_t y = rect.y + (rect.h - text_size.h)/2;