Skip to content

Commit

Permalink
font/sdl_ttf_compat: Drop redundant font::pango_draw_text() API
Browse files Browse the repository at this point in the history
It's literally font::pango_line_size() with fixed big extents and only
used once.
  • Loading branch information
irydacea committed Mar 16, 2021
1 parent e3b737c commit 9fbe48d
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 15 deletions.
6 changes: 0 additions & 6 deletions src/font/sdl_ttf_compat.cpp
Expand Up @@ -176,10 +176,4 @@ SDL_Rect pango_draw_text(surface& dst, const SDL_Rect& area, int size, const col
return res;
}

SDL_Rect pango_text_area(const std::string& text, int size, pango_text::FONT_STYLE style)
{
const SDL_Rect area {0,0,10000,10000};
return pango_draw_text(nullptr, area, size, font::NORMAL_COLOR, text, 0, 0, false, style);
}

} // end namespace font
5 changes: 0 additions & 5 deletions src/font/sdl_ttf_compat.hpp
Expand Up @@ -82,9 +82,4 @@ SDL_Rect pango_draw_text(surface& dst, const SDL_Rect& area, int size, const col
*/
SDL_Rect pango_draw_text(CVideo* gui, const SDL_Rect& area, int size, const color_t& color, const std::string& text, int x, int y, bool use_tooltips = false, pango_text::FONT_STYLE style = pango_text::STYLE_NORMAL);

/**
* Calculate the size of a text (in pixels) if it were to be drawn.
*/
SDL_Rect pango_text_area(const std::string& text, int size, pango_text::FONT_STYLE style = pango_text::STYLE_NORMAL);

} // end namespace font
8 changes: 4 additions & 4 deletions src/widgets/menu.cpp
Expand Up @@ -918,12 +918,12 @@ void menu::draw_row(const std::size_t row_index, const SDL_Rect& rect, ROW_TYPE
} else {
column.x = xpos;

const SDL_Rect& text_size = font::pango_text_area(str,style_->get_font_size());
const std::size_t y = rect.y + (rect.h - text_size.h)/2;
const auto text_size = font::pango_line_size(str, style_->get_font_size());
const std::size_t y = rect.y + (rect.h - text_size.second)/2;
const std::size_t padding = 2;
SDL_Rect text_rect = column;
text_rect.w = rect.w - (xpos - rect.x) - 2 * style_->get_thickness();
text_rect.h = text_size.h;
text_rect.h = text_size.second;
font::pango_draw_text(&video(), text_rect, style_->get_font_size(), font::NORMAL_COLOR, str,
(type == HEADING_ROW ? xpos+padding : xpos), y);

Expand All @@ -937,7 +937,7 @@ void menu::draw_row(const std::size_t row_index, const SDL_Rect& rect, ROW_TYPE
}
}

xpos += dir * (text_size.w + 5);
xpos += dir * (text_size.first + 5);
}
}
if(lang_rtl)
Expand Down

0 comments on commit 9fbe48d

Please sign in to comment.