summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-09-21 20:04:00 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-09-21 20:04:00 +0200
commitdefafd72bc771034d615d56fe3fc5f71a7f707e5 (patch)
tree5cf61389b7315605c61aa345e31464deab35542d
parent15a66dc8ab850de870f906ce64176ad5a58acf7e (diff)
downloadserenity-defafd72bc771034d615d56fe3fc5f71a7f707e5.zip
LibGUI: Convert custom widgets and subclasses to ObjectPtr
-rw-r--r--Applications/Calculator/CalculatorWidget.h2
-rw-r--r--Applications/Calculator/main.cpp2
-rw-r--r--Applications/FileManager/DirectoryView.h2
-rw-r--r--Applications/FileManager/main.cpp12
-rw-r--r--Applications/FontEditor/FontEditor.h3
-rw-r--r--Applications/FontEditor/main.cpp2
-rw-r--r--Applications/PaintBrush/PaletteWidget.cpp3
-rw-r--r--Applications/PaintBrush/ToolboxWidget.cpp5
-rw-r--r--Applications/PaintBrush/main.cpp4
-rw-r--r--Applications/Piano/PianoWidget.h3
-rw-r--r--Applications/Piano/main.cpp6
-rw-r--r--Applications/QuickShow/QSWidget.h3
-rw-r--r--Applications/QuickShow/main.cpp2
-rw-r--r--Applications/SoundPlayer/SampleWidget.h2
-rw-r--r--Applications/SoundPlayer/main.cpp2
-rw-r--r--Applications/Taskbar/TaskbarButton.h1
-rw-r--r--Applications/Taskbar/TaskbarWindow.cpp2
-rw-r--r--Applications/Terminal/main.cpp4
-rw-r--r--Applications/TextEditor/TextEditorWidget.h3
-rw-r--r--Applications/TextEditor/main.cpp2
-rw-r--r--Applications/Welcome/main.cpp2
-rw-r--r--Demos/Fire/Fire.cpp5
-rw-r--r--Demos/PaintTest/main.cpp2
-rw-r--r--DevTools/VisualBuilder/VBForm.h2
-rw-r--r--DevTools/VisualBuilder/VBPropertiesWindow.h1
-rw-r--r--DevTools/VisualBuilder/main.cpp8
-rw-r--r--Games/Minesweeper/Field.h2
-rw-r--r--Games/Minesweeper/main.cpp12
-rw-r--r--Games/Snake/SnakeGame.h3
-rw-r--r--Games/Snake/main.cpp2
30 files changed, 57 insertions, 47 deletions
diff --git a/Applications/Calculator/CalculatorWidget.h b/Applications/Calculator/CalculatorWidget.h
index 4f682f95ea..59502ed97a 100644
--- a/Applications/Calculator/CalculatorWidget.h
+++ b/Applications/Calculator/CalculatorWidget.h
@@ -12,10 +12,10 @@ class GLabel;
class CalculatorWidget final : public GWidget {
C_OBJECT(CalculatorWidget)
public:
- explicit CalculatorWidget(GWidget*);
virtual ~CalculatorWidget() override;
private:
+ explicit CalculatorWidget(GWidget*);
void add_button(GButton&, Calculator::Operation);
void add_button(GButton&, int);
void add_button(GButton&);
diff --git a/Applications/Calculator/main.cpp b/Applications/Calculator/main.cpp
index 9e7208a293..f0701b1ead 100644
--- a/Applications/Calculator/main.cpp
+++ b/Applications/Calculator/main.cpp
@@ -11,7 +11,7 @@ int main(int argc, char** argv)
window->set_resizable(false);
window->set_rect({ 300, 200, 254, 213 });
- auto* calc_widget = new CalculatorWidget(nullptr);
+ auto calc_widget = CalculatorWidget::construct(nullptr);
window->set_main_widget(calc_widget);
window->show();
diff --git a/Applications/FileManager/DirectoryView.h b/Applications/FileManager/DirectoryView.h
index 8ea8f41880..53b6eec578 100644
--- a/Applications/FileManager/DirectoryView.h
+++ b/Applications/FileManager/DirectoryView.h
@@ -10,7 +10,6 @@
class DirectoryView final : public GStackWidget {
C_OBJECT(DirectoryView)
public:
- explicit DirectoryView(GWidget* parent);
virtual ~DirectoryView() override;
void open(const StringView& path);
@@ -57,6 +56,7 @@ public:
}
private:
+ explicit DirectoryView(GWidget* parent);
GDirectoryModel& model() { return *m_model; }
const GDirectoryModel& model() const { return *m_model; }
diff --git a/Applications/FileManager/main.cpp b/Applications/FileManager/main.cpp
index 7ac0d0a8f0..73b32c0441 100644
--- a/Applications/FileManager/main.cpp
+++ b/Applications/FileManager/main.cpp
@@ -64,7 +64,7 @@ int main(int argc, char** argv)
tree_view->set_model(file_system_model);
tree_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
tree_view->set_preferred_size(200, 0);
- auto* directory_view = new DirectoryView(splitter);
+ auto directory_view = DirectoryView::construct(splitter);
auto statusbar = GStatusBar::construct(widget);
@@ -76,7 +76,7 @@ int main(int argc, char** argv)
progressbar->set_frame_shadow(FrameShadow::Sunken);
progressbar->set_frame_thickness(1);
- location_textbox->on_return_pressed = [directory_view, location_textbox] {
+ location_textbox->on_return_pressed = [&] {
directory_view->open(location_textbox->text());
};
@@ -87,7 +87,7 @@ int main(int argc, char** argv)
directory_view->open(path);
};
- auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [directory_view](const GAction&) {
+ auto open_parent_directory_action = GAction::create("Open parent directory", { Mod_Alt, Key_Up }, GraphicsBitmap::load_from_file("/res/icons/16x16/open-parent-directory.png"), [&](const GAction&) {
directory_view->open_parent_directory();
});
@@ -250,17 +250,17 @@ int main(int argc, char** argv)
});
delete_action->set_enabled(false);
- auto go_back_action = GAction::create("Go Back", { Mod_Alt, Key_Left }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-back.png"), [directory_view](const GAction&) {
+ auto go_back_action = GAction::create("Go Back", { Mod_Alt, Key_Left }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-back.png"), [&](const GAction&) {
dbgprintf("'Go Back' action activated!\n");
directory_view->open_previous_directory();
});
- auto go_forward_action = GAction::create("Go Forward", { Mod_Alt, Key_Right }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [directory_view](const GAction&) {
+ auto go_forward_action = GAction::create("Go Forward", { Mod_Alt, Key_Right }, GraphicsBitmap::load_from_file("/res/icons/16x16/go-forward.png"), [&](const GAction&) {
dbgprintf("'Go Forward' action activated!\n");
directory_view->open_next_directory();
});
- auto go_home_action = GAction::create("Go to Home Directory", GraphicsBitmap::load_from_file("/res/icons/16x16/go-home.png"), [directory_view](auto&) {
+ auto go_home_action = GAction::create("Go to Home Directory", GraphicsBitmap::load_from_file("/res/icons/16x16/go-home.png"), [&](auto&) {
directory_view->open(get_current_user_home_path());
});
diff --git a/Applications/FontEditor/FontEditor.h b/Applications/FontEditor/FontEditor.h
index 033daf3301..2b6fccd724 100644
--- a/Applications/FontEditor/FontEditor.h
+++ b/Applications/FontEditor/FontEditor.h
@@ -10,11 +10,12 @@ class GTextBox;
struct UI_FontEditorBottom;
class FontEditorWidget final : public GWidget {
+ C_OBJECT(FontEditorWidget)
public:
- FontEditorWidget(const String& path, RefPtr<Font>&&, GWidget* parent = nullptr);
virtual ~FontEditorWidget() override;
private:
+ FontEditorWidget(const String& path, RefPtr<Font>&&, GWidget* parent = nullptr);
RefPtr<Font> m_edited_font;
GlyphMapWidget* m_glyph_map_widget { nullptr };
diff --git a/Applications/FontEditor/main.cpp b/Applications/FontEditor/main.cpp
index d8799c4279..109e4a1151 100644
--- a/Applications/FontEditor/main.cpp
+++ b/Applications/FontEditor/main.cpp
@@ -28,7 +28,7 @@ int main(int argc, char** argv)
auto window = GWindow::construct();
window->set_title("Font Editor");
window->set_rect({ 50, 50, 390, 342 });
- auto* font_editor = new FontEditorWidget(path, move(edited_font));
+ auto font_editor = FontEditorWidget::construct(path, move(edited_font));
window->set_main_widget(font_editor);
window->show();
window->set_icon(load_png("/res/icons/16x16/app-font-editor.png"));
diff --git a/Applications/PaintBrush/PaletteWidget.cpp b/Applications/PaintBrush/PaletteWidget.cpp
index be2d442abe..dcd7f9d60e 100644
--- a/Applications/PaintBrush/PaletteWidget.cpp
+++ b/Applications/PaintBrush/PaletteWidget.cpp
@@ -4,6 +4,7 @@
#include <LibGUI/GBoxLayout.h>
class ColorWidget : public GFrame {
+ C_OBJECT(ColorWidget)
public:
explicit ColorWidget(Color color, PaletteWidget& palette_widget, GWidget* parent)
: GFrame(parent)
@@ -95,7 +96,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
bottom_color_container->layout()->set_spacing(1);
auto add_color_widget = [&](GWidget* container, Color color) {
- auto* color_widget = new ColorWidget(color, *this, container);
+ auto color_widget = ColorWidget::construct(color, *this, container);
color_widget->set_fill_with_background_color(true);
color_widget->set_background_color(color);
};
diff --git a/Applications/PaintBrush/ToolboxWidget.cpp b/Applications/PaintBrush/ToolboxWidget.cpp
index b4ea7a430b..1ec7d32d4d 100644
--- a/Applications/PaintBrush/ToolboxWidget.cpp
+++ b/Applications/PaintBrush/ToolboxWidget.cpp
@@ -10,6 +10,7 @@
#include <LibDraw/PNGLoader.h>
class ToolButton final : public GButton {
+ C_OBJECT(ToolButton)
public:
ToolButton(const String& name, GWidget* parent, OwnPtr<Tool>&& tool)
: GButton(parent)
@@ -47,7 +48,7 @@ ToolboxWidget::ToolboxWidget(GWidget* parent)
layout()->set_margins({ 4, 4, 4, 4 });
auto add_tool = [&](const StringView& name, const StringView& icon_name, OwnPtr<Tool>&& tool) {
- auto* button = new ToolButton(name, this, move(tool));
+ auto button = ToolButton::construct(name, this, move(tool));
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
button->set_preferred_size(0, 32);
button->set_checkable(true);
@@ -55,7 +56,7 @@ ToolboxWidget::ToolboxWidget(GWidget* parent)
button->set_icon(load_png(String::format("/res/icons/paintbrush/%s.png", String(icon_name).characters())));
- button->on_checked = [button](auto checked) {
+ button->on_checked = [button = button.ptr()](auto checked) {
if (checked)
PaintableWidget::the().set_tool(&button->tool());
else
diff --git a/Applications/PaintBrush/main.cpp b/Applications/PaintBrush/main.cpp
index 453da4a42c..bc00303e1a 100644
--- a/Applications/PaintBrush/main.cpp
+++ b/Applications/PaintBrush/main.cpp
@@ -30,8 +30,8 @@ int main(int argc, char** argv)
vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
vertical_container->layout()->set_spacing(0);
- auto* paintable_widget = new PaintableWidget(vertical_container);
- new PaletteWidget(*paintable_widget, vertical_container);
+ auto paintable_widget = PaintableWidget::construct(vertical_container);
+ PaletteWidget::construct(*paintable_widget, vertical_container);
window->show();
diff --git a/Applications/Piano/PianoWidget.h b/Applications/Piano/PianoWidget.h
index 73cc3443be..8e64d90528 100644
--- a/Applications/Piano/PianoWidget.h
+++ b/Applications/Piano/PianoWidget.h
@@ -6,13 +6,14 @@
class GPainter;
class PianoWidget final : public GWidget {
+ C_OBJECT(PianoWidget)
public:
- PianoWidget();
virtual ~PianoWidget() override;
void fill_audio_buffer(uint8_t* stream, int len);
private:
+ PianoWidget();
virtual void paint_event(GPaintEvent&) override;
virtual void keydown_event(GKeyEvent&) override;
virtual void keyup_event(GKeyEvent&) override;
diff --git a/Applications/Piano/main.cpp b/Applications/Piano/main.cpp
index 22699a1ada..f7a874c58f 100644
--- a/Applications/Piano/main.cpp
+++ b/Applications/Piano/main.cpp
@@ -21,12 +21,12 @@ int main(int argc, char** argv)
window->set_title("Piano");
window->set_rect(100, 100, 512, 512);
- auto* piano_widget = new PianoWidget;
+ auto piano_widget = PianoWidget::construct();
window->set_main_widget(piano_widget);
window->show();
window->set_icon(load_png("/res/icons/16x16/app-piano.png"));
- LibThread::Thread sound_thread([piano_widget] {
+ LibThread::Thread sound_thread([piano_widget = piano_widget.ptr()] {
CFile audio("/dev/audio");
if (!audio.open(CIODevice::WriteOnly)) {
dbgprintf("Can't open audio device: %s", audio.error_string());
@@ -38,7 +38,7 @@ int main(int argc, char** argv)
piano_widget->fill_audio_buffer(buffer, sizeof(buffer));
audio.write(buffer, sizeof(buffer));
GEventLoop::current().post_event(*piano_widget, make<CCustomEvent>(0));
- GEventLoop::current().wake();
+ GEventLoop::wake();
}
});
sound_thread.start();
diff --git a/Applications/QuickShow/QSWidget.h b/Applications/QuickShow/QSWidget.h
index a4a2f69ff3..aca9151552 100644
--- a/Applications/QuickShow/QSWidget.h
+++ b/Applications/QuickShow/QSWidget.h
@@ -6,8 +6,8 @@ class GLabel;
class QSLabel;
class QSWidget final : public GFrame {
+ C_OBJECT(QSWidget)
public:
- QSWidget(GWidget* parent);
virtual ~QSWidget() override;
void set_bitmap(NonnullRefPtr<GraphicsBitmap>);
@@ -15,6 +15,7 @@ public:
Function<void(int)> on_scale_change;
private:
+ explicit QSWidget(GWidget* parent = nullptr);
virtual void paint_event(GPaintEvent&) override;
virtual void resize_event(GResizeEvent&) override;
virtual void mousedown_event(GMouseEvent&) override;
diff --git a/Applications/QuickShow/main.cpp b/Applications/QuickShow/main.cpp
index 22cadbb3a7..e40c96b780 100644
--- a/Applications/QuickShow/main.cpp
+++ b/Applications/QuickShow/main.cpp
@@ -60,7 +60,7 @@ int main(int argc, char** argv)
update_window_title(100);
window->set_rect(200, 200, bitmap->width(), bitmap->height());
- auto* widget = new QSWidget(nullptr);
+ auto widget = QSWidget::construct();
widget->on_scale_change = [&](int scale) {
update_window_title(scale);
};
diff --git a/Applications/SoundPlayer/SampleWidget.h b/Applications/SoundPlayer/SampleWidget.h
index 3325f3d6c9..bd82d3ef75 100644
--- a/Applications/SoundPlayer/SampleWidget.h
+++ b/Applications/SoundPlayer/SampleWidget.h
@@ -7,12 +7,12 @@ class ABuffer;
class SampleWidget final : public GFrame {
C_OBJECT(SampleWidget)
public:
- explicit SampleWidget(GWidget* parent);
virtual ~SampleWidget() override;
void set_buffer(ABuffer*);
private:
+ explicit SampleWidget(GWidget* parent);
virtual void paint_event(GPaintEvent&) override;
RefPtr<ABuffer> m_buffer;
diff --git a/Applications/SoundPlayer/main.cpp b/Applications/SoundPlayer/main.cpp
index 657551fe27..35cd32ae13 100644
--- a/Applications/SoundPlayer/main.cpp
+++ b/Applications/SoundPlayer/main.cpp
@@ -41,7 +41,7 @@ int main(int argc, char** argv)
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
widget->layout()->set_margins({ 2, 2, 2, 2 });
- auto* sample_widget = new SampleWidget(widget);
+ auto sample_widget = SampleWidget::construct(widget);
auto button = GButton::construct("Quit", widget);
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
diff --git a/Applications/Taskbar/TaskbarButton.h b/Applications/Taskbar/TaskbarButton.h
index 000f71be86..95be9a4f8f 100644
--- a/Applications/Taskbar/TaskbarButton.h
+++ b/Applications/Taskbar/TaskbarButton.h
@@ -4,6 +4,7 @@
#include <LibGUI/GButton.h>
class TaskbarButton final : public GButton {
+ C_OBJECT(TaskbarButton)
public:
TaskbarButton(const WindowIdentifier&, GWidget* parent);
virtual ~TaskbarButton() override;
diff --git a/Applications/Taskbar/TaskbarWindow.cpp b/Applications/Taskbar/TaskbarWindow.cpp
index f4492650f3..2ab9898526 100644
--- a/Applications/Taskbar/TaskbarWindow.cpp
+++ b/Applications/Taskbar/TaskbarWindow.cpp
@@ -48,7 +48,7 @@ void TaskbarWindow::on_screen_rect_change(const Rect& rect)
GButton* TaskbarWindow::create_button(const WindowIdentifier& identifier)
{
- auto* button = new TaskbarButton(identifier, main_widget());
+ auto button = TaskbarButton::construct(identifier, main_widget());
button->set_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
button->set_preferred_size(140, 22);
button->set_checkable(true);
diff --git a/Applications/Terminal/main.cpp b/Applications/Terminal/main.cpp
index c0a2f0a0ae..9e46463a39 100644
--- a/Applications/Terminal/main.cpp
+++ b/Applications/Terminal/main.cpp
@@ -162,7 +162,7 @@ int main(int argc, char** argv)
window->set_double_buffering_enabled(false);
RefPtr<CConfigFile> config = CConfigFile::get_for_app("Terminal");
- auto* terminal = new TerminalWidget(ptm_fd, config);
+ auto terminal = TerminalWidget::construct(ptm_fd, config);
window->set_main_widget(terminal);
window->move_to(300, 300);
terminal->apply_size_increments_to_window(*window);
@@ -200,7 +200,7 @@ int main(int argc, char** argv)
auto font_menu = make<GMenu>("Font");
GFontDatabase::the().for_each_fixed_width_font([&](const StringView& font_name) {
- font_menu->add_action(GAction::create(font_name, [terminal, &config](const GAction& action) {
+ font_menu->add_action(GAction::create(font_name, [&](const GAction& action) {
terminal->set_font(GFontDatabase::the().get_by_name(action.text()));
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
ASSERT(metadata.has_value());
diff --git a/Applications/TextEditor/TextEditorWidget.h b/Applications/TextEditor/TextEditorWidget.h
index 2b59e912d6..12b29876cb 100644
--- a/Applications/TextEditor/TextEditorWidget.h
+++ b/Applications/TextEditor/TextEditorWidget.h
@@ -13,13 +13,14 @@ class GTextEditor;
class GStatusBar;
class TextEditorWidget final : public GWidget {
+ C_OBJECT(TextEditorWidget)
public:
- TextEditorWidget();
virtual ~TextEditorWidget() override;
void open_sesame(const String& path);
bool request_close();
private:
+ TextEditorWidget();
void set_path(const FileSystemPath& file);
void update_title();
diff --git a/Applications/TextEditor/main.cpp b/Applications/TextEditor/main.cpp
index 66d4699f17..0b0046b84e 100644
--- a/Applications/TextEditor/main.cpp
+++ b/Applications/TextEditor/main.cpp
@@ -9,7 +9,7 @@ int main(int argc, char** argv)
window->set_title("Text Editor");
window->set_rect(20, 200, 640, 400);
- auto* text_widget = new TextEditorWidget();
+ auto text_widget = TextEditorWidget::construct();
window->set_main_widget(text_widget);
window->on_close_request = [&]() -> GWindow::CloseRequestDecision {
diff --git a/Applications/Welcome/main.cpp b/Applications/Welcome/main.cpp
index 0fa33298e6..5f10cbfea8 100644
--- a/Applications/Welcome/main.cpp
+++ b/Applications/Welcome/main.cpp
@@ -125,7 +125,7 @@ int main(int argc, char** argv)
content_title->set_preferred_size(0, 10);
for (auto& paragraph : page.content) {
- auto* content_text = new TextWidget(content);
+ auto content_text = TextWidget::construct(content);
content_text->set_font(Font::default_font());
content_text->set_text(paragraph);
content_text->set_text_alignment(TextAlignment::TopLeft);
diff --git a/Demos/Fire/Fire.cpp b/Demos/Fire/Fire.cpp
index acf7119e79..8c2aaed32d 100644
--- a/Demos/Fire/Fire.cpp
+++ b/Demos/Fire/Fire.cpp
@@ -64,12 +64,13 @@ static int my_rand(void)
* Fire Widget
*/
class Fire : public GWidget {
+ C_OBJECT(Fire)
public:
- explicit Fire(GWidget* parent = nullptr);
virtual ~Fire() override;
void set_stat_label(GLabel* l) { stats = l; };
private:
+ explicit Fire(GWidget* parent = nullptr);
RefPtr<GraphicsBitmap> bitmap;
GLabel* stats;
@@ -220,7 +221,7 @@ int main(int argc, char** argv)
window->set_resizable(false);
window->set_rect(100, 100, 640, 400);
- auto* fire = new Fire;
+ auto fire = Fire::construct();
window->set_main_widget(fire);
auto time = GLabel::construct(fire);
diff --git a/Demos/PaintTest/main.cpp b/Demos/PaintTest/main.cpp
index 3486c5f186..8cd0fde90e 100644
--- a/Demos/PaintTest/main.cpp
+++ b/Demos/PaintTest/main.cpp
@@ -42,7 +42,7 @@ int main(int argc, char** argv)
window->set_rect(100, 100, 400, 400);
window->set_title("Paint test");
- auto* test_widget = new TestWidget(nullptr);
+ auto test_widget = new TestWidget(nullptr);
window->set_main_widget(test_widget);
test_widget->set_bitmap(load_png("/res/icons/gear16.png"));
diff --git a/DevTools/VisualBuilder/VBForm.h b/DevTools/VisualBuilder/VBForm.h
index e2d7421185..a2c0a27f90 100644
--- a/DevTools/VisualBuilder/VBForm.h
+++ b/DevTools/VisualBuilder/VBForm.h
@@ -5,8 +5,8 @@
#include <LibGUI/GWidget.h>
class VBForm : public GWidget {
+ C_OBJECT(VBForm)
friend class VBWidget;
-
public:
explicit VBForm(const String& name, GWidget* parent = nullptr);
virtual ~VBForm() override;
diff --git a/DevTools/VisualBuilder/VBPropertiesWindow.h b/DevTools/VisualBuilder/VBPropertiesWindow.h
index 070854568c..eb1b17530b 100644
--- a/DevTools/VisualBuilder/VBPropertiesWindow.h
+++ b/DevTools/VisualBuilder/VBPropertiesWindow.h
@@ -6,6 +6,7 @@ class GTableView;
class GTextBox;
class VBPropertiesWindow final : public GWindow {
+ C_OBJECT(VBPropertiesWindow)
public:
VBPropertiesWindow();
virtual ~VBPropertiesWindow() override;
diff --git a/DevTools/VisualBuilder/main.cpp b/DevTools/VisualBuilder/main.cpp
index adecb57f08..c93a5527c4 100644
--- a/DevTools/VisualBuilder/main.cpp
+++ b/DevTools/VisualBuilder/main.cpp
@@ -23,10 +23,10 @@ int main(int argc, char** argv)
{
GApplication app(argc, argv);
- auto* propbox = new VBPropertiesWindow;
+ auto propbox = VBPropertiesWindow::construct();
- auto* form1 = new VBForm("Form1");
- form1->on_widget_selected = [propbox](VBWidget* widget) {
+ auto form1 = VBForm::construct("Form1");
+ form1->on_widget_selected = [&](VBWidget* widget) {
propbox->table_view().set_model(widget ? &widget->property_model() : nullptr);
};
@@ -42,7 +42,7 @@ int main(int argc, char** argv)
file_menu->add_action(GAction::create("Dump Form", [&](auto&) {
form1->dump();
}));
- file_menu->add_action(GAction::create("Save Form...", { Mod_Ctrl, Key_S }, [form1](auto&) {
+ file_menu->add_action(GAction::create("Save Form...", { Mod_Ctrl, Key_S }, [&](auto&) {
form1->write_to_file("/tmp/form.frm");
}));
menubar->add_menu(move(file_menu));
diff --git a/Games/Minesweeper/Field.h b/Games/Minesweeper/Field.h
index e976d26189..fff4cb0161 100644
--- a/Games/Minesweeper/Field.h
+++ b/Games/Minesweeper/Field.h
@@ -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;
diff --git a/Games/Minesweeper/main.cpp b/Games/Minesweeper/main.cpp
index 5299572f74..c7083785d8 100644
--- a/Games/Minesweeper/main.cpp
+++ b/Games/Minesweeper/main.cpp
@@ -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));
diff --git a/Games/Snake/SnakeGame.h b/Games/Snake/SnakeGame.h
index 2c03e2541b..ac002158ac 100644
--- a/Games/Snake/SnakeGame.h
+++ b/Games/Snake/SnakeGame.h
@@ -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;
diff --git a/Games/Snake/main.cpp b/Games/Snake/main.cpp
index e8df14fd36..2000cc2aa4 100644
--- a/Games/Snake/main.cpp
+++ b/Games/Snake/main.cpp
@@ -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>();