| 1 | // Aseprite |
| 2 | // Copyright (C) 2022 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2017 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_COMMANDS_FILTERS_FILTER_WINDOW_H_INCLUDED |
| 9 | #define APP_COMMANDS_FILTERS_FILTER_WINDOW_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/commands/filters/filter_preview.h" |
| 13 | #include "app/commands/filters/filter_target_buttons.h" |
| 14 | #include "filters/tiled_mode.h" |
| 15 | #include "ui/box.h" |
| 16 | #include "ui/button.h" |
| 17 | #include "ui/window.h" |
| 18 | |
| 19 | namespace app { |
| 20 | class FilterManagerImpl; |
| 21 | |
| 22 | using namespace filters; |
| 23 | |
| 24 | // A generic window to show parameters for a Filter with integrated |
| 25 | // preview in the current editor. |
| 26 | class FilterWindow : public ui::Window { |
| 27 | public: |
| 28 | enum WithChannels { WithChannelsSelector, WithoutChannelsSelector }; |
| 29 | enum WithTiled { WithTiledCheckBox, WithoutTiledCheckBox }; |
| 30 | |
| 31 | FilterWindow(const char* title, const char* cfgSection, |
| 32 | FilterManagerImpl* filterMgr, |
| 33 | WithChannels withChannels, |
| 34 | WithTiled withTiled, |
| 35 | TiledMode tiledMode = TiledMode::NONE); |
| 36 | ~FilterWindow(); |
| 37 | |
| 38 | // Shows the window as modal (blocking interface), and returns true |
| 39 | // if the user pressed "OK" button (i.e. wants to apply the filter |
| 40 | // with the current settings). |
| 41 | bool doModal(); |
| 42 | |
| 43 | // Starts (or restart) the preview procedure. You should call this |
| 44 | // method after the user modifies parameters of the Filter. |
| 45 | void restartPreview(); |
| 46 | |
| 47 | protected: |
| 48 | // Changes the target buttons. Used by convolution matrix filter |
| 49 | // which specified different targets for each matrix. |
| 50 | void setNewTarget(Target target); |
| 51 | |
| 52 | // Returns the container where derived classes should put controls. |
| 53 | ui::Widget* getContainer() { return &m_container; } |
| 54 | |
| 55 | void onOk(ui::Event& ev); |
| 56 | void onCancel(ui::Event& ev); |
| 57 | void onShowPreview(ui::Event& ev); |
| 58 | void onTargetButtonChange(); |
| 59 | void onTiledChange(); |
| 60 | |
| 61 | // Derived classes WithTiledCheckBox should set its filter's tiled |
| 62 | // mode overriding this method. |
| 63 | virtual void setupTiledMode(TiledMode tiledMode) { } |
| 64 | |
| 65 | // Stops the filter preview background thread, you should call |
| 66 | // this before you modify the parameters of the Filter. |
| 67 | void stopPreview(); |
| 68 | |
| 69 | private: |
| 70 | const char* m_cfgSection; |
| 71 | FilterManagerImpl* m_filterMgr; |
| 72 | ui::Box m_hbox; |
| 73 | ui::Box m_vbox; |
| 74 | ui::Box m_container; |
| 75 | ui::Button m_okButton; |
| 76 | ui::Button m_cancelButton; |
| 77 | FilterPreview m_preview; |
| 78 | FilterTargetButtons m_targetButton; |
| 79 | ui::CheckBox m_showPreview; |
| 80 | ui::CheckBox* m_tiledCheck; |
| 81 | }; |
| 82 | |
| 83 | } // namespace app |
| 84 | |
| 85 | #endif |
| 86 | |