2020-01-18 05:38:21 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
2021-09-13 17:48:22 -03:00
|
|
|
* Copyright (c) 2021, Mustafa Quraish <mustafa@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-14 13:51:57 -03:00
|
|
|
#include "PenTool.h"
|
2021-09-17 04:54:55 -03:00
|
|
|
#include "../ImageEditor.h"
|
|
|
|
|
#include "../Layer.h"
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Action.h>
|
2020-10-15 14:57:07 -03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/Label.h>
|
2020-02-06 16:33:02 -03:00
|
|
|
#include <LibGUI/Menu.h>
|
|
|
|
|
#include <LibGUI/Painter.h>
|
2021-08-05 14:36:38 -03:00
|
|
|
#include <LibGUI/ValueSlider.h>
|
2019-06-14 13:51:57 -03:00
|
|
|
|
2020-05-20 15:35:35 -03:00
|
|
|
namespace PixelPaint {
|
2020-05-12 18:44:46 -03:00
|
|
|
|
2019-06-14 13:51:57 -03:00
|
|
|
PenTool::PenTool()
|
|
|
|
|
{
|
2021-09-08 00:16:13 -03:00
|
|
|
set_size(1);
|
2019-06-14 13:51:57 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-08 00:16:13 -03:00
|
|
|
void PenTool::draw_point(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& point)
|
2019-06-14 13:51:57 -03:00
|
|
|
{
|
2021-09-08 00:16:13 -03:00
|
|
|
GUI::Painter painter(bitmap);
|
|
|
|
|
painter.draw_line(point, point, color, size());
|
2019-06-14 13:51:57 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-08 00:16:13 -03:00
|
|
|
void PenTool::draw_line(Gfx::Bitmap& bitmap, Gfx::Color const& color, Gfx::IntPoint const& start, Gfx::IntPoint const& end)
|
2019-06-14 13:51:57 -03:00
|
|
|
{
|
2021-09-08 00:16:13 -03:00
|
|
|
GUI::Painter painter(bitmap);
|
|
|
|
|
painter.draw_line(start, end, color, size());
|
2019-06-14 13:51:57 -03:00
|
|
|
}
|
2019-06-23 05:00:02 -03:00
|
|
|
|
2020-10-15 14:57:07 -03:00
|
|
|
GUI::Widget* PenTool::get_properties_widget()
|
|
|
|
|
{
|
|
|
|
|
if (!m_properties_widget) {
|
|
|
|
|
m_properties_widget = GUI::Widget::construct();
|
|
|
|
|
m_properties_widget->set_layout<GUI::VerticalBoxLayout>();
|
|
|
|
|
|
2021-09-08 00:16:13 -03:00
|
|
|
auto& size_container = m_properties_widget->add<GUI::Widget>();
|
|
|
|
|
size_container.set_fixed_height(20);
|
|
|
|
|
size_container.set_layout<GUI::HorizontalBoxLayout>();
|
2020-10-15 14:57:07 -03:00
|
|
|
|
2021-09-08 00:16:13 -03:00
|
|
|
auto& size_label = size_container.add<GUI::Label>("Thickness:");
|
|
|
|
|
size_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
|
|
|
|
size_label.set_fixed_size(80, 20);
|
2020-10-15 14:57:07 -03:00
|
|
|
|
2021-09-08 00:16:13 -03:00
|
|
|
auto& size_slider = size_container.add<GUI::ValueSlider>(Orientation::Horizontal, "px");
|
|
|
|
|
size_slider.set_range(1, 20);
|
|
|
|
|
size_slider.set_value(size());
|
2021-08-03 07:46:10 -03:00
|
|
|
|
2021-09-08 00:16:13 -03:00
|
|
|
size_slider.on_change = [&](int value) {
|
|
|
|
|
set_size(value);
|
2020-10-15 14:57:07 -03:00
|
|
|
};
|
2021-09-08 00:16:13 -03:00
|
|
|
set_primary_slider(&size_slider);
|
2020-10-15 14:57:07 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m_properties_widget.ptr();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-12 18:44:46 -03:00
|
|
|
}
|