2020-01-18 05:38:21 -03:00
|
|
|
/*
|
2021-05-15 18:08:17 -03:00
|
|
|
* Copyright (c) 2018-2021, Andreas Kling <kling@serenityos.org>
|
2022-02-10 16:28:48 -03:00
|
|
|
* Copyright (c) 2022, the SerenityOS developers.
|
2020-01-18 05:38:21 -03:00
|
|
|
*
|
2021-04-22 05:24:48 -03:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 05:38:21 -03:00
|
|
|
*/
|
|
|
|
|
|
2019-06-12 00:58:31 -03:00
|
|
|
#include "ToolboxWidget.h"
|
2021-09-17 04:54:55 -03:00
|
|
|
#include "Tools/BrushTool.h"
|
|
|
|
|
#include "Tools/BucketTool.h"
|
|
|
|
|
#include "Tools/CloneTool.h"
|
|
|
|
|
#include "Tools/EllipseTool.h"
|
|
|
|
|
#include "Tools/EraseTool.h"
|
|
|
|
|
#include "Tools/GuideTool.h"
|
|
|
|
|
#include "Tools/LineTool.h"
|
|
|
|
|
#include "Tools/MoveTool.h"
|
|
|
|
|
#include "Tools/PenTool.h"
|
|
|
|
|
#include "Tools/PickerTool.h"
|
|
|
|
|
#include "Tools/RectangleSelectTool.h"
|
|
|
|
|
#include "Tools/RectangleTool.h"
|
|
|
|
|
#include "Tools/SprayTool.h"
|
2022-08-29 20:20:20 -03:00
|
|
|
#include "Tools/WandSelectTool.h"
|
2021-09-17 04:54:55 -03:00
|
|
|
#include "Tools/ZoomTool.h"
|
2020-05-13 09:22:10 -03:00
|
|
|
#include <LibGUI/Action.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Button.h>
|
2021-05-15 18:08:17 -03:00
|
|
|
#include <LibGUI/Toolbar.h>
|
2019-06-12 00:58:31 -03:00
|
|
|
|
2021-05-15 19:03:13 -03:00
|
|
|
REGISTER_WIDGET(PixelPaint, ToolboxWidget);
|
|
|
|
|
|
2020-05-20 15:35:35 -03:00
|
|
|
namespace PixelPaint {
|
2020-05-12 18:44:46 -03:00
|
|
|
|
2020-02-23 06:57:42 -03:00
|
|
|
ToolboxWidget::ToolboxWidget()
|
2019-06-12 00:58:31 -03:00
|
|
|
{
|
|
|
|
|
set_fill_with_background_color(true);
|
|
|
|
|
|
2021-05-15 18:08:17 -03:00
|
|
|
set_fixed_width(26);
|
2019-06-12 00:58:31 -03:00
|
|
|
|
2020-03-04 05:43:54 -03:00
|
|
|
set_layout<GUI::VerticalBoxLayout>();
|
2021-05-15 13:22:17 -03:00
|
|
|
layout()->set_spacing(0);
|
Userland+LibGUI: Add shorthand versions of the Margins constructor
This allows for typing [8] instead of [8, 8, 8, 8] to specify the same
margin on all edges, for example. The constructors follow CSS' style of
specifying margins. The added constructors are:
- Margins(int all): Sets the same margin on all edges.
- Margins(int vertical, int horizontal): Sets the first argument to top
and bottom margins, and the second argument to left and right margins.
- Margins(int top, int vertical, int bottom): Sets the first argument to
the top margin, the second argument to the left and right margins,
and the third argument to the bottom margin.
2021-08-16 21:11:38 -03:00
|
|
|
layout()->set_margins(2);
|
2019-06-12 00:58:31 -03:00
|
|
|
|
2020-05-13 09:48:17 -03:00
|
|
|
m_action_group.set_exclusive(true);
|
|
|
|
|
m_action_group.set_unchecking_allowed(false);
|
|
|
|
|
|
2021-05-15 18:08:17 -03:00
|
|
|
m_toolbar = add<GUI::Toolbar>(Gfx::Orientation::Vertical);
|
2022-07-27 09:14:28 -03:00
|
|
|
m_toolbar->set_collapsible(true);
|
2021-04-04 19:50:34 -03:00
|
|
|
setup_tools();
|
2020-07-23 14:53:48 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ToolboxWidget::setup_tools()
|
|
|
|
|
{
|
2022-08-21 15:25:52 -03:00
|
|
|
auto add_tool = [&](StringView icon_name, GUI::Shortcut const& shortcut, NonnullOwnPtr<Tool> tool) {
|
|
|
|
|
auto action = GUI::Action::create_checkable(tool->tool_name(), shortcut, Gfx::Bitmap::try_load_from_file(String::formatted("/res/icons/pixelpaint/{}.png", icon_name)).release_value_but_fixme_should_propagate_errors(),
|
2021-05-15 18:08:17 -03:00
|
|
|
[this, tool = tool.ptr()](auto& action) {
|
2021-09-12 22:36:01 -03:00
|
|
|
if (action.is_checked()) {
|
2021-05-15 18:08:17 -03:00
|
|
|
on_tool_selection(tool);
|
2021-09-12 22:36:01 -03:00
|
|
|
m_active_tool = tool;
|
|
|
|
|
} else {
|
2021-05-15 18:08:17 -03:00
|
|
|
on_tool_selection(nullptr);
|
2021-09-12 22:36:01 -03:00
|
|
|
}
|
2021-05-15 18:08:17 -03:00
|
|
|
});
|
|
|
|
|
m_action_group.add_action(action);
|
|
|
|
|
auto& button = m_toolbar->add_action(action);
|
|
|
|
|
button.on_context_menu_request = [action = action.ptr(), tool = tool.ptr()](auto& event) {
|
|
|
|
|
action->activate();
|
|
|
|
|
tool->on_tool_button_contextmenu(event);
|
|
|
|
|
};
|
|
|
|
|
tool->set_action(action);
|
|
|
|
|
m_tools.append(move(tool));
|
2019-06-12 00:58:31 -03:00
|
|
|
};
|
|
|
|
|
|
2022-08-21 15:25:52 -03:00
|
|
|
add_tool("move"sv, { 0, Key_M }, make<MoveTool>());
|
|
|
|
|
add_tool("pen"sv, { 0, Key_N }, make<PenTool>());
|
|
|
|
|
add_tool("brush"sv, { 0, Key_P }, make<BrushTool>());
|
|
|
|
|
add_tool("bucket"sv, { Mod_Shift, Key_B }, make<BucketTool>());
|
|
|
|
|
add_tool("spray"sv, { Mod_Shift, Key_S }, make<SprayTool>());
|
|
|
|
|
add_tool("picker"sv, { 0, Key_O }, make<PickerTool>());
|
|
|
|
|
add_tool("eraser"sv, { Mod_Shift, Key_E }, make<EraseTool>());
|
|
|
|
|
add_tool("line"sv, { Mod_Ctrl | Mod_Shift, Key_L }, make<LineTool>());
|
|
|
|
|
add_tool("rectangle"sv, { Mod_Ctrl | Mod_Shift, Key_R }, make<RectangleTool>());
|
|
|
|
|
add_tool("circle"sv, { Mod_Ctrl | Mod_Shift, Key_E }, make<EllipseTool>());
|
|
|
|
|
add_tool("zoom"sv, { 0, Key_Z }, make<ZoomTool>());
|
|
|
|
|
add_tool("rectangle-select"sv, { 0, Key_R }, make<RectangleSelectTool>());
|
2022-08-29 20:20:20 -03:00
|
|
|
add_tool("wand-select"sv, { 0, Key_W }, make<WandSelectTool>());
|
2022-08-21 15:25:52 -03:00
|
|
|
add_tool("guides"sv, { 0, Key_G }, make<GuideTool>());
|
|
|
|
|
add_tool("clone"sv, { 0, Key_C }, make<CloneTool>());
|
2019-06-12 00:58:31 -03:00
|
|
|
}
|
|
|
|
|
|
2020-05-12 18:44:46 -03:00
|
|
|
}
|