diff --git a/src/app/commands/filters/filter_window.cpp b/src/app/commands/filters/filter_window.cpp index 6b0a1b284..7929fd97f 100644 --- a/src/app/commands/filters/filter_window.cpp +++ b/src/app/commands/filters/filter_window.cpp @@ -17,7 +17,10 @@ #include "app/ini_file.h" #include "app/modules/gui.h" #include "app/pref/preferences.h" +#include "app/tools/tool_box.h" #include "app/ui/editor/editor.h" +#include "app/ui/context_bar.h" +#include "app/ui/toolbar.h" namespace app { @@ -43,6 +46,8 @@ FilterWindow::FilterWindow(const char* title, const char* cfgSection, , m_tiledCheck(withTiled == WithTiledCheckBox ? new CheckBox(Strings::filters_tiled()) : nullptr) + , m_editor(nullptr) + , m_oldTool(nullptr) { m_okButton.processMnemonicFromText(); m_cancelButton.processMnemonicFromText(); @@ -85,10 +90,21 @@ FilterWindow::FilterWindow(const char* title, const char* cfgSection, // OK is magnetic (the default button) m_okButton.setFocusMagnet(true); + + if (Editor::activeEditor()) { + m_editor = Editor::activeEditor(); + m_editor->add_observer(this); + m_oldTool = m_editor->getCurrentEditorTool(); + tools::Tool* hand = App::instance()->toolBox()->getToolById(tools::WellKnownTools::Hand); + ToolBar::instance()->selectTool(hand); + } } FilterWindow::~FilterWindow() { + if (m_oldTool) + ToolBar::instance()->selectTool(m_oldTool); + // Save window configuration save_window_pos(this, m_cfgSection); @@ -97,6 +113,9 @@ FilterWindow::~FilterWindow() // Save cels target button Preferences::instance().filters.celsTarget(m_targetButton.celsTarget()); + + if (m_editor) + m_editor->remove_observer(this); } bool FilterWindow::doModal() @@ -131,6 +150,18 @@ bool FilterWindow::doModal() return result; } +void FilterWindow::onBroadcastMouseMessage(const gfx::Point& screenPos, + ui::WidgetsList& targets) { + // Add the Filter Window as receptor of mouse events. + targets.push_back(this); + // Also add the editor + if (m_editor) + targets.push_back(ui::View::getView(m_editor)); + // and add the context bar. + if (App::instance()->contextBar()) + targets.push_back(App::instance()->contextBar()); +} + void FilterWindow::restartPreview() { bool state = m_showPreview.isSelected(); @@ -201,4 +232,14 @@ void FilterWindow::stopPreview() m_preview.stop(); } +void FilterWindow::onScrollChanged(Editor* editor) +{ + restartPreview(); +} + +void FilterWindow::onZoomChanged(Editor* editor) +{ + restartPreview(); +} + } // namespace app diff --git a/src/app/commands/filters/filter_window.h b/src/app/commands/filters/filter_window.h index f9c5e205e..72436714b 100644 --- a/src/app/commands/filters/filter_window.h +++ b/src/app/commands/filters/filter_window.h @@ -11,6 +11,7 @@ #include "app/commands/filters/filter_preview.h" #include "app/commands/filters/filter_target_buttons.h" +#include "app/ui/editor/editor.h" #include "filters/tiled_mode.h" #include "ui/box.h" #include "ui/button.h" @@ -23,7 +24,8 @@ namespace app { // A generic window to show parameters for a Filter with integrated // preview in the current editor. - class FilterWindow : public ui::Window { + class FilterWindow : public ui::Window, + public EditorObserver { public: enum WithChannels { WithChannelsSelector, WithoutChannelsSelector }; enum WithTiled { WithTiledCheckBox, WithoutTiledCheckBox }; @@ -49,6 +51,9 @@ namespace app { // which specified different targets for each matrix. void setNewTarget(Target target); + void onBroadcastMouseMessage(const gfx::Point& screenPos, + ui::WidgetsList& targets) override; + // Returns the container where derived classes should put controls. ui::Widget* getContainer() { return &m_container; } @@ -67,6 +72,10 @@ namespace app { void stopPreview(); private: + // EditorObserver impl + void onScrollChanged(Editor* editor) override; + void onZoomChanged(Editor* editor) override; + const char* m_cfgSection; FilterManagerImpl* m_filterMgr; ui::Box m_hbox; @@ -78,6 +87,8 @@ namespace app { FilterTargetButtons m_targetButton; ui::CheckBox m_showPreview; ui::CheckBox* m_tiledCheck; + Editor* m_editor; + tools::Tool* m_oldTool; }; } // namespace app