mirror of
https://github.com/RGBCube/serenity
synced 2025-07-24 19:47:42 +00:00
VisualBuilder: Add the first VBWidget subclass: VBButtonWidget. :^)
This commit is contained in:
parent
d73f79a2d2
commit
ead6524c0a
8 changed files with 73 additions and 11 deletions
|
@ -1,6 +1,8 @@
|
|||
OBJS = \
|
||||
VBForm.o \
|
||||
VBWidget.o \
|
||||
VBButtonWidget.o \
|
||||
VBWidgetFactory.o \
|
||||
main.o
|
||||
|
||||
APP = VisualBuilder
|
||||
|
|
17
Applications/VisualBuilder/VBButtonWidget.cpp
Normal file
17
Applications/VisualBuilder/VBButtonWidget.cpp
Normal file
|
@ -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);
|
||||
}
|
15
Applications/VisualBuilder/VBButtonWidget.h
Normal file
15
Applications/VisualBuilder/VBButtonWidget.h
Normal file
|
@ -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&);
|
||||
};
|
|
@ -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();
|
||||
|
|
|
@ -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);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,11 +35,14 @@ public:
|
|||
Rect grabber_rect(Direction) const;
|
||||
Direction grabber_at(const Point&) const;
|
||||
|
||||
void paint(GPainter&);
|
||||
virtual void paint(GPainter&);
|
||||
|
||||
virtual const char* gwidget_name() const { return "GWidget"; }
|
||||
|
||||
protected:
|
||||
explicit VBWidget(VBForm&);
|
||||
|
||||
private:
|
||||
VBWidget(VBForm&);
|
||||
|
||||
VBForm& m_form;
|
||||
Rect m_rect;
|
||||
};
|
||||
|
|
9
Applications/VisualBuilder/VBWidgetFactory.cpp
Normal file
9
Applications/VisualBuilder/VBWidgetFactory.cpp
Normal file
|
@ -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);
|
||||
}
|
12
Applications/VisualBuilder/VBWidgetFactory.h
Normal file
12
Applications/VisualBuilder/VBWidgetFactory.h
Normal file
|
@ -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&);
|
||||
};
|
Loading…
Add table
Add a link
Reference in a new issue