1 | // Aseprite |
---|---|
2 | // Copyright (C) 2019-2020 Igara Studio S.A. |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifndef APP_ACTIVE_SITE_HANDLER_H_INCLUDED |
8 | #define APP_ACTIVE_SITE_HANDLER_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "app/doc_observer.h" |
12 | #include "app/doc_range.h" |
13 | #include "doc/frame.h" |
14 | #include "doc/object_id.h" |
15 | #include "doc/palette_picks.h" |
16 | |
17 | #include <map> |
18 | |
19 | namespace doc { |
20 | class Layer; |
21 | } |
22 | |
23 | namespace app { |
24 | class Doc; |
25 | class Site; |
26 | |
27 | // Pseudo-DocViews to handle active layer/frame in a non-UI context |
28 | // per Doc. |
29 | // |
30 | // TODO we could move code to handle active frame/layer from |
31 | // Timeline to this class. |
32 | class ActiveSiteHandler : public DocObserver { |
33 | public: |
34 | ActiveSiteHandler(); |
35 | virtual ~ActiveSiteHandler(); |
36 | |
37 | void addDoc(Doc* doc); |
38 | void removeDoc(Doc* doc); |
39 | void getActiveSiteForDoc(Doc* doc, Site* site); |
40 | void setActiveLayerInDoc(Doc* doc, doc::Layer* layer); |
41 | void setActiveFrameInDoc(Doc* doc, doc::frame_t frame); |
42 | void setRangeInDoc(Doc* doc, const DocRange& range); |
43 | void setSelectedColorsInDoc(Doc* doc, const doc::PalettePicks& picks); |
44 | void setSelectedTilesInDoc(Doc* doc, const doc::PalettePicks& picks); |
45 | |
46 | private: |
47 | // DocObserver impl |
48 | void onAddLayer(DocEvent& ev) override; |
49 | void onAddFrame(DocEvent& ev) override; |
50 | void onBeforeRemoveLayer(DocEvent& ev) override; |
51 | void onRemoveFrame(DocEvent& ev) override; |
52 | |
53 | // Active data for a document |
54 | struct Data { |
55 | doc::ObjectId layer; |
56 | doc::frame_t frame; |
57 | DocRange range; |
58 | doc::PalettePicks selectedColors; |
59 | doc::PalettePicks selectedTiles; |
60 | }; |
61 | |
62 | Data& getData(Doc* doc); |
63 | |
64 | std::map<Doc*, Data> m_data; |
65 | }; |
66 | |
67 | } // namespace app |
68 | |
69 | #endif |
70 |