diff options
author | Andreas Kling <kling@serenityos.org> | 2020-02-23 12:07:13 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2020-02-23 12:27:53 +0100 |
commit | c5d913970ab122cdeaf23aea24e65efa6b425ab0 (patch) | |
tree | 07ef4cb2d039521ec7b1931c707b5196b7ea1628 /Games | |
parent | 4ce28c32d1813b043758c0d15d5efc17452c2b77 (diff) | |
download | serenity-c5d913970ab122cdeaf23aea24e65efa6b425ab0.zip |
LibGUI: Remove parent parameter to GUI::Widget constructor
Diffstat (limited to 'Games')
-rw-r--r-- | Games/Minesweeper/Field.cpp | 34 | ||||
-rw-r--r-- | Games/Minesweeper/Field.h | 6 | ||||
-rw-r--r-- | Games/Snake/SnakeGame.cpp | 3 | ||||
-rw-r--r-- | Games/Snake/SnakeGame.h | 2 |
4 files changed, 24 insertions, 21 deletions
diff --git a/Games/Minesweeper/Field.cpp b/Games/Minesweeper/Field.cpp index 17250264ca..90cef6454a 100644 --- a/Games/Minesweeper/Field.cpp +++ b/Games/Minesweeper/Field.cpp @@ -36,12 +36,9 @@ #include <unistd.h> class SquareButton final : public GUI::Button { -public: - SquareButton(GUI::Widget* parent) - : GUI::Button(parent) - { - } + C_OBJECT(SquareButton); +public: Function<void()> on_right_click; Function<void()> on_middle_click; @@ -57,16 +54,15 @@ public: } GUI::Button::mousedown_event(event); } + +private: + SquareButton() {} }; class SquareLabel final : public GUI::Label { -public: - SquareLabel(Square& square, GUI::Widget* parent) - : GUI::Label(parent) - , m_square(square) - { - } + C_OBJECT(SquareLabel); +public: Function<void()> on_chord_click; virtual void mousedown_event(GUI::MouseEvent& event) override @@ -115,6 +111,12 @@ public: GUI::Label::mouseup_event(event); } +private: + explicit SquareLabel(Square& square) + : m_square(square) + { + } + Square& m_square; bool m_chord { false }; }; @@ -243,7 +245,7 @@ void Field::reset() square.is_considering = false; square.is_swept = false; if (!square.label) { - square.label = new SquareLabel(square, this); + square.label = add<SquareLabel>(square); square.label->set_background_color(Color::from_rgb(0xff4040)); } square.label->set_fill_with_background_color(false); @@ -251,7 +253,7 @@ void Field::reset() square.label->set_visible(false); square.label->set_icon(square.has_mine ? m_mine_bitmap : nullptr); if (!square.button) { - square.button = new SquareButton(this); + square.button = add<SquareButton>(); square.button->on_click = [this, &square](GUI::Button&) { on_square_clicked(square); }; @@ -513,10 +515,12 @@ void Field::set_single_chording(bool enabled) config->write_bool_entry("Minesweeper", "SingleChording", m_single_chording); } +Square::Square() +{ +} + Square::~Square() { - delete label; - delete button; } template<typename Callback> diff --git a/Games/Minesweeper/Field.h b/Games/Minesweeper/Field.h index b56813d460..97a84f015d 100644 --- a/Games/Minesweeper/Field.h +++ b/Games/Minesweeper/Field.h @@ -37,7 +37,7 @@ class SquareLabel; class Square { AK_MAKE_NONCOPYABLE(Square) public: - Square() {} + Square(); ~Square(); Field* field { nullptr }; @@ -48,8 +48,8 @@ public: int row { 0 }; int column { 0 }; int number { 0 }; - SquareButton* button { nullptr }; - SquareLabel* label { nullptr }; + RefPtr<SquareButton> button; + RefPtr<SquareLabel> label; template<typename Callback> void for_each_neighbor(Callback); diff --git a/Games/Snake/SnakeGame.cpp b/Games/Snake/SnakeGame.cpp index a560d895d6..39ba9caa44 100644 --- a/Games/Snake/SnakeGame.cpp +++ b/Games/Snake/SnakeGame.cpp @@ -32,8 +32,7 @@ #include <stdlib.h> #include <time.h> -SnakeGame::SnakeGame(GUI::Widget* parent) - : GUI::Widget(parent) +SnakeGame::SnakeGame() { set_font(GFontDatabase::the().get_by_name("Liza Regular")); m_fruit_bitmaps.append(*Gfx::Bitmap::load_from_file("/res/icons/snake/paprika.png")); diff --git a/Games/Snake/SnakeGame.h b/Games/Snake/SnakeGame.h index abe08df450..6ecb5fa099 100644 --- a/Games/Snake/SnakeGame.h +++ b/Games/Snake/SnakeGame.h @@ -38,7 +38,7 @@ public: void reset(); private: - explicit SnakeGame(GUI::Widget* parent = nullptr); + SnakeGame(); virtual void paint_event(GUI::PaintEvent&) override; virtual void keydown_event(GUI::KeyEvent&) override; virtual void timer_event(Core::TimerEvent&) override; |