mirror of
https://github.com/RGBCube/serenity
synced 2025-05-19 00:15:08 +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
|
@ -12,10 +12,10 @@ class GLabel;
|
||||||
class CalculatorWidget final : public GWidget {
|
class CalculatorWidget final : public GWidget {
|
||||||
C_OBJECT(CalculatorWidget)
|
C_OBJECT(CalculatorWidget)
|
||||||
public:
|
public:
|
||||||
explicit CalculatorWidget(GWidget*);
|
|
||||||
virtual ~CalculatorWidget() override;
|
virtual ~CalculatorWidget() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit CalculatorWidget(GWidget*);
|
||||||
void add_button(GButton&, Calculator::Operation);
|
void add_button(GButton&, Calculator::Operation);
|
||||||
void add_button(GButton&, int);
|
void add_button(GButton&, int);
|
||||||
void add_button(GButton&);
|
void add_button(GButton&);
|
||||||
|
|
|
@ -11,7 +11,7 @@ int main(int argc, char** argv)
|
||||||
window->set_resizable(false);
|
window->set_resizable(false);
|
||||||
window->set_rect({ 300, 200, 254, 213 });
|
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->set_main_widget(calc_widget);
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
class DirectoryView final : public GStackWidget {
|
class DirectoryView final : public GStackWidget {
|
||||||
C_OBJECT(DirectoryView)
|
C_OBJECT(DirectoryView)
|
||||||
public:
|
public:
|
||||||
explicit DirectoryView(GWidget* parent);
|
|
||||||
virtual ~DirectoryView() override;
|
virtual ~DirectoryView() override;
|
||||||
|
|
||||||
void open(const StringView& path);
|
void open(const StringView& path);
|
||||||
|
@ -57,6 +56,7 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit DirectoryView(GWidget* parent);
|
||||||
GDirectoryModel& model() { return *m_model; }
|
GDirectoryModel& model() { return *m_model; }
|
||||||
const GDirectoryModel& model() const { 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_model(file_system_model);
|
||||||
tree_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
tree_view->set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
||||||
tree_view->set_preferred_size(200, 0);
|
tree_view->set_preferred_size(200, 0);
|
||||||
auto* directory_view = new DirectoryView(splitter);
|
auto directory_view = DirectoryView::construct(splitter);
|
||||||
|
|
||||||
auto statusbar = GStatusBar::construct(widget);
|
auto statusbar = GStatusBar::construct(widget);
|
||||||
|
|
||||||
|
@ -76,7 +76,7 @@ int main(int argc, char** argv)
|
||||||
progressbar->set_frame_shadow(FrameShadow::Sunken);
|
progressbar->set_frame_shadow(FrameShadow::Sunken);
|
||||||
progressbar->set_frame_thickness(1);
|
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());
|
directory_view->open(location_textbox->text());
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -87,7 +87,7 @@ int main(int argc, char** argv)
|
||||||
directory_view->open(path);
|
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();
|
directory_view->open_parent_directory();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -250,17 +250,17 @@ int main(int argc, char** argv)
|
||||||
});
|
});
|
||||||
delete_action->set_enabled(false);
|
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");
|
dbgprintf("'Go Back' action activated!\n");
|
||||||
directory_view->open_previous_directory();
|
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");
|
dbgprintf("'Go Forward' action activated!\n");
|
||||||
directory_view->open_next_directory();
|
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());
|
directory_view->open(get_current_user_home_path());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -10,11 +10,12 @@ class GTextBox;
|
||||||
struct UI_FontEditorBottom;
|
struct UI_FontEditorBottom;
|
||||||
|
|
||||||
class FontEditorWidget final : public GWidget {
|
class FontEditorWidget final : public GWidget {
|
||||||
|
C_OBJECT(FontEditorWidget)
|
||||||
public:
|
public:
|
||||||
FontEditorWidget(const String& path, RefPtr<Font>&&, GWidget* parent = nullptr);
|
|
||||||
virtual ~FontEditorWidget() override;
|
virtual ~FontEditorWidget() override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
FontEditorWidget(const String& path, RefPtr<Font>&&, GWidget* parent = nullptr);
|
||||||
RefPtr<Font> m_edited_font;
|
RefPtr<Font> m_edited_font;
|
||||||
|
|
||||||
GlyphMapWidget* m_glyph_map_widget { nullptr };
|
GlyphMapWidget* m_glyph_map_widget { nullptr };
|
||||||
|
|
|
@ -28,7 +28,7 @@ int main(int argc, char** argv)
|
||||||
auto window = GWindow::construct();
|
auto window = GWindow::construct();
|
||||||
window->set_title("Font Editor");
|
window->set_title("Font Editor");
|
||||||
window->set_rect({ 50, 50, 390, 342 });
|
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->set_main_widget(font_editor);
|
||||||
window->show();
|
window->show();
|
||||||
window->set_icon(load_png("/res/icons/16x16/app-font-editor.png"));
|
window->set_icon(load_png("/res/icons/16x16/app-font-editor.png"));
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <LibGUI/GBoxLayout.h>
|
#include <LibGUI/GBoxLayout.h>
|
||||||
|
|
||||||
class ColorWidget : public GFrame {
|
class ColorWidget : public GFrame {
|
||||||
|
C_OBJECT(ColorWidget)
|
||||||
public:
|
public:
|
||||||
explicit ColorWidget(Color color, PaletteWidget& palette_widget, GWidget* parent)
|
explicit ColorWidget(Color color, PaletteWidget& palette_widget, GWidget* parent)
|
||||||
: GFrame(parent)
|
: GFrame(parent)
|
||||||
|
@ -95,7 +96,7 @@ PaletteWidget::PaletteWidget(PaintableWidget& paintable_widget, GWidget* parent)
|
||||||
bottom_color_container->layout()->set_spacing(1);
|
bottom_color_container->layout()->set_spacing(1);
|
||||||
|
|
||||||
auto add_color_widget = [&](GWidget* container, Color color) {
|
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_fill_with_background_color(true);
|
||||||
color_widget->set_background_color(color);
|
color_widget->set_background_color(color);
|
||||||
};
|
};
|
||||||
|
|
|
@ -10,6 +10,7 @@
|
||||||
#include <LibDraw/PNGLoader.h>
|
#include <LibDraw/PNGLoader.h>
|
||||||
|
|
||||||
class ToolButton final : public GButton {
|
class ToolButton final : public GButton {
|
||||||
|
C_OBJECT(ToolButton)
|
||||||
public:
|
public:
|
||||||
ToolButton(const String& name, GWidget* parent, OwnPtr<Tool>&& tool)
|
ToolButton(const String& name, GWidget* parent, OwnPtr<Tool>&& tool)
|
||||||
: GButton(parent)
|
: GButton(parent)
|
||||||
|
@ -47,7 +48,7 @@ ToolboxWidget::ToolboxWidget(GWidget* parent)
|
||||||
layout()->set_margins({ 4, 4, 4, 4 });
|
layout()->set_margins({ 4, 4, 4, 4 });
|
||||||
|
|
||||||
auto add_tool = [&](const StringView& name, const StringView& icon_name, OwnPtr<Tool>&& tool) {
|
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_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
button->set_preferred_size(0, 32);
|
button->set_preferred_size(0, 32);
|
||||||
button->set_checkable(true);
|
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->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)
|
if (checked)
|
||||||
PaintableWidget::the().set_tool(&button->tool());
|
PaintableWidget::the().set_tool(&button->tool());
|
||||||
else
|
else
|
||||||
|
|
|
@ -30,8 +30,8 @@ int main(int argc, char** argv)
|
||||||
vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
vertical_container->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
vertical_container->layout()->set_spacing(0);
|
vertical_container->layout()->set_spacing(0);
|
||||||
|
|
||||||
auto* paintable_widget = new PaintableWidget(vertical_container);
|
auto paintable_widget = PaintableWidget::construct(vertical_container);
|
||||||
new PaletteWidget(*paintable_widget, vertical_container);
|
PaletteWidget::construct(*paintable_widget, vertical_container);
|
||||||
|
|
||||||
window->show();
|
window->show();
|
||||||
|
|
||||||
|
|
|
@ -6,13 +6,14 @@
|
||||||
class GPainter;
|
class GPainter;
|
||||||
|
|
||||||
class PianoWidget final : public GWidget {
|
class PianoWidget final : public GWidget {
|
||||||
|
C_OBJECT(PianoWidget)
|
||||||
public:
|
public:
|
||||||
PianoWidget();
|
|
||||||
virtual ~PianoWidget() override;
|
virtual ~PianoWidget() override;
|
||||||
|
|
||||||
void fill_audio_buffer(uint8_t* stream, int len);
|
void fill_audio_buffer(uint8_t* stream, int len);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PianoWidget();
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
virtual void keydown_event(GKeyEvent&) override;
|
virtual void keydown_event(GKeyEvent&) override;
|
||||||
virtual void keyup_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_title("Piano");
|
||||||
window->set_rect(100, 100, 512, 512);
|
window->set_rect(100, 100, 512, 512);
|
||||||
|
|
||||||
auto* piano_widget = new PianoWidget;
|
auto piano_widget = PianoWidget::construct();
|
||||||
window->set_main_widget(piano_widget);
|
window->set_main_widget(piano_widget);
|
||||||
window->show();
|
window->show();
|
||||||
window->set_icon(load_png("/res/icons/16x16/app-piano.png"));
|
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");
|
CFile audio("/dev/audio");
|
||||||
if (!audio.open(CIODevice::WriteOnly)) {
|
if (!audio.open(CIODevice::WriteOnly)) {
|
||||||
dbgprintf("Can't open audio device: %s", audio.error_string());
|
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));
|
piano_widget->fill_audio_buffer(buffer, sizeof(buffer));
|
||||||
audio.write(buffer, sizeof(buffer));
|
audio.write(buffer, sizeof(buffer));
|
||||||
GEventLoop::current().post_event(*piano_widget, make<CCustomEvent>(0));
|
GEventLoop::current().post_event(*piano_widget, make<CCustomEvent>(0));
|
||||||
GEventLoop::current().wake();
|
GEventLoop::wake();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
sound_thread.start();
|
sound_thread.start();
|
||||||
|
|
|
@ -6,8 +6,8 @@ class GLabel;
|
||||||
class QSLabel;
|
class QSLabel;
|
||||||
|
|
||||||
class QSWidget final : public GFrame {
|
class QSWidget final : public GFrame {
|
||||||
|
C_OBJECT(QSWidget)
|
||||||
public:
|
public:
|
||||||
QSWidget(GWidget* parent);
|
|
||||||
virtual ~QSWidget() override;
|
virtual ~QSWidget() override;
|
||||||
|
|
||||||
void set_bitmap(NonnullRefPtr<GraphicsBitmap>);
|
void set_bitmap(NonnullRefPtr<GraphicsBitmap>);
|
||||||
|
@ -15,6 +15,7 @@ public:
|
||||||
Function<void(int)> on_scale_change;
|
Function<void(int)> on_scale_change;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit QSWidget(GWidget* parent = nullptr);
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
virtual void resize_event(GResizeEvent&) override;
|
virtual void resize_event(GResizeEvent&) override;
|
||||||
virtual void mousedown_event(GMouseEvent&) override;
|
virtual void mousedown_event(GMouseEvent&) override;
|
||||||
|
|
|
@ -60,7 +60,7 @@ int main(int argc, char** argv)
|
||||||
update_window_title(100);
|
update_window_title(100);
|
||||||
window->set_rect(200, 200, bitmap->width(), bitmap->height());
|
window->set_rect(200, 200, bitmap->width(), bitmap->height());
|
||||||
|
|
||||||
auto* widget = new QSWidget(nullptr);
|
auto widget = QSWidget::construct();
|
||||||
widget->on_scale_change = [&](int scale) {
|
widget->on_scale_change = [&](int scale) {
|
||||||
update_window_title(scale);
|
update_window_title(scale);
|
||||||
};
|
};
|
||||||
|
|
|
@ -7,12 +7,12 @@ class ABuffer;
|
||||||
class SampleWidget final : public GFrame {
|
class SampleWidget final : public GFrame {
|
||||||
C_OBJECT(SampleWidget)
|
C_OBJECT(SampleWidget)
|
||||||
public:
|
public:
|
||||||
explicit SampleWidget(GWidget* parent);
|
|
||||||
virtual ~SampleWidget() override;
|
virtual ~SampleWidget() override;
|
||||||
|
|
||||||
void set_buffer(ABuffer*);
|
void set_buffer(ABuffer*);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit SampleWidget(GWidget* parent);
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
|
|
||||||
RefPtr<ABuffer> m_buffer;
|
RefPtr<ABuffer> m_buffer;
|
||||||
|
|
|
@ -41,7 +41,7 @@ int main(int argc, char** argv)
|
||||||
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
widget->set_layout(make<GBoxLayout>(Orientation::Vertical));
|
||||||
widget->layout()->set_margins({ 2, 2, 2, 2 });
|
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);
|
auto button = GButton::construct("Quit", widget);
|
||||||
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
||||||
|
|
|
@ -4,6 +4,7 @@
|
||||||
#include <LibGUI/GButton.h>
|
#include <LibGUI/GButton.h>
|
||||||
|
|
||||||
class TaskbarButton final : public GButton {
|
class TaskbarButton final : public GButton {
|
||||||
|
C_OBJECT(TaskbarButton)
|
||||||
public:
|
public:
|
||||||
TaskbarButton(const WindowIdentifier&, GWidget* parent);
|
TaskbarButton(const WindowIdentifier&, GWidget* parent);
|
||||||
virtual ~TaskbarButton() override;
|
virtual ~TaskbarButton() override;
|
||||||
|
|
|
@ -48,7 +48,7 @@ void TaskbarWindow::on_screen_rect_change(const Rect& rect)
|
||||||
|
|
||||||
GButton* TaskbarWindow::create_button(const WindowIdentifier& identifier)
|
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_size_policy(SizePolicy::Fixed, SizePolicy::Fixed);
|
||||||
button->set_preferred_size(140, 22);
|
button->set_preferred_size(140, 22);
|
||||||
button->set_checkable(true);
|
button->set_checkable(true);
|
||||||
|
|
|
@ -162,7 +162,7 @@ int main(int argc, char** argv)
|
||||||
window->set_double_buffering_enabled(false);
|
window->set_double_buffering_enabled(false);
|
||||||
|
|
||||||
RefPtr<CConfigFile> config = CConfigFile::get_for_app("Terminal");
|
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->set_main_widget(terminal);
|
||||||
window->move_to(300, 300);
|
window->move_to(300, 300);
|
||||||
terminal->apply_size_increments_to_window(*window);
|
terminal->apply_size_increments_to_window(*window);
|
||||||
|
@ -200,7 +200,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto font_menu = make<GMenu>("Font");
|
auto font_menu = make<GMenu>("Font");
|
||||||
GFontDatabase::the().for_each_fixed_width_font([&](const StringView& font_name) {
|
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()));
|
terminal->set_font(GFontDatabase::the().get_by_name(action.text()));
|
||||||
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
|
auto metadata = GFontDatabase::the().get_metadata_by_name(action.text());
|
||||||
ASSERT(metadata.has_value());
|
ASSERT(metadata.has_value());
|
||||||
|
|
|
@ -13,13 +13,14 @@ class GTextEditor;
|
||||||
class GStatusBar;
|
class GStatusBar;
|
||||||
|
|
||||||
class TextEditorWidget final : public GWidget {
|
class TextEditorWidget final : public GWidget {
|
||||||
|
C_OBJECT(TextEditorWidget)
|
||||||
public:
|
public:
|
||||||
TextEditorWidget();
|
|
||||||
virtual ~TextEditorWidget() override;
|
virtual ~TextEditorWidget() override;
|
||||||
void open_sesame(const String& path);
|
void open_sesame(const String& path);
|
||||||
bool request_close();
|
bool request_close();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
TextEditorWidget();
|
||||||
void set_path(const FileSystemPath& file);
|
void set_path(const FileSystemPath& file);
|
||||||
void update_title();
|
void update_title();
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,7 @@ int main(int argc, char** argv)
|
||||||
window->set_title("Text Editor");
|
window->set_title("Text Editor");
|
||||||
window->set_rect(20, 200, 640, 400);
|
window->set_rect(20, 200, 640, 400);
|
||||||
|
|
||||||
auto* text_widget = new TextEditorWidget();
|
auto text_widget = TextEditorWidget::construct();
|
||||||
window->set_main_widget(text_widget);
|
window->set_main_widget(text_widget);
|
||||||
|
|
||||||
window->on_close_request = [&]() -> GWindow::CloseRequestDecision {
|
window->on_close_request = [&]() -> GWindow::CloseRequestDecision {
|
||||||
|
|
|
@ -125,7 +125,7 @@ int main(int argc, char** argv)
|
||||||
content_title->set_preferred_size(0, 10);
|
content_title->set_preferred_size(0, 10);
|
||||||
|
|
||||||
for (auto& paragraph : page.content) {
|
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_font(Font::default_font());
|
||||||
content_text->set_text(paragraph);
|
content_text->set_text(paragraph);
|
||||||
content_text->set_text_alignment(TextAlignment::TopLeft);
|
content_text->set_text_alignment(TextAlignment::TopLeft);
|
||||||
|
|
|
@ -64,12 +64,13 @@ static int my_rand(void)
|
||||||
* Fire Widget
|
* Fire Widget
|
||||||
*/
|
*/
|
||||||
class Fire : public GWidget {
|
class Fire : public GWidget {
|
||||||
|
C_OBJECT(Fire)
|
||||||
public:
|
public:
|
||||||
explicit Fire(GWidget* parent = nullptr);
|
|
||||||
virtual ~Fire() override;
|
virtual ~Fire() override;
|
||||||
void set_stat_label(GLabel* l) { stats = l; };
|
void set_stat_label(GLabel* l) { stats = l; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit Fire(GWidget* parent = nullptr);
|
||||||
RefPtr<GraphicsBitmap> bitmap;
|
RefPtr<GraphicsBitmap> bitmap;
|
||||||
GLabel* stats;
|
GLabel* stats;
|
||||||
|
|
||||||
|
@ -220,7 +221,7 @@ int main(int argc, char** argv)
|
||||||
window->set_resizable(false);
|
window->set_resizable(false);
|
||||||
window->set_rect(100, 100, 640, 400);
|
window->set_rect(100, 100, 640, 400);
|
||||||
|
|
||||||
auto* fire = new Fire;
|
auto fire = Fire::construct();
|
||||||
window->set_main_widget(fire);
|
window->set_main_widget(fire);
|
||||||
|
|
||||||
auto time = GLabel::construct(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_rect(100, 100, 400, 400);
|
||||||
window->set_title("Paint test");
|
window->set_title("Paint test");
|
||||||
|
|
||||||
auto* test_widget = new TestWidget(nullptr);
|
auto test_widget = new TestWidget(nullptr);
|
||||||
window->set_main_widget(test_widget);
|
window->set_main_widget(test_widget);
|
||||||
|
|
||||||
test_widget->set_bitmap(load_png("/res/icons/gear16.png"));
|
test_widget->set_bitmap(load_png("/res/icons/gear16.png"));
|
||||||
|
|
|
@ -5,8 +5,8 @@
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
|
|
||||||
class VBForm : public GWidget {
|
class VBForm : public GWidget {
|
||||||
|
C_OBJECT(VBForm)
|
||||||
friend class VBWidget;
|
friend class VBWidget;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit VBForm(const String& name, GWidget* parent = nullptr);
|
explicit VBForm(const String& name, GWidget* parent = nullptr);
|
||||||
virtual ~VBForm() override;
|
virtual ~VBForm() override;
|
||||||
|
|
|
@ -6,6 +6,7 @@ class GTableView;
|
||||||
class GTextBox;
|
class GTextBox;
|
||||||
|
|
||||||
class VBPropertiesWindow final : public GWindow {
|
class VBPropertiesWindow final : public GWindow {
|
||||||
|
C_OBJECT(VBPropertiesWindow)
|
||||||
public:
|
public:
|
||||||
VBPropertiesWindow();
|
VBPropertiesWindow();
|
||||||
virtual ~VBPropertiesWindow() override;
|
virtual ~VBPropertiesWindow() override;
|
||||||
|
|
|
@ -23,10 +23,10 @@ int main(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GApplication app(argc, argv);
|
GApplication app(argc, argv);
|
||||||
|
|
||||||
auto* propbox = new VBPropertiesWindow;
|
auto propbox = VBPropertiesWindow::construct();
|
||||||
|
|
||||||
auto* form1 = new VBForm("Form1");
|
auto form1 = VBForm::construct("Form1");
|
||||||
form1->on_widget_selected = [propbox](VBWidget* widget) {
|
form1->on_widget_selected = [&](VBWidget* widget) {
|
||||||
propbox->table_view().set_model(widget ? &widget->property_model() : nullptr);
|
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&) {
|
file_menu->add_action(GAction::create("Dump Form", [&](auto&) {
|
||||||
form1->dump();
|
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");
|
form1->write_to_file("/tmp/form.frm");
|
||||||
}));
|
}));
|
||||||
menubar->add_menu(move(file_menu));
|
menubar->add_menu(move(file_menu));
|
||||||
|
|
|
@ -32,9 +32,9 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
class Field final : public GFrame {
|
class Field final : public GFrame {
|
||||||
|
C_OBJECT(Field)
|
||||||
friend class Square;
|
friend class Square;
|
||||||
friend class SquareLabel;
|
friend class SquareLabel;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent, Function<void(Size)> on_size_changed);
|
Field(GLabel& flag_label, GLabel& time_label, GButton& face_button, GWidget* parent, Function<void(Size)> on_size_changed);
|
||||||
virtual ~Field() override;
|
virtual ~Field() override;
|
||||||
|
|
|
@ -39,7 +39,7 @@ int main(int argc, char** argv)
|
||||||
auto time_icon_label = GLabel::construct(container);
|
auto time_icon_label = GLabel::construct(container);
|
||||||
time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png"));
|
time_icon_label->set_icon(GraphicsBitmap::load_from_file("/res/icons/minesweeper/timer.png"));
|
||||||
auto time_label = GLabel::construct(container);
|
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());
|
size.set_height(size.height() + container->preferred_size().height());
|
||||||
window->resize(size);
|
window->resize(size);
|
||||||
});
|
});
|
||||||
|
@ -48,7 +48,7 @@ int main(int argc, char** argv)
|
||||||
|
|
||||||
auto app_menu = make<GMenu>("Minesweeper");
|
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();
|
field->reset();
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
@ -74,16 +74,16 @@ int main(int argc, char** argv)
|
||||||
menubar->add_menu(move(app_menu));
|
menubar->add_menu(move(app_menu));
|
||||||
|
|
||||||
auto difficulty_menu = make<GMenu>("Difficulty");
|
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);
|
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);
|
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);
|
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);
|
field->set_field_size(32, 60, 350);
|
||||||
}));
|
}));
|
||||||
menubar->add_menu(move(difficulty_menu));
|
menubar->add_menu(move(difficulty_menu));
|
||||||
|
|
|
@ -5,13 +5,14 @@
|
||||||
#include <LibGUI/GWidget.h>
|
#include <LibGUI/GWidget.h>
|
||||||
|
|
||||||
class SnakeGame : public GWidget {
|
class SnakeGame : public GWidget {
|
||||||
|
C_OBJECT(SnakeGame)
|
||||||
public:
|
public:
|
||||||
explicit SnakeGame(GWidget* parent = nullptr);
|
|
||||||
virtual ~SnakeGame() override;
|
virtual ~SnakeGame() override;
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
explicit SnakeGame(GWidget* parent = nullptr);
|
||||||
virtual void paint_event(GPaintEvent&) override;
|
virtual void paint_event(GPaintEvent&) override;
|
||||||
virtual void keydown_event(GKeyEvent&) override;
|
virtual void keydown_event(GKeyEvent&) override;
|
||||||
virtual void timer_event(CTimerEvent&) override;
|
virtual void timer_event(CTimerEvent&) override;
|
||||||
|
|
|
@ -18,7 +18,7 @@ int main(int argc, char** argv)
|
||||||
window->set_title("Snake");
|
window->set_title("Snake");
|
||||||
window->set_rect(100, 100, 320, 320);
|
window->set_rect(100, 100, 320, 320);
|
||||||
|
|
||||||
auto* game = new SnakeGame;
|
auto game = SnakeGame::construct();
|
||||||
window->set_main_widget(game);
|
window->set_main_widget(game);
|
||||||
|
|
||||||
auto menubar = make<GMenuBar>();
|
auto menubar = make<GMenuBar>();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue