mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 13:37:45 +00:00
LibChess: Add and use Square::{file,rank}_char() methods
This saves us having to build and allocate a String, just to then use one character of it.
This commit is contained in:
parent
c73c697f94
commit
5f6dd87163
4 changed files with 35 additions and 13 deletions
|
@ -66,16 +66,20 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
|
|||
}
|
||||
|
||||
if (m_coordinates) {
|
||||
auto coord = sq.to_algebraic();
|
||||
auto text_color = (sq.is_light()) ? board_theme().dark_square_color : board_theme().light_square_color;
|
||||
|
||||
auto shrunken_rect = tile_rect;
|
||||
shrunken_rect.shrink(4, 4);
|
||||
if (sq.rank == coord_rank_file)
|
||||
painter.draw_text(shrunken_rect, coord.substring_view(0, 1), coordinate_font, Gfx::TextAlignment::BottomRight, text_color);
|
||||
|
||||
if (sq.file == coord_rank_file)
|
||||
painter.draw_text(shrunken_rect, coord.substring_view(1, 1), coordinate_font, Gfx::TextAlignment::TopLeft, text_color);
|
||||
if (sq.rank == coord_rank_file) {
|
||||
auto file_char = sq.file_char();
|
||||
painter.draw_text(shrunken_rect, { &file_char, 1 }, coordinate_font, Gfx::TextAlignment::BottomRight, text_color);
|
||||
}
|
||||
|
||||
if (sq.file == coord_rank_file) {
|
||||
auto rank_char = sq.rank_char();
|
||||
painter.draw_text(shrunken_rect, { &rank_char, 1 }, coordinate_font, Gfx::TextAlignment::TopLeft, text_color);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& m : m_board_markings) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue