forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_palette.cpp
51 lines (39 loc) · 927 Bytes
/
add_palette.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/cmd/add_palette.h"
#include "doc/sprite.h"
#include "doc/palette.h"
#include "doc/palette_io.h"
namespace app {
namespace cmd {
using namespace doc;
AddPalette::AddPalette(Sprite* sprite, Palette* pal)
: WithSprite(sprite)
, m_size(0)
, m_frame(pal->frame())
{
write_palette(m_stream, pal);
m_size = size_t(m_stream.tellp());
}
void AddPalette::onExecute()
{
m_stream.seekp(0);
Sprite* sprite = this->sprite();
Palette* pal = read_palette(m_stream);
sprite->setPalette(pal, true);
sprite->incrementVersion();
}
void AddPalette::onUndo()
{
Sprite* sprite = this->sprite();
sprite->deletePalette(m_frame);
sprite->incrementVersion();
}
} // namespace cmd
} // namespace app