mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 14:37:45 +00:00
PixelPaint: Make GenericConvolutionFilterInputDialog
cancellable
Also tweaks the GUI to look a bit less...bad.
This commit is contained in:
parent
2074c9d66d
commit
d366ad8232
12 changed files with 47 additions and 56 deletions
|
@ -43,13 +43,8 @@ BoxBlurFilter<N>::~BoxBlurFilter()
|
|||
}
|
||||
|
||||
template<size_t N>
|
||||
void BoxBlurFilter<N>::apply(const Filter::Parameters& parameters)
|
||||
{
|
||||
GenericConvolutionFilter<N>::apply(parameters);
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
typename GenericConvolutionFilter<N>::Parameters BoxBlurFilter<N>::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect)
|
||||
OwnPtr<typename GenericConvolutionFilter<N>::Parameters>
|
||||
BoxBlurFilter<N>::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect)
|
||||
{
|
||||
Matrix<N, float> kernel;
|
||||
|
||||
|
@ -61,7 +56,7 @@ typename GenericConvolutionFilter<N>::Parameters BoxBlurFilter<N>::get_parameter
|
|||
|
||||
normalize(kernel);
|
||||
|
||||
return { bitmap, rect, kernel };
|
||||
return make<typename GenericConvolutionFilter<N>::Parameters>(bitmap, rect, kernel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -38,9 +38,7 @@ public:
|
|||
|
||||
virtual const char* class_name() const override { return "BoxBlurFilter"; }
|
||||
|
||||
virtual void apply(const Filter::Parameters&) override;
|
||||
|
||||
typename GenericConvolutionFilter<N>::Parameters get_parameters(Gfx::Bitmap&, const Gfx::IntRect&);
|
||||
OwnPtr<typename GenericConvolutionFilter<N>::Parameters> get_parameters(Gfx::Bitmap&, const Gfx::IntRect&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -47,6 +47,8 @@ public:
|
|||
const Gfx::IntRect& rect() const { return m_target_rect; }
|
||||
virtual bool is_generic_convolution_filter() const { return false; }
|
||||
|
||||
virtual ~Parameters() { }
|
||||
|
||||
private:
|
||||
Gfx::Bitmap& m_target_bitmap;
|
||||
Gfx::IntRect m_target_rect;
|
||||
|
|
|
@ -106,12 +106,15 @@ void GenericConvolutionFilter<N>::apply(const Filter::Parameters& parameters)
|
|||
}
|
||||
|
||||
template<size_t N>
|
||||
typename GenericConvolutionFilter<N>::Parameters GenericConvolutionFilter<N>::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect, GUI::Window* parent_window)
|
||||
OwnPtr<typename GenericConvolutionFilter<N>::Parameters>
|
||||
GenericConvolutionFilter<N>::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect, GUI::Window* parent_window)
|
||||
{
|
||||
auto input = GenericConvolutionFilterInputDialog<N>::construct(parent_window);
|
||||
input->exec();
|
||||
if (input->result() == GUI::Dialog::ExecOK)
|
||||
return make<Parameters>(bitmap, rect, input->matrix(), input->should_wrap());
|
||||
|
||||
return { bitmap, rect, input->matrix(), input->should_wrap() };
|
||||
return {};
|
||||
}
|
||||
|
||||
template<size_t N>
|
||||
|
@ -119,11 +122,18 @@ GenericConvolutionFilterInputDialog<N>::GenericConvolutionFilterInputDialog(Wind
|
|||
: Dialog(parent_window)
|
||||
{
|
||||
// FIXME: Help! Make this GUI less ugly.
|
||||
StringBuilder builder;
|
||||
builder.appendf("%zux%zu", N, N);
|
||||
builder.append(" Convolution");
|
||||
set_title(builder.string_view());
|
||||
|
||||
resize(200, 250);
|
||||
auto& main_widget = set_main_widget<GUI::Frame>();
|
||||
main_widget.set_frame_shape(Gfx::FrameShape::Container);
|
||||
main_widget.set_frame_shadow(Gfx::FrameShadow::Raised);
|
||||
main_widget.set_fill_with_background_color(true);
|
||||
main_widget.template set_layout<GUI::VerticalBoxLayout>();
|
||||
auto& layout = main_widget.template set_layout<GUI::VerticalBoxLayout>();
|
||||
layout.set_margins({ 4, 4, 4, 4 });
|
||||
|
||||
size_t index = 0;
|
||||
size_t columns = N;
|
||||
|
@ -158,7 +168,6 @@ GenericConvolutionFilterInputDialog<N>::GenericConvolutionFilterInputDialog(Wind
|
|||
wrap_checkbox.set_checked(m_should_wrap);
|
||||
|
||||
auto& button = main_widget.template add<GUI::Button>("Done");
|
||||
button.set_button_style(Gfx::ButtonStyle::CoolBar);
|
||||
button.on_click = [&](auto) {
|
||||
m_should_wrap = wrap_checkbox.is_checked();
|
||||
if (norm_checkbox.is_checked())
|
||||
|
|
|
@ -79,7 +79,7 @@ public:
|
|||
|
||||
virtual void apply(const Filter::Parameters&) override;
|
||||
|
||||
Parameters get_parameters(Gfx::Bitmap&, const Gfx::IntRect&, GUI::Window* parent_window);
|
||||
OwnPtr<Parameters> get_parameters(Gfx::Bitmap&, const Gfx::IntRect&, GUI::Window* parent_window);
|
||||
};
|
||||
|
||||
template<size_t N>
|
||||
|
|
|
@ -36,17 +36,12 @@ LaplacianFilter::~LaplacianFilter()
|
|||
{
|
||||
}
|
||||
|
||||
void LaplacianFilter::apply(const Filter::Parameters& parameters)
|
||||
{
|
||||
GenericConvolutionFilter::apply(parameters);
|
||||
}
|
||||
|
||||
GenericConvolutionFilter<3>::Parameters LaplacianFilter::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect, bool diagonal)
|
||||
OwnPtr<GenericConvolutionFilter<3>::Parameters> LaplacianFilter::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect, bool diagonal)
|
||||
{
|
||||
if (diagonal)
|
||||
return { bitmap, rect, Matrix<3, float>(-1, -1, -1, -1, 8, -1, -1, -1, -1) };
|
||||
return make<GenericConvolutionFilter<3>::Parameters>(bitmap, rect, Matrix<3, float>(-1, -1, -1, -1, 8, -1, -1, -1, -1));
|
||||
|
||||
return { bitmap, rect, Matrix<3, float>(0, -1, 0, -1, 4, -1, 0, -1, 0) };
|
||||
return make<GenericConvolutionFilter<3>::Parameters>(bitmap, rect, Matrix<3, float>(0, -1, 0, -1, 4, -1, 0, -1, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,9 +37,7 @@ public:
|
|||
|
||||
virtual const char* class_name() const override { return "LaplacianFilter"; }
|
||||
|
||||
virtual void apply(const Filter::Parameters&) override;
|
||||
|
||||
GenericConvolutionFilter::Parameters get_parameters(Gfx::Bitmap&, const Gfx::IntRect&, bool diagonal);
|
||||
OwnPtr<GenericConvolutionFilter::Parameters> get_parameters(Gfx::Bitmap&, const Gfx::IntRect&, bool diagonal);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -37,14 +37,9 @@ SharpenFilter::~SharpenFilter()
|
|||
{
|
||||
}
|
||||
|
||||
void SharpenFilter::apply(const Filter::Parameters& parameters)
|
||||
OwnPtr<GenericConvolutionFilter<3>::Parameters> SharpenFilter::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect)
|
||||
{
|
||||
GenericConvolutionFilter::apply(parameters);
|
||||
}
|
||||
|
||||
GenericConvolutionFilter<3>::Parameters SharpenFilter::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect)
|
||||
{
|
||||
return { bitmap, rect, Matrix<3, float>(0, -1, 0, -1, 5, -1, 0, -1, 0) };
|
||||
return make<GenericConvolutionFilter<3>::Parameters>(bitmap, rect, Matrix<3, float>(0, -1, 0, -1, 5, -1, 0, -1, 0));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -37,9 +37,7 @@ public:
|
|||
|
||||
virtual const char* class_name() const override { return "SharpenFilter"; }
|
||||
|
||||
virtual void apply(const Filter::Parameters&) override;
|
||||
|
||||
GenericConvolutionFilter::Parameters get_parameters(Gfx::Bitmap&, const Gfx::IntRect&);
|
||||
OwnPtr<GenericConvolutionFilter::Parameters> get_parameters(Gfx::Bitmap&, const Gfx::IntRect&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -38,14 +38,9 @@ SpatialGaussianBlurFilter<N, T>::~SpatialGaussianBlurFilter()
|
|||
{
|
||||
}
|
||||
|
||||
template<size_t N, typename T>
|
||||
void SpatialGaussianBlurFilter<N, T>::apply(const Filter::Parameters& parameters)
|
||||
{
|
||||
GenericConvolutionFilter<N>::apply(parameters);
|
||||
}
|
||||
|
||||
template<size_t N, typename _T>
|
||||
typename GenericConvolutionFilter<N>::Parameters SpatialGaussianBlurFilter<N, _T>::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect)
|
||||
OwnPtr<typename GenericConvolutionFilter<N>::Parameters>
|
||||
SpatialGaussianBlurFilter<N, _T>::get_parameters(Gfx::Bitmap& bitmap, const Gfx::IntRect& rect)
|
||||
{
|
||||
Matrix<N, float> kernel;
|
||||
auto sigma = 1.0f;
|
||||
|
@ -60,7 +55,7 @@ typename GenericConvolutionFilter<N>::Parameters SpatialGaussianBlurFilter<N, _T
|
|||
|
||||
normalize(kernel);
|
||||
|
||||
return { bitmap, rect, kernel };
|
||||
return make<typename GenericConvolutionFilter<N>::Parameters>(bitmap, rect, kernel);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -39,9 +39,7 @@ public:
|
|||
|
||||
virtual const char* class_name() const override { return "SpatialGaussianBlurFilter"; }
|
||||
|
||||
virtual void apply(const Filter::Parameters&) override;
|
||||
|
||||
typename GenericConvolutionFilter<N>::Parameters get_parameters(Gfx::Bitmap&, const Gfx::IntRect&);
|
||||
OwnPtr<typename GenericConvolutionFilter<N>::Parameters> get_parameters(Gfx::Bitmap&, const Gfx::IntRect&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue