diff options
author | Andreas Kling <awesomekling@gmail.com> | 2019-04-11 02:49:10 +0200 |
---|---|---|
committer | Andreas Kling <awesomekling@gmail.com> | 2019-04-11 02:49:10 +0200 |
commit | ead6524c0afa342ac5e47420a86047e2c003eba9 (patch) | |
tree | 4c26eb098a0419a950e986f253564960802d4967 /Applications/VisualBuilder | |
parent | d73f79a2d203d0a838a49bd436f29d7ed7e32339 (diff) | |
download | serenity-ead6524c0afa342ac5e47420a86047e2c003eba9.zip |
VisualBuilder: Add the first VBWidget subclass: VBButtonWidget. :^)
Diffstat (limited to 'Applications/VisualBuilder')
-rw-r--r-- | Applications/VisualBuilder/Makefile | 2 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBButtonWidget.cpp | 17 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBButtonWidget.h | 15 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBForm.cpp | 14 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBWidget.cpp | 6 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBWidget.h | 9 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBWidgetFactory.cpp | 9 | ||||
-rw-r--r-- | Applications/VisualBuilder/VBWidgetFactory.h | 12 |
8 files changed, 73 insertions, 11 deletions
diff --git a/Applications/VisualBuilder/Makefile b/Applications/VisualBuilder/Makefile index cacbff9524..cea96f817c 100644 --- a/Applications/VisualBuilder/Makefile +++ b/Applications/VisualBuilder/Makefile @@ -1,6 +1,8 @@ OBJS = \ VBForm.o \ VBWidget.o \ + VBButtonWidget.o \ + VBWidgetFactory.o \ main.o APP = VisualBuilder diff --git a/Applications/VisualBuilder/VBButtonWidget.cpp b/Applications/VisualBuilder/VBButtonWidget.cpp new file mode 100644 index 0000000000..d6dccc7731 --- /dev/null +++ b/Applications/VisualBuilder/VBButtonWidget.cpp @@ -0,0 +1,17 @@ +#include "VBButtonWidget.h" +#include <SharedGraphics/StylePainter.h> +#include <LibGUI/GPainter.h> + +VBButtonWidget::VBButtonWidget(VBForm& form) + : VBWidget(form) +{ +} + +VBButtonWidget::~VBButtonWidget() +{ +} + +void VBButtonWidget::paint(GPainter& painter) +{ + StylePainter::paint_button(painter, rect(), ButtonStyle::Normal, false); +} diff --git a/Applications/VisualBuilder/VBButtonWidget.h b/Applications/VisualBuilder/VBButtonWidget.h new file mode 100644 index 0000000000..91a92905df --- /dev/null +++ b/Applications/VisualBuilder/VBButtonWidget.h @@ -0,0 +1,15 @@ +#pragma once + +#include "VBWidget.h" + +class VBButtonWidget : public VBWidget { +public: + static Retained<VBButtonWidget> create(VBForm& form) { return adopt(*new VBButtonWidget(form)); } + virtual ~VBButtonWidget() override; + + virtual void paint(GPainter&) override; + virtual const char* gwidget_name() const { return "GButton"; } + +private: + explicit VBButtonWidget(VBForm&); +}; diff --git a/Applications/VisualBuilder/VBForm.cpp b/Applications/VisualBuilder/VBForm.cpp index b7133cc8a5..f07e22f278 100644 --- a/Applications/VisualBuilder/VBForm.cpp +++ b/Applications/VisualBuilder/VBForm.cpp @@ -1,5 +1,6 @@ #include "VBForm.h" #include "VBWidget.h" +#include "VBWidgetFactory.h" #include <LibGUI/GPainter.h> VBForm::VBForm(const String& name, GWidget* parent) @@ -15,6 +16,10 @@ VBForm::VBForm(const String& name, GWidget* parent) auto box2 = VBWidget::create(*this); box2->set_rect({ 100, 100, 161, 141 }); m_widgets.append(move(box2)); + + auto button1 = VBWidgetFactory::create("GButton", *this); + button1->set_rect({ 200, 50, 101, 21 }); + m_widgets.append(move(button1)); } VBForm::~VBForm() @@ -34,6 +39,11 @@ void VBForm::paint_event(GPaintEvent& event) for (auto& widget : m_widgets) { widget->paint(painter); + if (widget->is_selected()) { + for_each_direction([&] (Direction direction) { + painter.fill_rect(widget->grabber_rect(direction), Color::Black); + }); + } } } @@ -151,8 +161,8 @@ void VBForm::mousemove_event(GMouseEvent& event) new_rect.set_x(new_rect.x() - (new_rect.x() % m_grid_size)); new_rect.set_y(new_rect.y() - (new_rect.y() % m_grid_size)); - new_rect.set_width(new_rect.width() - (new_rect.width() % m_grid_size)); - new_rect.set_height(new_rect.height() - (new_rect.height() % m_grid_size)); + new_rect.set_width(new_rect.width() - (new_rect.width() % m_grid_size) + 1); + new_rect.set_height(new_rect.height() - (new_rect.height() % m_grid_size) + 1); m_selected_widget->set_rect(new_rect); update(); diff --git a/Applications/VisualBuilder/VBWidget.cpp b/Applications/VisualBuilder/VBWidget.cpp index 32bd355c31..da54240889 100644 --- a/Applications/VisualBuilder/VBWidget.cpp +++ b/Applications/VisualBuilder/VBWidget.cpp @@ -56,10 +56,4 @@ void VBWidget::paint(GPainter& painter) { painter.fill_rect(m_rect, Color::White); painter.draw_rect(m_rect, Color::Black); - - if (is_selected()) { - for_each_direction([&] (Direction direction) { - painter.fill_rect(grabber_rect(direction), Color::Black); - }); - } } diff --git a/Applications/VisualBuilder/VBWidget.h b/Applications/VisualBuilder/VBWidget.h index 5489ae882e..521ee87cd3 100644 --- a/Applications/VisualBuilder/VBWidget.h +++ b/Applications/VisualBuilder/VBWidget.h @@ -35,11 +35,14 @@ public: Rect grabber_rect(Direction) const; Direction grabber_at(const Point&) const; - void paint(GPainter&); + virtual void paint(GPainter&); -private: - VBWidget(VBForm&); + virtual const char* gwidget_name() const { return "GWidget"; } + +protected: + explicit VBWidget(VBForm&); +private: VBForm& m_form; Rect m_rect; }; diff --git a/Applications/VisualBuilder/VBWidgetFactory.cpp b/Applications/VisualBuilder/VBWidgetFactory.cpp new file mode 100644 index 0000000000..83f2afa02f --- /dev/null +++ b/Applications/VisualBuilder/VBWidgetFactory.cpp @@ -0,0 +1,9 @@ +#include "VBWidgetFactory.h" +#include "VBButtonWidget.h" + +Retained<VBWidget> VBWidgetFactory::create(const String& widget_name, VBForm& form) +{ + if (widget_name == "GButton") + return VBButtonWidget::create(form); + return VBWidget::create(form); +} diff --git a/Applications/VisualBuilder/VBWidgetFactory.h b/Applications/VisualBuilder/VBWidgetFactory.h new file mode 100644 index 0000000000..486887fd3c --- /dev/null +++ b/Applications/VisualBuilder/VBWidgetFactory.h @@ -0,0 +1,12 @@ +#pragma once + +#include <AK/AKString.h> +#include <AK/Retained.h> + +class VBForm; +class VBWidget; + +class VBWidgetFactory { +public: + static Retained<VBWidget> create(const String& widget_name, VBForm&); +}; |