mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-22 12:35:14 +00:00
LibGUI: Convert custom widgets and subclasses to ObjectPtr
This commit is contained in:
parent
15a66dc8ab
commit
defafd72bc
Notes:
sideshowbarker
2024-07-19 12:00:58 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/defafd72bc7
30 changed files with 57 additions and 47 deletions
|
@ -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&);
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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; }
|
||||
|
||||
|
|
|
@ -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());
|
||||
});
|
||||
|
||||
|
|
|
@ -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 };
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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());
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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"));
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -6,6 +6,7 @@ class GTableView;
|
|||
class GTextBox;
|
||||
|
||||
class VBPropertiesWindow final : public GWindow {
|
||||
C_OBJECT(VBPropertiesWindow)
|
||||
public:
|
||||
VBPropertiesWindow();
|
||||
virtual ~VBPropertiesWindow() override;
|
||||
|
|
|
@ -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));
|
||||
|
|
|
@ -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
Reference in a new issue