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.
This commit is contained in:
parent
849e2ded24
commit
cf2c215def
Notes:
sideshowbarker
2024-07-19 00:14:49 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/cf2c215defd Pull-request: https://github.com/SerenityOS/serenity/pull/4723
1 changed files with 4 additions and 2 deletions
|
@ -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()
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue