Skip to content

Commit

Permalink
完成command类
Browse files Browse the repository at this point in the history
  • Loading branch information
mayerui committed Sep 5, 2019
1 parent f17b14f commit 661f96a
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
33 changes: 33 additions & 0 deletions src/command.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "scene.h"
#include "command.h"

CCommand::CCommand(CScene *pOwner) : _pOwner(pOwner)
{}

CCommand::CCommand(const CCommand &rhs)
: _pOwner(rhs._pOwner.get())
, _stPoint(rhs._stPoint)
, _nPreValue(rhs._nPreValue)
, _nCurValue(rhs._nCurValue)
{}

CCommand::~CCommand(){}

bool CCommand::excute(int nInputValue)
{
if (!_pOwner)
return false;

_stPoint = _pOwner.get()->getCurPoint();
return _pOwner.get()->setCurValue(nInputValue, _nPreValue);
}

void CCommand::undo()
{
if (_pOwner)
{
_pOwner.get()->setPointValue(_stPoint, _nPreValue);
}

return;
}
5 changes: 3 additions & 2 deletions src/command.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@ class CScene;
class CCommand
{
public:
CCommand(std::shared_ptr<CScene> pOwner);
CCommand(CScene* pOwner);
CCommand(const CCommand &);
~CCommand();

void excute();
bool excute(int nInputValue);
void undo();

private:
Expand Down

0 comments on commit 661f96a

Please sign in to comment.