1 | // Aseprite |
2 | // Copyright (C) 2019-2020 Igara Studio S.A. |
3 | // Copyright (C) 2001-2016 David Capello |
4 | // |
5 | // This program is distributed under the terms of |
6 | // the End-User License Agreement for Aseprite. |
7 | |
8 | #ifndef APP_CMD_COPY_REGION_H_INCLUDED |
9 | #define APP_CMD_COPY_REGION_H_INCLUDED |
10 | #pragma once |
11 | |
12 | #include "app/cmd.h" |
13 | #include "app/cmd/with_image.h" |
14 | #include "base/buffer.h" |
15 | #include "doc/tile.h" |
16 | #include "gfx/point.h" |
17 | #include "gfx/region.h" |
18 | |
19 | namespace doc { |
20 | class Tileset; |
21 | } |
22 | |
23 | namespace app { |
24 | namespace cmd { |
25 | using namespace doc; |
26 | |
27 | class CopyRegion : public Cmd |
28 | , public WithImage { |
29 | public: |
30 | // If alreadyCopied is false, it means that onExecute() will copy |
31 | // pixels from src to dst. If it's true, it means that "onExecute" |
32 | // should do nothing, because modified pixels are alreadt on "dst" |
33 | // (so we use "src" as the original image). |
34 | CopyRegion(Image* dst, const Image* src, |
35 | const gfx::Region& region, |
36 | const gfx::Point& dstPos, |
37 | bool alreadyCopied = false); |
38 | |
39 | protected: |
40 | void onExecute() override; |
41 | void onUndo() override; |
42 | void onRedo() override; |
43 | size_t onMemSize() const override { |
44 | return sizeof(*this) + m_buffer.size(); |
45 | } |
46 | |
47 | private: |
48 | void swap(); |
49 | virtual void rehash() { } |
50 | |
51 | bool m_alreadyCopied; |
52 | gfx::Region m_region; |
53 | base::buffer m_buffer; |
54 | }; |
55 | |
56 | class CopyTileRegion : public CopyRegion { |
57 | public: |
58 | CopyTileRegion(Image* dst, const Image* src, |
59 | const gfx::Region& region, |
60 | const gfx::Point& dstPos, |
61 | bool alreadyCopied, |
62 | const doc::tile_index tileIndex, |
63 | const doc::Tileset* tileset); |
64 | |
65 | private: |
66 | void rehash() override; |
67 | |
68 | doc::tile_index m_tileIndex; |
69 | doc::ObjectId m_tilesetId; |
70 | }; |
71 | |
72 | } // namespace cmd |
73 | } // namespace app |
74 | |
75 | #endif |
76 | |