diff --git a/src/Commands/MvLayerUpCmd.cpp b/src/Commands/MvLayerUpCmd.cpp new file mode 100644 index 0000000..1b2182c --- /dev/null +++ b/src/Commands/MvLayerUpCmd.cpp @@ -0,0 +1,45 @@ +#include "MvLayerUpCmd.h" + +namespace ofx { +namespace piMapper { + +MvLayerUpCmd::MvLayerUpCmd(BaseSurface * selectedSurface){ + _selectedSurface = selectedSurface; + _selectedSurfaceIndex = -1; +} + +void MvLayerUpCmd::exec(){ + ofLogNotice("MvLayerUpCmd", "exec"); + + // Find selected surface index in SurfaceStack. + for(int i = 0; i < SurfaceStack::instance()->size(); ++i){ + if(_selectedSurface == SurfaceStack::instance()->at(i)){ + _selectedSurfaceIndex = i; + break; + } + } + + if(_selectedSurfaceIndex == -1){ + throw runtime_error("MvLayerUpCmd used with no surface selected"); + } + + if(_selectedSurfaceIndex == SurfaceStack::instance()->size() - 1){ + throw runtime_error("Check if selected surface is not top before using MvLayerUpCmd"); + } + + if(SurfaceStack::instance()->size() <= 1){ + throw runtime_error("Check if there is more than one surface before using MvLayerUpCmd"); + } + + // Swap it with the next surface + SurfaceStack::instance()->swap(_selectedSurfaceIndex, _selectedSurfaceIndex + 1); +} + +void MvLayerUpCmd::undo(){ + ofLogNotice("MvLayerUoCmd", "undo"); + SurfaceStack::instance()->swap(_selectedSurfaceIndex, _selectedSurfaceIndex + 1); +} + +} // namespace piMapper +} // namespace ofx + diff --git a/src/Commands/MvLayerUpCmd.h b/src/Commands/MvLayerUpCmd.h new file mode 100644 index 0000000..91d41ed --- /dev/null +++ b/src/Commands/MvLayerUpCmd.h @@ -0,0 +1,26 @@ +#pragma once + +#include "BaseCmd.h" +#include "BaseSurface.h" +#include "SurfaceStack.h" + +namespace ofx { +namespace piMapper { + +class MvLayerUpCmd : public BaseUndoCmd { + + public: + MvLayerUpCmd(BaseSurface * selectedSurface); + void exec(); + void undo(); + + private: + BaseSurface * _selectedSurface; + + int _selectedSurfaceIndex; + +}; + +} // namespace piMapper +} // namespace ofx +