mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 07:08:10 +00:00
PixelPaint: Tool properties panel
Each tool can have its own set of properties that can be modified through a panel on the right side. The tools I've added properties for are: Pen: Thickness Brush: Size Hardness Spray: Thickness Density Bucket: Threshold
This commit is contained in:
parent
544f2f3c96
commit
afd52e2576
13 changed files with 324 additions and 12 deletions
|
@ -28,9 +28,13 @@
|
|||
#include "ImageEditor.h"
|
||||
#include "Layer.h"
|
||||
#include <LibGUI/Action.h>
|
||||
#include <LibGUI/BoxLayout.h>
|
||||
#include <LibGUI/Label.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
#include <LibGUI/Slider.h>
|
||||
#include <LibGfx/Color.h>
|
||||
#include <LibGfx/Rect.h>
|
||||
#include <utility>
|
||||
|
||||
namespace PixelPaint {
|
||||
|
||||
|
@ -70,7 +74,7 @@ void BrushTool::draw_point(Gfx::Bitmap& bitmap, const Gfx::Color& color, const G
|
|||
if (distance >= m_size)
|
||||
continue;
|
||||
|
||||
auto falloff = (1.0 - (distance / (float)m_size)) * 0.2;
|
||||
auto falloff = (1.0 - (distance / (float)m_size)) * (1.0f / (100 - m_hardness));
|
||||
auto pixel_color = color;
|
||||
pixel_color.set_alpha(falloff * 255);
|
||||
bitmap.set_pixel(x, y, bitmap.get_pixel(x, y).blend(pixel_color));
|
||||
|
@ -111,4 +115,52 @@ void BrushTool::draw_line(Gfx::Bitmap& bitmap, const Gfx::Color& color, const Gf
|
|||
}
|
||||
}
|
||||
|
||||
GUI::Widget* BrushTool::get_properties_widget()
|
||||
{
|
||||
if (!m_properties_widget) {
|
||||
m_properties_widget = GUI::Widget::construct();
|
||||
m_properties_widget->set_layout<GUI::VerticalBoxLayout>();
|
||||
|
||||
auto& size_container = m_properties_widget->add<GUI::Widget>();
|
||||
size_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
size_container.set_preferred_size(0, 20);
|
||||
size_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
auto& size_label = size_container.add<GUI::Label>("Size:");
|
||||
size_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
size_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
size_label.set_preferred_size(80, 20);
|
||||
|
||||
auto& size_slider = size_container.add<GUI::HorizontalSlider>();
|
||||
size_slider.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
size_slider.set_preferred_size(0, 20);
|
||||
size_slider.set_range(1, 100);
|
||||
size_slider.set_value(m_size);
|
||||
size_slider.on_value_changed = [this](int value) {
|
||||
m_size = value;
|
||||
};
|
||||
|
||||
auto& hardness_container = m_properties_widget->add<GUI::Widget>();
|
||||
hardness_container.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
hardness_container.set_preferred_size(0, 20);
|
||||
hardness_container.set_layout<GUI::HorizontalBoxLayout>();
|
||||
|
||||
auto& hardness_label = hardness_container.add<GUI::Label>("Hardness:");
|
||||
hardness_label.set_text_alignment(Gfx::TextAlignment::CenterLeft);
|
||||
hardness_label.set_size_policy(GUI::SizePolicy::Fixed, GUI::SizePolicy::Fixed);
|
||||
hardness_label.set_preferred_size(80, 20);
|
||||
|
||||
auto& hardness_slider = hardness_container.add<GUI::HorizontalSlider>();
|
||||
hardness_slider.set_size_policy(GUI::SizePolicy::Fill, GUI::SizePolicy::Fixed);
|
||||
hardness_slider.set_preferred_size(0, 20);
|
||||
hardness_slider.set_range(1, 99);
|
||||
hardness_slider.set_value(m_hardness);
|
||||
hardness_slider.on_value_changed = [this](int value) {
|
||||
m_hardness = value;
|
||||
};
|
||||
}
|
||||
|
||||
return m_properties_widget.ptr();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue