1 // Aseprite
2 // Copyright (C) 2016 David Capello
3 //
4 // This program is distributed under the terms of
5 // the End-User License Agreement for Aseprite.
6
7 #ifdef HAVE_CONFIG_H
8 #include "config.h"
9 #endif
10
11 #include "app/cmd/patch_cel.h"
12
13 #include "app/cmd/copy_region.h"
14 #include "app/cmd/crop_cel.h"
15 #include "app/cmd/trim_cel.h"
16 #include "doc/cel.h"
17
18 namespace app {
19 namespace cmd {
20
21 using namespace doc;
22
PatchCel(doc::Cel * dstCel,const doc::Image * patch,const gfx::Region & patchedRegion,const gfx::Point & patchPos)23 PatchCel::PatchCel(doc::Cel* dstCel,
24 const doc::Image* patch,
25 const gfx::Region& patchedRegion,
26 const gfx::Point& patchPos)
27 : WithCel(dstCel)
28 , m_patch(patch)
29 , m_region(patchedRegion)
30 , m_pos(patchPos)
31 {
32 }
33
onExecute()34 void PatchCel::onExecute()
35 {
36 Cel* cel = this->cel();
37
38 executeAndAdd(
39 new CropCel(cel,
40 cel->bounds() |
41 gfx::Rect(m_region.bounds()).offset(m_pos)));
42
43 executeAndAdd(
44 new CopyRegion(cel->image(),
45 m_patch,
46 m_region,
47 m_pos - cel->position()));
48
49 executeAndAdd(
50 new TrimCel(cel));
51
52 m_patch = nullptr;
53 }
54
55 } // namespace cmd
56 } // namespace app
57