mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-30 22:54:35 +03: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:
parent
6eaae726fa
commit
12adaac08d
Notes:
sideshowbarker
2024-07-17 03:27:40 +09:00
Author: https://github.com/tcl3 Commit: https://github.com/SerenityOS/serenity/commit/12adaac08d Pull-request: https://github.com/SerenityOS/serenity/pull/21163
@ -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
|
||||
|
@ -84,6 +84,7 @@ private:
|
||||
NonnullOwnPtr<Board> m_board;
|
||||
|
||||
bool m_running { false };
|
||||
bool m_dragging_enabled { true };
|
||||
|
||||
int m_running_timer_interval { 500 };
|
||||
int m_running_pattern_preview_timer_interval { 100 };
|
||||
|
@ -71,7 +71,7 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
||||
statusbar.segment(1).set_fixed_width(ceil(width));
|
||||
|
||||
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);
|
||||
};
|
||||
show_statusbar_hint();
|
||||
|
Loading…
Reference in New Issue
Block a user