Skip to content

Commit

Permalink
Chess+GamesSettings: Give chess pieces some breathing room
Browse files Browse the repository at this point in the history
Draw pieces around 80% of the size of a square, instead of 100%, so that
there is a nice gap around them. This feels more comfy, and makes it
actually possible to read the coordinates while a piece is on their
square.
  • Loading branch information
AtkinsSJ authored and awesomekling committed Feb 4, 2023
1 parent 7e4186d commit 0f2936d
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Userland/Applications/GamesSettings/ChessSettingsWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ class ChessGamePreview final : public GUI::Frame {
// With the same preview size as we use for card games, a nice fit is 2 ranks of 6.
// There are definitely better ways of doing this, but it'll do. ;^)
auto square_size = 61;
auto square_margin = square_size / 10;

auto rect_for_square = [&](Chess::Square const& square) {
return Gfx::IntRect {
Expand Down Expand Up @@ -196,7 +197,7 @@ class ChessGamePreview final : public GUI::Frame {
auto draw_piece = [&](Chess::Piece const& piece, Chess::Square const& square) {
auto& bitmap = *m_piece_images.get(piece).value();
painter.draw_scaled_bitmap(
rect_for_square(square),
rect_for_square(square).shrunken(square_margin, square_margin, square_margin, square_margin),
bitmap,
bitmap.rect(),
1.0f,
Expand Down
3 changes: 2 additions & 1 deletion Userland/Games/Chess/ChessWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)

auto square_width = min_size / 8;
auto square_height = min_size / 8;
auto square_margin = square_width / 10;
int coord_rank_file = (side() == Chess::Color::White) ? 0 : 7;

Chess::Board& active_board = (m_playback ? board_playback() : board());
Expand Down Expand Up @@ -84,7 +85,7 @@ void ChessWidget::paint_event(GUI::PaintEvent& event)
if (!(m_dragging_piece && sq == m_moving_square)) {
auto bmp = m_pieces.get(active_board.get_piece(sq));
if (bmp.has_value()) {
painter.draw_scaled_bitmap(tile_rect, *bmp.value(), bmp.value()->rect(), 1.0f, Gfx::Painter::ScalingMode::BilinearBlend);
painter.draw_scaled_bitmap(tile_rect.shrunken(square_margin, square_margin, square_margin, square_margin), *bmp.value(), bmp.value()->rect(), 1.0f, Gfx::Painter::ScalingMode::BilinearBlend);
}
}

Expand Down

0 comments on commit 0f2936d

Please sign in to comment.