1 | // Aseprite |
2 | // Copyright (C) 2019-2021 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_UTIL_CLIPBOARD_H_INCLUDED |
9 | #define APP_UTIL_CLIPBOARD_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "doc/cel_list.h" |
13 | #include "doc/image_ref.h" |
14 | #include "gfx/point.h" |
15 | #include "gfx/size.h" |
16 | #include "ui/base.h" |
17 | #include "ui/clipboard_delegate.h" |
18 | |
19 | #include <memory> |
20 | |
21 | namespace doc { |
22 | class Image; |
23 | class Mask; |
24 | class Palette; |
25 | class PalettePicks; |
26 | class Tileset; |
27 | } |
28 | |
29 | namespace app { |
30 | class Context; |
31 | class ContextReader; |
32 | class ContextWriter; |
33 | class Doc; |
34 | class DocRange; |
35 | class Site; |
36 | class Tx; |
37 | |
38 | enum class ClipboardFormat { |
39 | None, |
40 | Image, |
41 | DocRange, |
42 | PaletteEntries, |
43 | Tilemap, |
44 | Tileset, |
45 | }; |
46 | |
47 | class Clipboard : public ui::ClipboardDelegate { |
48 | public: |
49 | static Clipboard* instance(); |
50 | |
51 | Clipboard(); |
52 | ~Clipboard(); |
53 | |
54 | ClipboardFormat format() const; |
55 | void getDocumentRangeInfo(Doc** document, DocRange* range); |
56 | |
57 | void clearMaskFromCels(Tx& tx, |
58 | Doc* doc, |
59 | const Site& site, |
60 | const doc::CelList& cels, |
61 | const bool deselectMask); |
62 | |
63 | void clearContent(); |
64 | void cut(ContextWriter& context); |
65 | void copy(const ContextReader& context); |
66 | void copyMerged(const ContextReader& context); |
67 | void copyRange(const ContextReader& context, const DocRange& range); |
68 | void copyImage(const doc::Image* image, |
69 | const doc::Mask* mask, |
70 | const doc::Palette* palette); |
71 | void copyTilemap(const doc::Image* image, |
72 | const doc::Mask* mask, |
73 | const doc::Palette* pal, |
74 | const doc::Tileset* tileset); |
75 | void copyPalette(const doc::Palette* palette, |
76 | const doc::PalettePicks& picks); |
77 | void paste(Context* ctx, const bool interactive); |
78 | |
79 | doc::ImageRef getImage(doc::Palette* palette); |
80 | |
81 | // Returns true and fills the specified "size"" with the image's |
82 | // size in the clipboard, or return false in case that the clipboard |
83 | // doesn't contain an image at all. |
84 | bool getImageSize(gfx::Size& size); |
85 | |
86 | doc::Palette* getPalette(); |
87 | const doc::PalettePicks& getPalettePicks(); |
88 | |
89 | // ui::ClipboardDelegate impl |
90 | void setClipboardText(const std::string& text) override; |
91 | bool getClipboardText(std::string& text) override; |
92 | |
93 | private: |
94 | void setData(doc::Image* image, |
95 | doc::Mask* mask, |
96 | doc::Palette* palette, |
97 | doc::Tileset* tileset, |
98 | bool set_native_clipboard, |
99 | bool image_source_is_transparent); |
100 | bool copyFromDocument(const Site& site, bool merged = false); |
101 | |
102 | // Native clipboard |
103 | void clearNativeContent(); |
104 | void registerNativeFormats(); |
105 | bool hasNativeBitmap() const; |
106 | bool setNativeBitmap(const doc::Image* image, |
107 | const doc::Mask* mask, |
108 | const doc::Palette* palette, |
109 | const doc::Tileset* tileset = nullptr); |
110 | bool getNativeBitmap(doc::Image** image, |
111 | doc::Mask** mask, |
112 | doc::Palette** palette, |
113 | doc::Tileset** tileset); |
114 | bool getNativeBitmapSize(gfx::Size* size); |
115 | |
116 | struct Data; |
117 | std::unique_ptr<Data> m_data; |
118 | }; |
119 | |
120 | } // namespace app |
121 | |
122 | #endif |
123 | |