mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 11:57:35 +00:00
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
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);
|
painter.fill_rect(event.rect(), m_dead_color);
|
||||||
auto game_rect = rect();
|
auto game_rect = rect();
|
||||||
auto cell_size = Gfx::IntSize(game_rect.width() / m_columns, game_rect.height() / m_rows);
|
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 y = 0; y < m_rows; y++) {
|
||||||
for (int x = 0; x < m_columns; x++) {
|
for (int x = 0; x < m_columns; x++) {
|
||||||
Gfx::IntRect rect {
|
Gfx::IntRect rect {
|
||||||
x * cell_size.width(),
|
x * cell_size.width() + x_margin,
|
||||||
y * cell_size.height(),
|
y * cell_size.height() + y_margin,
|
||||||
cell_size.width(),
|
cell_size.width(),
|
||||||
cell_size.height()
|
cell_size.height()
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue