mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 06:58:11 +00:00
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.
This commit is contained in:
parent
d71b0e4638
commit
e8be8f7b6d
2 changed files with 15 additions and 5 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue