diff options
author | Tobias Christiansen <tobyase@serenityos.org> | 2022-03-16 19:54:34 +0100 |
---|---|---|
committer | Andreas Kling <kling@serenityos.org> | 2022-03-16 21:45:31 +0100 |
commit | e8be8f7b6d700e60fd1f3e6438f8d4080ba205cc (patch) | |
tree | 6c02c281fbb2e85944a666cad7d6e545d02ceb73 /Userland/Applications | |
parent | d71b0e46381c2bb211233bb72d9f7f457a72c5d4 (diff) | |
download | serenity-e8be8f7b6d700e60fd1f3e6438f8d4080ba205cc.zip |
PixelPaint: Add Timer for displaying previews of filters
This way the preview image is not generated on _every_ update_preview()
call but rather only if the last update_preview() was longer than 100ms
ago.
When rapidly moving the Slider for large blur values in the
FastBoxBlurFilter with the Gaussian approximation the usage became
noticeably sliggush because we queued a lot of preview generation just
to throw it away immediately. This patch fixes that.
Diffstat (limited to 'Userland/Applications')
-rw-r--r-- | Userland/Applications/PixelPaint/Filters/Filter.cpp | 14 | ||||
-rw-r--r-- | Userland/Applications/PixelPaint/Filters/Filter.h | 6 |
2 files changed, 15 insertions, 5 deletions
diff --git a/Userland/Applications/PixelPaint/Filters/Filter.cpp b/Userland/Applications/PixelPaint/Filters/Filter.cpp index 4cd3c708eb..567ab10a5f 100644 --- a/Userland/Applications/PixelPaint/Filters/Filter.cpp +++ b/Userland/Applications/PixelPaint/Filters/Filter.cpp @@ -11,6 +11,16 @@ namespace PixelPaint { +Filter::Filter(ImageEditor* editor) + : m_editor(editor) + , m_update_timer(Core::Timer::create_single_shot(100, [&] { + if (on_settings_change) + on_settings_change(); + })) +{ + m_update_timer->set_active(false); +} + RefPtr<GUI::Widget> Filter::get_settings_widget() { if (!m_settings_widget) { @@ -39,8 +49,6 @@ void Filter::apply() const void Filter::update_preview() { - if (on_settings_change) - on_settings_change(); + m_update_timer->restart(); } - } diff --git a/Userland/Applications/PixelPaint/Filters/Filter.h b/Userland/Applications/PixelPaint/Filters/Filter.h index 3d201a0282..cfb8f0e57b 100644 --- a/Userland/Applications/PixelPaint/Filters/Filter.h +++ b/Userland/Applications/PixelPaint/Filters/Filter.h @@ -24,8 +24,7 @@ public: virtual ~Filter() {}; - Filter(ImageEditor* editor) - : m_editor(editor) {}; + Filter(ImageEditor* editor); Function<void(void)> on_settings_change; @@ -33,6 +32,9 @@ protected: ImageEditor* m_editor { nullptr }; RefPtr<GUI::Widget> m_settings_widget { nullptr }; void update_preview(); + +private: + NonnullRefPtr<Core::Timer> m_update_timer; }; } |