| 1 | // Aseprite |
| 2 | // Copyright (C) 2019-2020 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2018 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_UI_DOC_VIEW_H_INCLUDED |
| 9 | #define APP_UI_DOC_VIEW_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/doc_observer.h" |
| 13 | #include "app/ui/input_chain_element.h" |
| 14 | #include "app/ui/tabs.h" |
| 15 | #include "app/ui/workspace_view.h" |
| 16 | #include "ui/box.h" |
| 17 | |
| 18 | namespace ui { |
| 19 | class View; |
| 20 | } |
| 21 | |
| 22 | namespace app { |
| 23 | class Doc; |
| 24 | class Editor; |
| 25 | class Site; |
| 26 | |
| 27 | class DocViewPreviewDelegate { |
| 28 | public: |
| 29 | virtual ~DocViewPreviewDelegate() { } |
| 30 | virtual void onScrollOtherEditor(Editor* editor) = 0; |
| 31 | virtual void onDisposeOtherEditor(Editor* editor) = 0; |
| 32 | virtual void onPreviewOtherEditor(Editor* editor) = 0; |
| 33 | virtual void onTagChangeEditor(Editor* editor, DocEvent& ev) = 0; |
| 34 | }; |
| 35 | |
| 36 | class DocView : public ui::Box, |
| 37 | public TabView, |
| 38 | public app::DocObserver, |
| 39 | public WorkspaceView, |
| 40 | public app::InputChainElement { |
| 41 | public: |
| 42 | enum Type { |
| 43 | Normal, |
| 44 | Preview |
| 45 | }; |
| 46 | |
| 47 | DocView(Doc* document, Type type, |
| 48 | DocViewPreviewDelegate* previewDelegate); |
| 49 | ~DocView(); |
| 50 | |
| 51 | Doc* document() const { return m_document; } |
| 52 | Editor* editor() { return m_editor; } |
| 53 | ui::View* viewWidget() const { return m_view; } |
| 54 | void getSite(Site* site) const; |
| 55 | |
| 56 | bool isPreview() { return m_type == Preview; } |
| 57 | |
| 58 | // TabView implementation |
| 59 | std::string getTabText() override; |
| 60 | TabIcon getTabIcon() override; |
| 61 | gfx::Color getTabColor() override; |
| 62 | |
| 63 | // WorkspaceView implementation |
| 64 | ui::Widget* getContentWidget() override { return this; } |
| 65 | bool canCloneWorkspaceView() override { return true; } |
| 66 | WorkspaceView* cloneWorkspaceView() override; |
| 67 | void onWorkspaceViewSelected() override; |
| 68 | void onClonedFrom(WorkspaceView* from) override; |
| 69 | bool onCloseView(Workspace* workspace, bool quitting) override; |
| 70 | void (Workspace* workspace) override; |
| 71 | InputChainElement* onGetInputChainElement() override { return this; } |
| 72 | |
| 73 | // DocObserver implementation |
| 74 | void onGeneralUpdate(DocEvent& ev) override; |
| 75 | void onSpritePixelsModified(DocEvent& ev) override; |
| 76 | void onLayerMergedDown(DocEvent& ev) override; |
| 77 | void onAddLayer(DocEvent& ev) override; |
| 78 | void onAddFrame(DocEvent& ev) override; |
| 79 | void onRemoveFrame(DocEvent& ev) override; |
| 80 | void onTagChange(DocEvent& ev) override; |
| 81 | void onAddCel(DocEvent& ev) override; |
| 82 | void onAfterRemoveCel(DocEvent& ev) override; |
| 83 | void onTotalFramesChanged(DocEvent& ev) override; |
| 84 | void onLayerRestacked(DocEvent& ev) override; |
| 85 | void onTilesetChanged(DocEvent& ev) override; |
| 86 | |
| 87 | // InputChainElement impl |
| 88 | void onNewInputPriority(InputChainElement* element, |
| 89 | const ui::Message* msg) override; |
| 90 | bool onCanCut(Context* ctx) override; |
| 91 | bool onCanCopy(Context* ctx) override; |
| 92 | bool onCanPaste(Context* ctx) override; |
| 93 | bool onCanClear(Context* ctx) override; |
| 94 | bool onCut(Context* ctx) override; |
| 95 | bool onCopy(Context* ctx) override; |
| 96 | bool onPaste(Context* ctx) override; |
| 97 | bool onClear(Context* ctx) override; |
| 98 | void onCancel(Context* ctx) override; |
| 99 | |
| 100 | protected: |
| 101 | bool onProcessMessage(ui::Message* msg) override; |
| 102 | |
| 103 | private: |
| 104 | Type m_type; |
| 105 | Doc* m_document; |
| 106 | ui::View* m_view; |
| 107 | DocViewPreviewDelegate* m_previewDelegate; |
| 108 | Editor* m_editor; |
| 109 | }; |
| 110 | |
| 111 | } // namespace app |
| 112 | |
| 113 | #endif |
| 114 | |