1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:47:45 +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) void BoardWidget::mousedown_event(GUI::MouseEvent& event)
{ {
if (event.button() == GUI::MouseButton::Primary) { if (event.button() == GUI::MouseButton::Primary) {
m_dragging_enabled = (m_selected_pattern == nullptr);
set_toggling_cells(true); set_toggling_cells(true);
auto row_and_column = get_row_and_column_for_point(event.x(), event.y()); auto row_and_column = get_row_and_column_for_point(event.x(), event.y());
if (!row_and_column.has_value()) if (!row_and_column.has_value())
@ -239,7 +240,7 @@ void BoardWidget::mousemove_event(GUI::MouseEvent& event)
if (!row_and_column.has_value()) if (!row_and_column.has_value())
return; return;
auto [row, column] = row_and_column.value(); 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) if (m_last_cell_toggled.row != row || m_last_cell_toggled.column != column)
toggle_cell(row, column); toggle_cell(row, column);
} }
@ -253,6 +254,7 @@ void BoardWidget::mousemove_event(GUI::MouseEvent& event)
void BoardWidget::mouseup_event(GUI::MouseEvent&) void BoardWidget::mouseup_event(GUI::MouseEvent&)
{ {
set_toggling_cells(false); set_toggling_cells(false);
m_dragging_enabled = true;
} }
Optional<Board::RowAndColumn> BoardWidget::get_row_and_column_for_point(int x, int y) const Optional<Board::RowAndColumn> BoardWidget::get_row_and_column_for_point(int x, int y) const

View file

@ -84,6 +84,7 @@ private:
NonnullOwnPtr<Board> m_board; NonnullOwnPtr<Board> m_board;
bool m_running { false }; bool m_running { false };
bool m_dragging_enabled { true };
int m_running_timer_interval { 500 }; int m_running_timer_interval { 500 };
int m_running_pattern_preview_timer_interval { 100 }; int m_running_pattern_preview_timer_interval { 100 };

View file

@ -71,7 +71,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
statusbar.segment(1).set_fixed_width(ceil(width)); statusbar.segment(1).set_fixed_width(ceil(width));
auto show_statusbar_hint = [&]() { auto show_statusbar_hint = [&]() {
auto tip = board_widget->selected_pattern() ? pattern_place_tip : toggle_cells_tip; auto tip = board_widget.selected_pattern() ? pattern_place_tip : toggle_cells_tip;
statusbar.segment(0).set_text(tip); statusbar.segment(0).set_text(tip);
}; };
show_statusbar_hint(); show_statusbar_hint();