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>
|
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-22 07:05:35 -03:00
|
|
|
#include "PickerTool.h"
|
2021-09-17 04:54:55 -03:00
|
|
|
#include "../ImageEditor.h"
|
|
|
|
|
#include "../Layer.h"
|
2021-09-01 01:12:15 -03:00
|
|
|
#include <LibGUI/BoxLayout.h>
|
|
|
|
|
#include <LibGUI/CheckBox.h>
|
2019-06-22 07:05:35 -03:00
|
|
|
|
2020-05-20 15:35:35 -03:00
|
|
|
namespace PixelPaint {
|
2020-05-12 18:44:46 -03:00
|
|
|
|
2019-06-22 07:05:35 -03:00
|
|
|
PickerTool::PickerTool()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PickerTool::~PickerTool()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 05:07:24 -03:00
|
|
|
void PickerTool::on_mousedown(Layer* layer, MouseEvent& event)
|
2019-06-22 07:05:35 -03:00
|
|
|
{
|
2021-09-01 01:12:15 -03:00
|
|
|
auto& position = event.layer_event().position();
|
|
|
|
|
|
|
|
|
|
Color color;
|
|
|
|
|
if (m_sample_all_layers) {
|
|
|
|
|
color = m_editor->image().color_at(position);
|
|
|
|
|
} else {
|
|
|
|
|
if (!layer || !layer->rect().contains(position))
|
|
|
|
|
return;
|
|
|
|
|
color = layer->bitmap().get_pixel(position);
|
|
|
|
|
}
|
2021-08-25 05:07:24 -03:00
|
|
|
|
2021-09-01 01:12:15 -03:00
|
|
|
// We picked a transparent pixel, do nothing.
|
|
|
|
|
if (!color.alpha())
|
2019-06-22 07:05:35 -03:00
|
|
|
return;
|
2021-09-01 01:12:15 -03:00
|
|
|
|
|
|
|
|
if (event.layer_event().button() == GUI::MouseButton::Left)
|
2020-05-13 07:47:47 -03:00
|
|
|
m_editor->set_primary_color(color);
|
2021-09-01 01:12:15 -03:00
|
|
|
else if (event.layer_event().button() == GUI::MouseButton::Right)
|
2020-05-13 07:47:47 -03:00
|
|
|
m_editor->set_secondary_color(color);
|
2020-05-12 18:44:46 -03:00
|
|
|
}
|
|
|
|
|
|
2021-09-01 01:12:15 -03:00
|
|
|
GUI::Widget* PickerTool::get_properties_widget()
|
|
|
|
|
{
|
|
|
|
|
if (!m_properties_widget) {
|
|
|
|
|
m_properties_widget = GUI::Widget::construct();
|
|
|
|
|
m_properties_widget->set_layout<GUI::VerticalBoxLayout>();
|
|
|
|
|
|
|
|
|
|
auto& sample_checkbox = m_properties_widget->add<GUI::CheckBox>("Sample all layers");
|
|
|
|
|
sample_checkbox.set_checked(m_sample_all_layers);
|
|
|
|
|
sample_checkbox.on_checked = [&](bool value) {
|
|
|
|
|
m_sample_all_layers = value;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return m_properties_widget.ptr();
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-22 07:05:35 -03:00
|
|
|
}
|