1// Aseprite
2// Copyright (C) 2019 Igara Studio S.A.
3// Copyright (C) 2001-2015 David Capello
4//
5// This program is distributed under the terms of
6// the End-User License Agreement for Aseprite.
7
8#ifdef HAVE_CONFIG_H
9#include "config.h"
10#endif
11
12#include "app/cmd/flip_mask.h"
13
14#include "app/doc.h"
15#include "doc/algorithm/flip_image.h"
16#include "doc/mask.h"
17
18namespace app {
19namespace cmd {
20
21using namespace doc;
22
23FlipMask::FlipMask(Doc* doc, doc::algorithm::FlipType flipType)
24 : WithDocument(doc)
25 , m_flipType(flipType)
26{
27}
28
29void FlipMask::onExecute()
30{
31 swap();
32}
33
34void FlipMask::onUndo()
35{
36 swap();
37}
38
39void FlipMask::swap()
40{
41 Doc* doc = this->document();
42 Mask* mask = doc->mask();
43
44 ASSERT(mask->bitmap());
45 if (!mask->bitmap())
46 return;
47
48 mask->freeze();
49 doc::algorithm::flip_image(mask->bitmap(),
50 mask->bitmap()->bounds(), m_flipType);
51 mask->unfreeze();
52
53 doc->notifySelectionChanged();
54}
55
56} // namespace cmd
57} // namespace app
58