mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 12:07:45 +00:00
GameOfLife: Don't enable rotate button if a pattern isn't selected
This commit is contained in:
parent
fac0bbe739
commit
1179d5d921
3 changed files with 11 additions and 2 deletions
|
@ -28,6 +28,8 @@ BoardWidget::BoardWidget(size_t rows, size_t columns)
|
||||||
|
|
||||||
on_pattern_selection = [this](auto* pattern) {
|
on_pattern_selection = [this](auto* pattern) {
|
||||||
m_selected_pattern = pattern;
|
m_selected_pattern = pattern;
|
||||||
|
if (on_pattern_selection_state_change)
|
||||||
|
on_pattern_selection_state_change();
|
||||||
};
|
};
|
||||||
|
|
||||||
setup_patterns();
|
setup_patterns();
|
||||||
|
@ -245,6 +247,8 @@ void BoardWidget::place_pattern(size_t row, size_t column)
|
||||||
y_offset++;
|
y_offset++;
|
||||||
}
|
}
|
||||||
m_selected_pattern = nullptr;
|
m_selected_pattern = nullptr;
|
||||||
|
if (on_pattern_selection_state_change)
|
||||||
|
on_pattern_selection_state_change();
|
||||||
if (m_pattern_preview_timer->is_active())
|
if (m_pattern_preview_timer->is_active())
|
||||||
m_pattern_preview_timer->stop();
|
m_pattern_preview_timer->stop();
|
||||||
}
|
}
|
||||||
|
|
|
@ -66,6 +66,7 @@ public:
|
||||||
|
|
||||||
Function<void()> on_running_state_change;
|
Function<void()> on_running_state_change;
|
||||||
Function<void()> on_stall;
|
Function<void()> on_stall;
|
||||||
|
Function<void()> on_pattern_selection_state_change;
|
||||||
Function<void(Board*, size_t row, size_t column)> on_cell_toggled;
|
Function<void(Board*, size_t row, size_t column)> on_cell_toggled;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -127,9 +127,9 @@ int main(int argc, char** argv)
|
||||||
main_toolbar.add_action(randomize_cells_action);
|
main_toolbar.add_action(randomize_cells_action);
|
||||||
|
|
||||||
auto rotate_pattern_action = GUI::Action::create("&Rotate pattern", { 0, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/redo.png"), [&](auto&) {
|
auto rotate_pattern_action = GUI::Action::create("&Rotate pattern", { 0, Key_R }, Gfx::Bitmap::try_load_from_file("/res/icons/16x16/redo.png"), [&](auto&) {
|
||||||
if (board_widget.selected_pattern() != nullptr)
|
|
||||||
board_widget.selected_pattern()->rotate_clockwise();
|
board_widget.selected_pattern()->rotate_clockwise();
|
||||||
});
|
});
|
||||||
|
rotate_pattern_action->set_enabled(false);
|
||||||
main_toolbar.add_action(rotate_pattern_action);
|
main_toolbar.add_action(rotate_pattern_action);
|
||||||
|
|
||||||
auto& game_menu = window->add_menu("&Game");
|
auto& game_menu = window->add_menu("&Game");
|
||||||
|
@ -180,6 +180,10 @@ int main(int argc, char** argv)
|
||||||
statusbar.set_text(click_tip);
|
statusbar.set_text(click_tip);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
board_widget.on_pattern_selection_state_change = [&] {
|
||||||
|
rotate_pattern_action->set_enabled(board_widget.selected_pattern() != nullptr);
|
||||||
|
};
|
||||||
|
|
||||||
window->resize(500, 420);
|
window->resize(500, 420);
|
||||||
window->show();
|
window->show();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue