1 | // Aseprite |
---|---|
2 | // Copyright (C) 2001-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/add_palette.h" |
12 | |
13 | #include "doc/sprite.h" |
14 | #include "doc/palette.h" |
15 | #include "doc/palette_io.h" |
16 | |
17 | namespace app { |
18 | namespace cmd { |
19 | |
20 | using namespace doc; |
21 | |
22 | AddPalette::AddPalette(Sprite* sprite, Palette* pal) |
23 | : WithSprite(sprite) |
24 | , m_size(0) |
25 | , m_frame(pal->frame()) |
26 | { |
27 | write_palette(m_stream, pal); |
28 | m_size = size_t(m_stream.tellp()); |
29 | } |
30 | |
31 | void AddPalette::onExecute() |
32 | { |
33 | m_stream.seekp(0); |
34 | |
35 | Sprite* sprite = this->sprite(); |
36 | Palette* pal = read_palette(m_stream); |
37 | |
38 | sprite->setPalette(pal, true); |
39 | sprite->incrementVersion(); |
40 | } |
41 | |
42 | void AddPalette::onUndo() |
43 | { |
44 | Sprite* sprite = this->sprite(); |
45 | |
46 | sprite->deletePalette(m_frame); |
47 | sprite->incrementVersion(); |
48 | } |
49 | |
50 | } // namespace cmd |
51 | } // namespace app |
52 |