1 // Aseprite
2 // Copyright (C) 2001-2018 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/shift_masked_cel.h"
12
13 #include "app/doc.h"
14 #include "doc/algorithm/shift_image.h"
15 #include "doc/cel.h"
16 #include "doc/image.h"
17 #include "doc/layer.h"
18 #include "doc/mask.h"
19
20 namespace app {
21 namespace cmd {
22
ShiftMaskedCel(Cel * cel,int dx,int dy)23 ShiftMaskedCel::ShiftMaskedCel(Cel* cel, int dx, int dy)
24 : WithCel(cel)
25 , m_dx(dx)
26 , m_dy(dy)
27 {
28 }
29
onExecute()30 void ShiftMaskedCel::onExecute()
31 {
32 shift(m_dx, m_dy);
33 }
34
onUndo()35 void ShiftMaskedCel::onUndo()
36 {
37 shift(-m_dx, -m_dy);
38 }
39
shift(int dx,int dy)40 void ShiftMaskedCel::shift(int dx, int dy)
41 {
42 Cel* cel = this->cel();
43 Image* image = cel->image();
44 Mask* mask = static_cast<Doc*>(cel->document())->mask();
45 ASSERT(mask->bitmap());
46 if (!mask->bitmap())
47 return;
48
49 int x = cel->x();
50 int y = cel->y();
51
52 mask->offsetOrigin(-x, -y);
53 doc::algorithm::shift_image_with_mask(image, mask, dx, dy);
54 mask->offsetOrigin(x, y);
55
56 image->incrementVersion();
57 }
58
59 } // namespace cmd
60 } // namespace app
61