2019-06-12 05:58:31 +02:00
|
|
|
#include "ToolboxWidget.h"
|
2019-06-14 18:51:57 +02:00
|
|
|
#include "BucketTool.h"
|
2019-06-16 11:33:20 +02:00
|
|
|
#include "SprayTool.h"
|
2019-06-14 18:51:57 +02:00
|
|
|
#include "PaintableWidget.h"
|
|
|
|
#include "PenTool.h"
|
2019-06-22 12:05:35 +02:00
|
|
|
#include "PickerTool.h"
|
2019-06-28 11:11:06 +02:00
|
|
|
#include "EraseTool.h"
|
2019-06-12 05:58:31 +02:00
|
|
|
#include <LibGUI/GBoxLayout.h>
|
|
|
|
#include <LibGUI/GButton.h>
|
2019-07-18 10:15:00 +02:00
|
|
|
#include <LibDraw/PNGLoader.h>
|
2019-06-12 05:58:31 +02:00
|
|
|
|
2019-06-14 18:51:57 +02:00
|
|
|
class ToolButton final : public GButton {
|
|
|
|
public:
|
|
|
|
ToolButton(const String& name, GWidget* parent, OwnPtr<Tool>&& tool)
|
2019-06-15 17:52:53 +02:00
|
|
|
: GButton(parent)
|
2019-06-14 18:51:57 +02:00
|
|
|
, m_tool(move(tool))
|
|
|
|
{
|
2019-06-15 17:52:53 +02:00
|
|
|
set_tooltip(name);
|
2019-06-14 18:51:57 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const Tool& tool() const { return *m_tool; }
|
|
|
|
Tool& tool() { return *m_tool; }
|
|
|
|
|
2019-06-23 10:00:02 +02:00
|
|
|
virtual void context_menu_event(GContextMenuEvent& event) override
|
|
|
|
{
|
|
|
|
m_tool->on_contextmenu(event);
|
|
|
|
}
|
|
|
|
|
2019-06-14 18:51:57 +02:00
|
|
|
private:
|
|
|
|
OwnPtr<Tool> m_tool;
|
|
|
|
};
|
|
|
|
|
2019-06-12 05:58:31 +02:00
|
|
|
ToolboxWidget::ToolboxWidget(GWidget* parent)
|
|
|
|
: GFrame(parent)
|
|
|
|
{
|
2019-06-30 09:23:16 +02:00
|
|
|
set_background_color(Color::WarmGray);
|
2019-06-12 05:58:31 +02:00
|
|
|
set_fill_with_background_color(true);
|
|
|
|
|
|
|
|
set_frame_thickness(1);
|
|
|
|
set_frame_shape(FrameShape::Panel);
|
|
|
|
set_frame_shadow(FrameShadow::Raised);
|
|
|
|
|
|
|
|
set_size_policy(SizePolicy::Fixed, SizePolicy::Fill);
|
2019-07-20 22:39:24 +02:00
|
|
|
set_preferred_size(48, 0);
|
2019-06-12 05:58:31 +02:00
|
|
|
|
|
|
|
set_layout(make<GBoxLayout>(Orientation::Vertical));
|
|
|
|
layout()->set_margins({ 4, 4, 4, 4 });
|
|
|
|
|
2019-06-15 17:52:53 +02:00
|
|
|
auto add_tool = [&](const StringView& name, const StringView& icon_name, OwnPtr<Tool>&& tool) {
|
2019-06-14 18:51:57 +02:00
|
|
|
auto* button = new ToolButton(name, this, move(tool));
|
2019-06-12 05:58:31 +02:00
|
|
|
button->set_size_policy(SizePolicy::Fill, SizePolicy::Fixed);
|
2019-07-20 22:39:24 +02:00
|
|
|
button->set_preferred_size(0, 32);
|
2019-06-12 05:58:31 +02:00
|
|
|
button->set_checkable(true);
|
|
|
|
button->set_exclusive(true);
|
2019-06-14 18:51:57 +02:00
|
|
|
|
2019-07-08 15:38:44 +02:00
|
|
|
button->set_icon(load_png(String::format("/res/icons/paintbrush/%s.png", String(icon_name).characters())));
|
2019-06-15 17:52:53 +02:00
|
|
|
|
2019-06-14 18:51:57 +02:00
|
|
|
button->on_checked = [button](auto checked) {
|
|
|
|
if (checked)
|
|
|
|
PaintableWidget::the().set_tool(&button->tool());
|
|
|
|
else
|
|
|
|
PaintableWidget::the().set_tool(nullptr);
|
|
|
|
};
|
2019-06-12 05:58:31 +02:00
|
|
|
};
|
|
|
|
|
2019-06-15 17:52:53 +02:00
|
|
|
add_tool("Pen", "pen", make<PenTool>());
|
|
|
|
add_tool("Bucket Fill", "bucket", make<BucketTool>());
|
2019-06-21 09:22:32 +02:00
|
|
|
add_tool("Spray", "spray", make<SprayTool>());
|
2019-06-22 12:05:35 +02:00
|
|
|
add_tool("Color Picker", "picker", make<PickerTool>());
|
2019-06-30 09:40:15 +02:00
|
|
|
add_tool("Erase", "eraser", make<EraseTool>());
|
2019-06-12 05:58:31 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ToolboxWidget::~ToolboxWidget()
|
|
|
|
{
|
|
|
|
}
|