diff --git a/src/Commands/SetNextSourceCmd.cpp b/src/Commands/SetNextSourceCmd.cpp new file mode 100644 index 0000000..5a19b3d --- /dev/null +++ b/src/Commands/SetNextSourceCmd.cpp @@ -0,0 +1,57 @@ +#include "SetNextSourceCmd.h" + +namespace ofx { +namespace piMapper { + +SetNextSourceCmd::SetNextSourceCmd(int sourceType, + string sourceId, + BaseSurface * surface, + SourcesEditor * sourcesEditor){ + + _sourceType = sourceType; + _sourceId = sourceId; + _surface = surface; + _sourcesEditor = sourcesEditor; +} + +void SetNextSourceCmd::exec(){ + ofLogNotice("SetNextSourceCmd", "exec"); + + _oldSourceType = _surface->getSource()->getType(); + if(_surface->getSource()->isLoadable()){ + _oldSourceId = _surface->getSource()->getPath(); + }else{ + _oldSourceId = _surface->getSource()->getName(); + } + + if(_sourceType == SourceType::SOURCE_TYPE_IMAGE){ + _sourcesEditor->setImageSource(_sourceId); + }else if(_sourceType == SourceType::SOURCE_TYPE_VIDEO){ + _sourcesEditor->setVideoSource(_sourceId); + }else if(_sourceType == SourceType::SOURCE_TYPE_FBO){ + _sourcesEditor->setFboSource(_sourceId); + }else if(_sourceType == SourceType::SOURCE_TYPE_NONE){ + _sourcesEditor->clearSource(); + } +} + +void SetNextSourceCmd::undo(){ + ofLogNotice("SetNextSourceCmd", "undo"); + + if(_oldSourceType == SourceType::SOURCE_TYPE_IMAGE){ + _sourcesEditor->setImageSource(_oldSourceId); + }else if(_oldSourceType == SourceType::SOURCE_TYPE_VIDEO){ + _sourcesEditor->setVideoSource(_oldSourceId); + }else if(_oldSourceType == SourceType::SOURCE_TYPE_FBO){ + _sourcesEditor->setFboSource(_oldSourceId); + }else if(_oldSourceType == SourceType::SOURCE_TYPE_NONE){ + _sourcesEditor->clearSource(); + } + + _surface = 0; + _sourcesEditor = 0; +} + +} // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/SetNextSourceCmd.h b/src/Commands/SetNextSourceCmd.h new file mode 100644 index 0000000..1fc9b9a --- /dev/null +++ b/src/Commands/SetNextSourceCmd.h @@ -0,0 +1,35 @@ +#pragma once + +#include "BaseCmd.h" +#include "BaseSurface.h" +#include "SourcesEditor.h" + +namespace ofx { +namespace piMapper { + +class SourcesEditor; + +class SetNextSourceCmd : public BaseUndoCmd { + + public: + SetNextSourceCmd(int sourceType, + string sourceId, + BaseSurface * surface, + SourcesEditor * sourcesEditor); + void exec(); + void undo(); + + private: + int _sourceType; + string _sourceId; + BaseSurface * _surface; + SourcesEditor * _sourcesEditor; + + int _oldSourceType; + string _oldSourceId; + +}; + +} // namespace piMapper +} // namespace ofx +