summaryrefslogtreecommitdiff
path: root/Applications/PixelPaint
diff options
context:
space:
mode:
authorAnotherTest <ali.mpfard@gmail.com>2020-08-01 12:39:06 +0430
committerAndreas Kling <kling@serenityos.org>2020-08-01 17:44:40 +0200
commitd366ad8232b943a3035e16cbe0a9b6b9bd8bdc87 (patch)
tree160208417eb2a410e20362bdf3c3a46c9ce00056 /Applications/PixelPaint
parent2074c9d66d9f031265b0be4aee4b2d5e1d0941f8 (diff)
downloadserenity-d366ad8232b943a3035e16cbe0a9b6b9bd8bdc87.zip
PixelPaint: Make `GenericConvolutionFilterInputDialog` cancellable
Also tweaks the GUI to look a bit less...bad.
Diffstat (limited to 'Applications/PixelPaint')
-rw-r--r--Applications/PixelPaint/Filters/BoxBlurFilter.cpp11
-rw-r--r--Applications/PixelPaint/Filters/BoxBlurFilter.h4
-rw-r--r--Applications/PixelPaint/Filters/Filter.h2
-rw-r--r--Applications/PixelPaint/Filters/GenericConvolutionFilter.cpp17
-rw-r--r--Applications/PixelPaint/Filters/GenericConvolutionFilter.h2
-rw-r--r--Applications/PixelPaint/Filters/LaplacianFilter.cpp11
-rw-r--r--Applications/PixelPaint/Filters/LaplacianFilter.h4
-rw-r--r--Applications/PixelPaint/Filters/SharpenFilter.cpp9
-rw-r--r--Applications/PixelPaint/Filters/SharpenFilter.h4
-rw-r--r--Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.cpp11
-rw-r--r--Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.h4
-rw-r--r--Applications/PixelPaint/main.cpp24
12 files changed, 47 insertions, 56 deletions
diff --git a/Applications/PixelPaint/Filters/BoxBlurFilter.cpp b/Applications/PixelPaint/Filters/BoxBlurFilter.cpp
index 4da1c1d158..f6f6a6e2ce 100644
--- a/Applications/PixelPaint/Filters/BoxBlurFilter.cpp
+++ b/Applications/PixelPaint/Filters/BoxBlurFilter.cpp
@@ -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);
}
}
diff --git a/Applications/PixelPaint/Filters/BoxBlurFilter.h b/Applications/PixelPaint/Filters/BoxBlurFilter.h
index 760eb17df9..e96b00dd88 100644
--- a/Applications/PixelPaint/Filters/BoxBlurFilter.h
+++ b/Applications/PixelPaint/Filters/BoxBlurFilter.h
@@ -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&);
};
}
diff --git a/Applications/PixelPaint/Filters/Filter.h b/Applications/PixelPaint/Filters/Filter.h
index c2146324b1..b780751545 100644
--- a/Applications/PixelPaint/Filters/Filter.h
+++ b/Applications/PixelPaint/Filters/Filter.h
@@ -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;
diff --git a/Applications/PixelPaint/Filters/GenericConvolutionFilter.cpp b/Applications/PixelPaint/Filters/GenericConvolutionFilter.cpp
index 161beef25a..bfd8c4a503 100644
--- a/Applications/PixelPaint/Filters/GenericConvolutionFilter.cpp
+++ b/Applications/PixelPaint/Filters/GenericConvolutionFilter.cpp
@@ -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())
diff --git a/Applications/PixelPaint/Filters/GenericConvolutionFilter.h b/Applications/PixelPaint/Filters/GenericConvolutionFilter.h
index e32fd5f417..a6ff6f1d67 100644
--- a/Applications/PixelPaint/Filters/GenericConvolutionFilter.h
+++ b/Applications/PixelPaint/Filters/GenericConvolutionFilter.h
@@ -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>
diff --git a/Applications/PixelPaint/Filters/LaplacianFilter.cpp b/Applications/PixelPaint/Filters/LaplacianFilter.cpp
index e71ca17e1e..808fafd818 100644
--- a/Applications/PixelPaint/Filters/LaplacianFilter.cpp
+++ b/Applications/PixelPaint/Filters/LaplacianFilter.cpp
@@ -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));
}
}
diff --git a/Applications/PixelPaint/Filters/LaplacianFilter.h b/Applications/PixelPaint/Filters/LaplacianFilter.h
index 0184c47e55..0691e60a26 100644
--- a/Applications/PixelPaint/Filters/LaplacianFilter.h
+++ b/Applications/PixelPaint/Filters/LaplacianFilter.h
@@ -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);
};
}
diff --git a/Applications/PixelPaint/Filters/SharpenFilter.cpp b/Applications/PixelPaint/Filters/SharpenFilter.cpp
index 4d6f34ed43..c6152c085d 100644
--- a/Applications/PixelPaint/Filters/SharpenFilter.cpp
+++ b/Applications/PixelPaint/Filters/SharpenFilter.cpp
@@ -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));
}
}
diff --git a/Applications/PixelPaint/Filters/SharpenFilter.h b/Applications/PixelPaint/Filters/SharpenFilter.h
index 2fe26bb3fd..d1bdb836fa 100644
--- a/Applications/PixelPaint/Filters/SharpenFilter.h
+++ b/Applications/PixelPaint/Filters/SharpenFilter.h
@@ -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&);
};
}
diff --git a/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.cpp b/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.cpp
index 007df1adaa..fd3c2478fd 100644
--- a/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.cpp
+++ b/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.cpp
@@ -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);
}
}
diff --git a/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.h b/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.h
index 38e56d501b..aed206d345 100644
--- a/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.h
+++ b/Applications/PixelPaint/Filters/SpatialGaussianBlurFilter.h
@@ -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&);
};
}
diff --git a/Applications/PixelPaint/main.cpp b/Applications/PixelPaint/main.cpp
index 24bcffa377..d22a797044 100644
--- a/Applications/PixelPaint/main.cpp
+++ b/Applications/PixelPaint/main.cpp
@@ -207,44 +207,51 @@ int main(int argc, char** argv)
edge_detect_submenu.add_action(GUI::Action::create("Laplacian (cardinal)", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::LaplacianFilter filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect(), false));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect(), false))
+ filter.apply(*parameters);
}
}));
edge_detect_submenu.add_action(GUI::Action::create("Laplacian (diagonal)", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::LaplacianFilter filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect(), true));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect(), true))
+ filter.apply(*parameters);
}
}));
auto& blur_submenu = spatial_filters_menu.add_submenu("Blur and Sharpen");
blur_submenu.add_action(GUI::Action::create("Gaussian Blur (3x3)", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::SpatialGaussianBlurFilter<3> filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect()));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect()))
+ filter.apply(*parameters);
}
}));
blur_submenu.add_action(GUI::Action::create("Gaussian Blur (5x5)", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::SpatialGaussianBlurFilter<5> filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect()));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect()))
+ filter.apply(*parameters);
}
}));
blur_submenu.add_action(GUI::Action::create("Box Blur (3x3)", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::BoxBlurFilter<3> filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect()));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect()))
+ filter.apply(*parameters);
}
}));
blur_submenu.add_action(GUI::Action::create("Box Blur (5x5)", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::BoxBlurFilter<5> filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect()));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect()))
+ filter.apply(*parameters);
}
}));
blur_submenu.add_action(GUI::Action::create("Sharpen", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::SharpenFilter filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect()));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect()))
+ filter.apply(*parameters);
}
}));
@@ -252,7 +259,8 @@ int main(int argc, char** argv)
spatial_filters_menu.add_action(GUI::Action::create("Generic 5x5 Convolution", [&](auto&) {
if (auto* layer = image_editor.active_layer()) {
PixelPaint::GenericConvolutionFilter<5> filter;
- filter.apply(filter.get_parameters(layer->bitmap(), layer->rect(), window));
+ if (auto parameters = filter.get_parameters(layer->bitmap(), layer->rect(), window))
+ filter.apply(*parameters);
}
}));