Browse Source

Improve ClearSurfaceCmd with surface deselection

master
Krisjanis Rijnieks 9 years ago
parent
commit
81885d72df
  1. 12
      src/Application/Application.cpp
  2. 3
      src/Application/Application.h
  3. 6
      src/Commands/ClearSurfacesCmd.cpp
  4. 5
      src/Commands/ClearSurfacesCmd.h

12
src/Application/Application.cpp

@ -5,6 +5,8 @@ namespace ofx {
namespace piMapper {
Application::Application(){
_keySequence = "";
_surfaceManager.setMediaServer(&_mediaServer);
_gui.setMediaServer(&_mediaServer);
_gui.setCmdManager(&_cmdManager);
@ -55,6 +57,16 @@ void Application::draw(){
// Here we handle application state changes only
void Application::onKeyPressed(ofKeyEventArgs & args){
// Key sequence based commands. Last three keys are taken into account.
_keySequence += args.key;
if(_keySequence.size() >= 3){
_keySequence = _keySequence.substr(_keySequence.size() - 3, 3);
if(_keySequence == "new"){
_cmdManager.exec(new ClearSurfacesCmd());
return;
}
}
// For now we set the state of the new system and also the old
// before it is completely ported to the state system.

3
src/Application/Application.h

@ -4,6 +4,7 @@
#include "ofLog.h"
#include "SetApplicationStateCmd.h"
#include "ClearSurfacesCmd.h"
#include "ApplicationBaseState.h"
#include "PresentationState.h"
@ -84,6 +85,8 @@ class Application : public KeyListener {
bool _shiftKeyDown;
bool _isSSHConnection;
string _keySequence;
};

6
src/Commands/ClearSurfacesCmd.cpp

@ -3,11 +3,14 @@
namespace ofx {
namespace piMapper {
ClearSurfacesCmd::ClearSurfacesCmd(){
ClearSurfacesCmd::ClearSurfacesCmd(SurfaceManager * sm){
_surfaceManager = sm;
_selectedSurface = _surfaceManager->getSelectedSurface();
_surfaces = SurfaceStack::instance()->getSurfaces();
}
void ClearSurfacesCmd::exec(){
_surfaceManager->deselectSurface();
SurfaceStack::instance()->clear();
}
@ -16,6 +19,7 @@ void ClearSurfacesCmd::undo(){
for(unsigned int i = 0; i < _surfaces.size(); ++i){
SurfaceStack::instance()->push_back(_surfaces[i]);
}
_surfaceManager->selectSurface(_selectedSurface);
}
} // namespace piMapper

5
src/Commands/ClearSurfacesCmd.h

@ -7,6 +7,7 @@
#include "BaseCmd.h"
#include "BaseSurface.h"
#include "SurfaceStack.h"
#include "SurfaceManager.h"
#include "Gui.h"
namespace ofx {
@ -15,13 +16,15 @@ namespace piMapper {
class ClearSurfacesCmd : public BaseUndoCmd {
public:
ClearSurfacesCmd();
ClearSurfacesCmd(SurfaceManager * sm);
void exec();
void undo();
private:
// Here it would make sense to have another instance of SurfaceStack
vector<BaseSurface *> _surfaces;
SurfaceManager * _surfaceManager;
BaseSurface * _selectedSurface;
};

Loading…
Cancel
Save