1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 08:57:34 +00:00

PaintBrush: Make little icons for the pen and bucket tools.

This commit is contained in:
Andreas Kling 2019-06-15 17:52:53 +02:00
parent dcbddb4f8c
commit 694b4a64bd
3 changed files with 8 additions and 4 deletions

View file

@ -4,13 +4,15 @@
#include "PenTool.h" #include "PenTool.h"
#include <LibGUI/GBoxLayout.h> #include <LibGUI/GBoxLayout.h>
#include <LibGUI/GButton.h> #include <LibGUI/GButton.h>
#include <SharedGraphics/PNGLoader.h>
class ToolButton final : public GButton { class ToolButton final : public GButton {
public: public:
ToolButton(const String& name, GWidget* parent, OwnPtr<Tool>&& tool) ToolButton(const String& name, GWidget* parent, OwnPtr<Tool>&& tool)
: GButton(name, parent) : GButton(parent)
, m_tool(move(tool)) , m_tool(move(tool))
{ {
set_tooltip(name);
} }
const Tool& tool() const { return *m_tool; } const Tool& tool() const { return *m_tool; }
@ -36,13 +38,15 @@ ToolboxWidget::ToolboxWidget(GWidget* parent)
set_layout(make<GBoxLayout>(Orientation::Vertical)); set_layout(make<GBoxLayout>(Orientation::Vertical));
layout()->set_margins({ 4, 4, 4, 4 }); layout()->set_margins({ 4, 4, 4, 4 });
auto add_tool = [&](const StringView& 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 = new ToolButton(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);
button->set_exclusive(true); button->set_exclusive(true);
button->set_icon(load_png(String::format("/res/icons/paintbrush/%s.png", icon_name.characters())));
button->on_checked = [button](auto checked) { button->on_checked = [button](auto checked) {
if (checked) if (checked)
PaintableWidget::the().set_tool(&button->tool()); PaintableWidget::the().set_tool(&button->tool());
@ -51,8 +55,8 @@ ToolboxWidget::ToolboxWidget(GWidget* parent)
}; };
}; };
add_tool("Pen", make<PenTool>()); add_tool("Pen", "pen", make<PenTool>());
add_tool("Buck", make<BucketTool>()); add_tool("Bucket Fill", "bucket", make<BucketTool>());
} }
ToolboxWidget::~ToolboxWidget() ToolboxWidget::~ToolboxWidget()

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 333 B