mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 06:37:44 +00:00
LibGUI: Convert custom widgets and subclasses to ObjectPtr
This commit is contained in:
parent
15a66dc8ab
commit
defafd72bc
30 changed files with 57 additions and 47 deletions
|
@ -32,9 +32,9 @@ public:
|
|||
};
|
||||
|
||||
class Field final : public GFrame {
|
||||
C_OBJECT(Field)
|
||||
friend class Square;
|
||||
friend class SquareLabel;
|
||||
|
||||
public:
|
||||
Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent, Function<void(Size)> on_size_changed);
|
||||
virtual ~Field() override;
|
||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char** argv)
|
|||
auto time_icon_label = GLabel::construct(container);
|
||||
time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png"));
|
||||
auto time_label = GLabel::construct(container);
|
||||
auto* field = new Field(*flag_label, *time_label, *face_button, widget, [&](Size size) {
|
||||
auto field = Field::construct(*flag_label, *time_label, *face_button, widget, [&](Size size) {
|
||||
size.set_height(size.height() + container->preferred_size().height());
|
||||
window->resize(size);
|
||||
});
|
||||
|
@ -48,7 +48,7 @@ int main(int argc, char** argv)
|
|||
|
||||
auto app_menu = make<GMenu>("Minesweeper");
|
||||
|
||||
app_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [field](const GAction&) {
|
||||
app_menu->add_action(GAction::create("New game", { Mod_None, Key_F2 }, [&](const GAction&) {
|
||||
field->reset();
|
||||
}));
|
||||
|
||||
|
@ -74,16 +74,16 @@ int main(int argc, char** argv)
|
|||
menubar->add_menu(move(app_menu));
|
||||
|
||||
auto difficulty_menu = make<GMenu>("Difficulty");
|
||||
difficulty_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [field](const GAction&) {
|
||||
difficulty_menu->add_action(GAction::create("Beginner", { Mod_Ctrl, Key_B }, [&](const GAction&) {
|
||||
field->set_field_size(9, 9, 10);
|
||||
}));
|
||||
difficulty_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [field](const GAction&) {
|
||||
difficulty_menu->add_action(GAction::create("Intermediate", { Mod_Ctrl, Key_I }, [&](const GAction&) {
|
||||
field->set_field_size(16, 16, 40);
|
||||
}));
|
||||
difficulty_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [field](const GAction&) {
|
||||
difficulty_menu->add_action(GAction::create("Expert", { Mod_Ctrl, Key_E }, [&](const GAction&) {
|
||||
field->set_field_size(16, 30, 99);
|
||||
}));
|
||||
difficulty_menu->add_action(GAction::create("Madwoman", { Mod_Ctrl, Key_M }, [field](const GAction&) {
|
||||
difficulty_menu->add_action(GAction::create("Madwoman", { Mod_Ctrl, Key_M }, [&](const GAction&) {
|
||||
field->set_field_size(32, 60, 350);
|
||||
}));
|
||||
menubar->add_menu(move(difficulty_menu));
|
||||
|
|
|
@ -5,13 +5,14 @@
|
|||
#include <LibGUI/GWidget.h>
|
||||
|
||||
class SnakeGame : public GWidget {
|
||||
C_OBJECT(SnakeGame)
|
||||
public:
|
||||
explicit SnakeGame(GWidget* parent = nullptr);
|
||||
virtual ~SnakeGame() override;
|
||||
|
||||
void reset();
|
||||
|
||||
private:
|
||||
explicit SnakeGame(GWidget* parent = nullptr);
|
||||
virtual void paint_event(GPaintEvent&) override;
|
||||
virtual void keydown_event(GKeyEvent&) override;
|
||||
virtual void timer_event(CTimerEvent&) override;
|
||||
|
|
|
@ -18,7 +18,7 @@ int main(int argc, char** argv)
|
|||
window->set_title("Snake");
|
||||
window->set_rect(100, 100, 320, 320);
|
||||
|
||||
auto* game = new SnakeGame;
|
||||
auto game = SnakeGame::construct();
|
||||
window->set_main_widget(game);
|
||||
|
||||
auto menubar = make<GMenuBar>();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue