From cf2c215defd448ca44523143827e3ba022f8dd71 Mon Sep 17 00:00:00 2001 From: Linus Groh Date: Fri, 1 Jan 2021 23:11:07 +0100 Subject: [PATCH] Conway: Distribute leftover space equally on all sides This draws the universe centered rather than just putting all leftover space on the right and bottom sides until the window is large enough to be completely filled with cells again. --- Games/Conway/Game.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Games/Conway/Game.cpp b/Games/Conway/Game.cpp index 66fc794bca..e35603bcbb 100644 --- a/Games/Conway/Game.cpp +++ b/Games/Conway/Game.cpp @@ -103,12 +103,14 @@ void Game::paint_event(GUI::PaintEvent& event) painter.fill_rect(event.rect(), m_dead_color); auto game_rect = rect(); auto cell_size = Gfx::IntSize(game_rect.width() / m_columns, game_rect.height() / m_rows); + auto x_margin = (game_rect.width() - (cell_size.width() * m_columns)) / 2; + auto y_margin = (game_rect.height() - (cell_size.height() * m_rows)) / 2; for (int y = 0; y < m_rows; y++) { for (int x = 0; x < m_columns; x++) { Gfx::IntRect rect { - x * cell_size.width(), - y * cell_size.height(), + x * cell_size.width() + x_margin, + y * cell_size.height() + y_margin, cell_size.width(), cell_size.height() };