forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_transaction.cpp
More file actions
70 lines (54 loc) · 1.33 KB
/
cmd_transaction.cpp
File metadata and controls
70 lines (54 loc) · 1.33 KB
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// Aseprite
// Copyright (C) 2001-2015 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_transaction.h"
#include "app/context.h"
#include "doc/site.h"
namespace app {
CmdTransaction::CmdTransaction(const std::string& label,
bool changeSavedState, int* savedCounter)
: m_label(label)
, m_changeSavedState(changeSavedState)
, m_savedCounter(savedCounter)
{
}
void CmdTransaction::commit()
{
m_spritePositionAfter = calcSpritePosition();
}
void CmdTransaction::onExecute()
{
CmdSequence::onExecute();
// The execution of CmdTransaction is called by Transaction at the
// very beginning, just to save the current sprite position.
m_spritePositionBefore = calcSpritePosition();
if (m_changeSavedState)
++(*m_savedCounter);
}
void CmdTransaction::onUndo()
{
CmdSequence::onUndo();
if (m_changeSavedState)
--(*m_savedCounter);
}
void CmdTransaction::onRedo()
{
CmdSequence::onRedo();
if (m_changeSavedState)
++(*m_savedCounter);
}
std::string CmdTransaction::onLabel() const
{
return m_label;
}
doc::SpritePosition CmdTransaction::calcSpritePosition()
{
doc::Site site = context()->activeSite();
return doc::SpritePosition(site.layerIndex(), site.frame());
}
} // namespace app