1 #pragma once 2 3 #ifndef PREVIEW_FX_MANAGER 4 #define PREVIEW_FX_MANAGER 5 6 #include <QObject> 7 #include <QMap> 8 #include "trenderer.h" 9 #include "tfx.h" 10 11 //===================================================================================== 12 13 // Forward declarations 14 15 class FlipBook; 16 class PreviewFxInstance; 17 class TXsheet; 18 19 //===================================================================================== 20 21 //=============================== 22 // PreviewFxManager class 23 //------------------------------- 24 25 /*! 26 Manages the 'Preview Fx' requests and updates all contextually opened FlipBooks 27 when needed. 28 The class provides the medium between the 'Preview Fx' command and management of 29 both Toonz 30 rendering classes and Flipbooks. 31 \n \n 32 The showNewPreview() method invocation takes place when users activate the 33 'Preview' command from the 34 right-click menu of fxs in the schematic. It inizializes a TRenderer object and 35 starts the 36 render of passed fx over the preview properties range; at the same time, a new 37 Flipbook is opened to 38 visualize the images produced by the render process as frames are finalized. 39 \n \n 40 The refreshView() command is available to update an fx's view upon request (this 41 is typically handled 42 by flipbooks). 43 The manager always renders the area strictly necessary to correctly update all 44 flipbooks' current view; 45 in particular, previously rendered portions of flipbook views are retained, and 46 excluded from further 47 calculations. 48 \n 49 Observe that invalidation signals coming from TXshLevelHandle, TFxHandle and 50 TXsheetHandle classes are 51 automatically intercepted to update all FlipBooks created under the manager. 52 \n \n 53 Additional reset() methods are available to clear the manager about a single fx 54 or the whole scene's fxs. 55 56 \sa FlipBook, TXshLevelHandle, TFxHandle, TXsheetHandle classes. 57 */ 58 class PreviewFxManager final : public QObject { 59 Q_OBJECT 60 61 TThread::Mutex m_mutex; 62 QMap<unsigned long, PreviewFxInstance *> m_previewInstances; 63 64 private: 65 PreviewFxManager(); 66 ~PreviewFxManager(); 67 68 // Not implemented 69 PreviewFxManager(const PreviewFxManager &); 70 void operator=(const PreviewFxManager &); 71 72 public: 73 //! Returns the instance of the PreviewFxManager object. 74 static PreviewFxManager *instance(); 75 76 static void suspendRendering(bool suspend); 77 78 //! Starts a preview instance for passed fx. If explicitly requested, a new 79 //! flipbook is created to 80 //! host the preview, otherwise the Preference settings are used. In the 81 //! former case, the view refresh 82 //! must be explicitly invoked using the refreshView() command, in order to 83 //! allow changes of the flipbook's 84 //! view affine before it. 85 //! The associated flipbook is returned, in case it has been created. 86 FlipBook *showNewPreview(TFxP fx, bool forceFlipbook = false); 87 88 //! Updates the fx's preview on the associated flipbooks' current views. 89 void refreshView(TFxP fx); 90 91 //! Detaches the specified flipbook from the manager's control. Optionally, 92 //! the flipbooks may keep the already 93 //! previewed images instead of discarding them - however, observe that these 94 //! images may be \b cloned from the 95 //! preview originals, in case some flipbook is still actively previewing the 96 //! same fx. 97 void detach(FlipBook *flipbook); 98 99 //! Freezes the specified flipbook. 100 void freeze(FlipBook *flipbook); 101 void unfreeze(FlipBook *flipbook); 102 103 //! Resets the PreviewFxManager for input fx. All previously rendered previews 104 //! for it are cleared. 105 void reset(TFxP fx); 106 //! Resets the PreviewFxManager together with all internal rendering objects. 107 void reset(bool detachFlipbooks = true); 108 //! Resets the PreviewFxManager for input fx at frame. The previous rendered 109 //! preview is cleared. 110 void reset(TFxP fx, int frame); 111 112 // return true if the preview fx instance for specified fx is with sub-camera 113 // activated 114 bool isSubCameraActive(TFxP fx); 115 116 private: 117 friend class PreviewFxInstance; 118 void emitRenderedFrame(unsigned long fxId, 119 const TRenderPort::RenderData &renderData); 120 void emitStartedFrame(unsigned long fxId, 121 const TRenderPort::RenderData &renderData); 122 123 signals: 124 125 void startedFrame(unsigned long fxId, TRenderPort::RenderData renderData); 126 void renderedFrame(unsigned long fxId, TRenderPort::RenderData renderData); 127 void refreshViewRects(unsigned long fxId); 128 129 protected slots: 130 131 void onLevelChanged(); 132 void onFxChanged(); 133 void onXsheetChanged(); 134 void onObjectChanged(bool isDragging); 135 136 void onStartedFrame(unsigned long fxId, TRenderPort::RenderData renderData); 137 void onRenderedFrame(unsigned long fxId, TRenderPort::RenderData renderData); 138 139 void onRefreshViewRects(unsigned long id); 140 }; 141 142 #endif 143