1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 02:27:43 +00:00

GameOfLife: Don't toggle cells on mouse move when placing patterns

Previously, it was very easy to inadvertently toggle cells when
placing a pattern by dragging the mouse slightly.
This commit is contained in:
Tim Ledbetter 2023-09-19 22:15:17 +01:00 committed by Andreas Kling
parent 6eaae726fa
commit 12adaac08d
3 changed files with 5 additions and 2 deletions

View file

@ -196,6 +196,7 @@ void BoardWidget::paint_event(GUI::PaintEvent& event)
void BoardWidget::mousedown_event(GUI::MouseEvent& event)
{
if (event.button() == GUI::MouseButton::Primary) {
m_dragging_enabled = (m_selected_pattern == nullptr);
set_toggling_cells(true);
auto row_and_column = get_row_and_column_for_point(event.x(), event.y());
if (!row_and_column.has_value())
@ -239,7 +240,7 @@ void BoardWidget::mousemove_event(GUI::MouseEvent& event)
if (!row_and_column.has_value())
return;
auto [row, column] = row_and_column.value();
if (m_toggling_cells) {
if (m_toggling_cells && m_dragging_enabled) {
if (m_last_cell_toggled.row != row || m_last_cell_toggled.column != column)
toggle_cell(row, column);
}
@ -253,6 +254,7 @@ void BoardWidget::mousemove_event(GUI::MouseEvent& event)
void BoardWidget::mouseup_event(GUI::MouseEvent&)
{
set_toggling_cells(false);
m_dragging_enabled = true;
}
Optional<Board::RowAndColumn> BoardWidget::get_row_and_column_for_point(int x, int y) const