Browse Source

Add undoable RemoveSurfaceCommand

master
Krisjanis Rijnieks 10 years ago
parent
commit
bd69364284
  1. 6
      example/example.xcodeproj/project.pbxproj
  2. 28
      src/Commands/RemoveSurfaceCommand.cpp
  3. 30
      src/Commands/RemoveSurfaceCommand.h
  4. 29
      src/Surfaces/SurfaceManager.cpp
  5. 6
      src/Surfaces/SurfaceManager.h
  6. 3
      src/ofxPiMapper.cpp
  7. 1
      src/ofxPiMapper.h

6
example/example.xcodeproj/project.pbxproj

@ -22,6 +22,7 @@
397EFC7C1A08E7680009286E /* ofxPiMapper.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 397EFC7B1A08E7680009286E /* ofxPiMapper.cpp */; };
397EFC7F1A08FE720009286E /* FboSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 397EFC7D1A08FE720009286E /* FboSource.cpp */; };
397EFC821A09047C0009286E /* CustomSource.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 397EFC801A09047C0009286E /* CustomSource.cpp */; };
39A9AAE01B04E78600AA83BC /* RemoveSurfaceCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AADE1B04E78600AA83BC /* RemoveSurfaceCommand.cpp */; };
39C1243319EE9589005DF557 /* lz4.c in Sources */ = {isa = PBXBuildFile; fileRef = 39C123EA19EE9589005DF557 /* lz4.c */; };
39C1243419EE9589005DF557 /* Base64Encoding.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C1241219EE9589005DF557 /* Base64Encoding.cpp */; };
39C1243519EE9589005DF557 /* ByteBuffer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39C1241319EE9589005DF557 /* ByteBuffer.cpp */; };
@ -147,6 +148,8 @@
397EFC7E1A08FE720009286E /* FboSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FboSource.h; sourceTree = "<group>"; };
397EFC801A09047C0009286E /* CustomSource.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CustomSource.cpp; sourceTree = "<group>"; };
397EFC811A09047C0009286E /* CustomSource.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CustomSource.h; sourceTree = "<group>"; };
39A9AADE1B04E78600AA83BC /* RemoveSurfaceCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RemoveSurfaceCommand.cpp; path = Commands/RemoveSurfaceCommand.cpp; sourceTree = "<group>"; };
39A9AADF1B04E78600AA83BC /* RemoveSurfaceCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RemoveSurfaceCommand.h; path = Commands/RemoveSurfaceCommand.h; sourceTree = "<group>"; };
39C123E719EE9589005DF557 /* alphanum.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = alphanum.hpp; sourceTree = "<group>"; };
39C123EA19EE9589005DF557 /* lz4.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = lz4.c; sourceTree = "<group>"; };
39C123EB19EE9589005DF557 /* lz4.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = lz4.h; sourceTree = "<group>"; };
@ -642,6 +645,8 @@
39FDD9E81AC0076200262205 /* Commands */ = {
isa = PBXGroup;
children = (
39A9AADF1B04E78600AA83BC /* RemoveSurfaceCommand.h */,
39A9AADE1B04E78600AA83BC /* RemoveSurfaceCommand.cpp */,
39FDD9EA1AC007BF00262205 /* BaseCommand.h */,
39C787BB1AC20D2400691393 /* CommandManager.h */,
39C787BC1AC2111B00691393 /* CommandManager.cpp */,
@ -856,6 +861,7 @@
39C1243D19EE9589005DF557 /* DirectoryUtils.cpp in Sources */,
39264843192224F90008A7F5 /* tinyxmlparser.cpp in Sources */,
3933D5D419BB87BD000ACA55 /* ofxButton.cpp in Sources */,
39A9AAE01B04E78600AA83BC /* RemoveSurfaceCommand.cpp in Sources */,
39C1244519EE9589005DF557 /* RecursiveDirectoryIterator.cpp in Sources */,
39C1243919EE9589005DF557 /* COBSEncoding.cpp in Sources */,
39C1244919EE9589005DF557 /* snappy-sinksource.cc in Sources */,

28
src/Commands/RemoveSurfaceCommand.cpp

@ -0,0 +1,28 @@
#include "RemoveSurfaceCommand.h"
namespace ofx{
namespace piMapper{
RemoveSurfaceCommand::RemoveSurfaceCommand(ofxPiMapper * app){
_app = app;
_surface = 0;
}
void RemoveSurfaceCommand::exec(){
// Store the surface, this implies that the surfaceManager's
// removeSelectedSurface does not destroy the surface.
_surface = _app->surfaceManager.getSelectedSurface();
_app->surfaceManager.removeSelectedSurface();
}
void RemoveSurfaceCommand::undo(){
if (_surface == 0) {
ofLogError("RemoveSurfaceCommand", "No surface stored");
}
_app->surfaceManager.addSurface(_surface);
_surface = 0;
}
} // namespace piMapper
} // namespace ofx

30
src/Commands/RemoveSurfaceCommand.h

@ -0,0 +1,30 @@
// RemoveSurfaceCommand
// Provides with option to undo remove surface operation.
// Created by Krisjanis Rijnieks 2015-05-14
#pragma once
#include "ofxPiMapper.h"
#include "BaseCommand.h"
#include "BaseSurface.h"
class ofxPiMapper;
namespace ofx{
namespace piMapper{
class RemoveSurfaceCommand : public BaseUndoableCommand{
public:
RemoveSurfaceCommand(ofxPiMapper * app);
void exec();
void undo();
private:
ofxPiMapper * _app;
BaseSurface * _surface;
};
} // namespace piMapper
} // namespace ofx

29
src/Surfaces/SurfaceManager.cpp

@ -117,18 +117,25 @@ void SurfaceManager::addSurface(int surfaceType, BaseSource* newSource,
}
}
void SurfaceManager::removeSelectedSurface() {
if (selectedSurface == NULL) {
return;
}
for (int i = 0; i < surfaces.size(); i++) {
if (surfaces[i] == selectedSurface) {
delete surfaces[i];
surfaces.erase(surfaces.begin() + i);
selectedSurface = NULL;
break;
// Add existing surface
void SurfaceManager::addSurface(BaseSurface * surface){
surfaces.push_back(surface);
}
void SurfaceManager::removeSelectedSurface(){
if (selectedSurface == NULL){
return;
}
for (int i = 0; i < surfaces.size(); i++){
if (surfaces[i] == selectedSurface){
// Do not delete pointer as we are storing the
// surface in the RemoveSurfaceCommand.
//delete surfaces[i];
surfaces.erase(surfaces.begin() + i);
selectedSurface = NULL;
break;
}
}
}
}
void SurfaceManager::clear() {

6
src/Surfaces/SurfaceManager.h

@ -21,12 +21,18 @@ class SurfaceManager {
~SurfaceManager();
void draw();
// TODO: These should be renamed to createSurface
void addSurface(int surfaceType);
void addSurface(int surfaceType, BaseSource* newSource);
void addSurface(int surfaceType, vector<ofVec2f> vertices,
vector<ofVec2f> texCoords);
void addSurface(int surfaceType, BaseSource* newSource,
vector<ofVec2f> vertices, vector<ofVec2f> texCoords);
// Except this, as it adds existing surface
void addSurface(BaseSurface * surface);
void removeSelectedSurface();
void clear();
void saveXmlSettings(string fileName);

3
src/ofxPiMapper.cpp

@ -100,7 +100,8 @@ void ofxPiMapper::keyPressed(ofKeyEventArgs &args){
surfaceManager.saveXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE);
break;
case OF_KEY_BACKSPACE:
surfaceManager.removeSelectedSurface();
//surfaceManager.removeSelectedSurface();
commandManager.exec(new ofx::piMapper::RemoveSurfaceCommand((ofxPiMapper *)this));
break;
// TODO: Remove the following case when Command test done.
case '9':

1
src/ofxPiMapper.h

@ -16,6 +16,7 @@
#include "TestCommand.h" // TODO: Remove this line when done testing
#include "TestUndoCommand.h"
#include "CommandManager.h"
#include "RemoveSurfaceCommand.h"
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml"
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"

Loading…
Cancel
Save