Browse Source

Add undo feature with MoveSurfaceCommand

master
Krisjanis Rijnieks 10 years ago
parent
commit
c9a591a4ae
  1. 6
      example/example.xcodeproj/project.pbxproj
  2. 31
      src/Commands/MoveSurfaceCommand.cpp
  3. 31
      src/Commands/MoveSurfaceCommand.h
  4. 11
      src/Surfaces/SurfaceManagerGui.cpp
  5. 6
      src/Surfaces/SurfaceManagerGui.h
  6. 1
      src/ofxPiMapper.cpp

6
example/example.xcodeproj/project.pbxproj

@ -23,6 +23,7 @@
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 */; };
39A9AAE91B0518FC00AA83BC /* MoveSurfaceCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAE71B0518FC00AA83BC /* MoveSurfaceCommand.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 */; };
@ -150,6 +151,8 @@
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>"; };
39A9AAE71B0518FC00AA83BC /* MoveSurfaceCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MoveSurfaceCommand.cpp; path = Commands/MoveSurfaceCommand.cpp; sourceTree = "<group>"; };
39A9AAE81B0518FC00AA83BC /* MoveSurfaceCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MoveSurfaceCommand.h; path = Commands/MoveSurfaceCommand.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>"; };
@ -645,6 +648,8 @@
39FDD9E81AC0076200262205 /* Commands */ = {
isa = PBXGroup;
children = (
39A9AAE71B0518FC00AA83BC /* MoveSurfaceCommand.cpp */,
39A9AAE81B0518FC00AA83BC /* MoveSurfaceCommand.h */,
39A9AADF1B04E78600AA83BC /* RemoveSurfaceCommand.h */,
39A9AADE1B04E78600AA83BC /* RemoveSurfaceCommand.cpp */,
39FDD9EA1AC007BF00262205 /* BaseCommand.h */,
@ -855,6 +860,7 @@
E4B69E200A3A1BDC003C02F2 /* main.cpp in Sources */,
39C1244719EE9589005DF557 /* RegexPathFilter.cpp in Sources */,
39C787C11AC2BBAE00691393 /* TestUndoCommand.cpp in Sources */,
39A9AAE91B0518FC00AA83BC /* MoveSurfaceCommand.cpp in Sources */,
39C1247C19F187D5005DF557 /* BaseJoint.cpp in Sources */,
39FDD9EE1AC00EAE00262205 /* TestCommand.cpp in Sources */,
39C1245219EE95DD005DF557 /* MediaServer.cpp in Sources */,

31
src/Commands/MoveSurfaceCommand.cpp

@ -0,0 +1,31 @@
#include "MoveSurfaceCommand.h"
namespace ofx{
namespace piMapper{
MoveSurfaceCommand::MoveSurfaceCommand(
BaseSurface * surface,
ProjectionEditor * projectionEditor){
_surface = surface;
_projectionEditor = projectionEditor;
}
void MoveSurfaceCommand::exec(){
// Store surface location by copying vertices
_previousVertices = _surface->getVertices();
}
void MoveSurfaceCommand::undo(){
//for (auto i = 0; i < _previousVertices.size(); i++) {
//_surface->setVertex(i, _previousVertices[i]);
//}
_surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]);
_projectionEditor->updateJoints();
_previousVertices.clear();
_surface = 0;
}
} // namespace piMapper
} // namespace ofx

31
src/Commands/MoveSurfaceCommand.h

@ -0,0 +1,31 @@
// MoveSurfaceCommand
// Provides with option to undo move surface operation.
// Created by Krisjanis Rijnieks 2015-05-14
#pragma once
#include "BaseCommand.h"
#include "BaseSurface.h"
#include "ProjectionEditor.h"
namespace ofx{
namespace piMapper{
class MoveSurfaceCommand : public BaseUndoableCommand{
public:
MoveSurfaceCommand(
BaseSurface * surface,
ProjectionEditor * projectionEditor);
void exec();
void undo();
private:
BaseSurface * _surface;
ProjectionEditor * _projectionEditor;
vector<ofVec3f> _previousVertices;
};
} // namespace piMapper
} // namespace ofx

11
src/Surfaces/SurfaceManagerGui.cpp

@ -8,11 +8,13 @@ SurfaceManagerGui::SurfaceManagerGui() {
bDrag = false;
registerMouseEvents();
ofHideCursor();
_commandManager = 0;
}
SurfaceManagerGui::~SurfaceManagerGui() {
unregisterMouseEvents();
surfaceManager = NULL;
_commandManager = 0;
}
void SurfaceManagerGui::registerMouseEvents() {
@ -136,6 +138,11 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) {
// surface
clickPosition = ofVec2f(args.x, args.y);
startDrag();
_commandManager->exec(
new MoveSurfaceCommand(
surfaceManager->getSelectedSurface(),
&projectionEditor));
}
if (!bSurfaceSelected) {
@ -181,6 +188,10 @@ void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) {
sourcesEditor.setMediaServer(mediaServer);
}
void SurfaceManagerGui::setCommandManager(CommandManager * commandManager){
_commandManager = commandManager;
}
void SurfaceManagerGui::setMode(int newGuiMode) {
if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING &&
newGuiMode != GuiMode::PROJECTION_MAPPING &&

6
src/Surfaces/SurfaceManagerGui.h

@ -11,6 +11,8 @@
#include "ProjectionEditor.h"
#include "SourcesEditor.h"
#include "GuiMode.h"
#include "CommandManager.h"
#include "MoveSurfaceCommand.h"
namespace ofx {
namespace piMapper {
@ -26,8 +28,11 @@ class SurfaceManagerGui {
void mousePressed(ofMouseEventArgs& args);
void mouseReleased(ofMouseEventArgs& args);
void mouseDragged(ofMouseEventArgs& args);
void setSurfaceManager(SurfaceManager* newSurfaceManager);
void setMediaServer(MediaServer* newMediaServer);
void setCommandManager(CommandManager * commandManager);
void setMode(int newGuiMode);
void drawSelectedSurfaceHighlight();
void drawSelectedSurfaceTextureHighlight();
@ -43,6 +48,7 @@ class SurfaceManagerGui {
int guiMode;
bool bDrag;
ofVec2f clickPosition;
CommandManager * _commandManager;
};
}
}

1
src/ofxPiMapper.cpp

@ -14,6 +14,7 @@ void ofxPiMapper::setup(){
// Assign media server to other pi mapper components
surfaceManager.setMediaServer(&mediaServer);
gui.setMediaServer(&mediaServer);
gui.setCommandManager(&commandManager);
// Check if we have user surfaces defined, if not - load default
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){

Loading…
Cancel
Save