Browse Source

Add undo feature with SelectSurfaceCommand

master
Krisjanis Rijnieks 10 years ago
parent
commit
6d011c2e7a
  1. 6
      example/example.xcodeproj/project.pbxproj
  2. 33
      src/Commands/SelectSurfaceCommand.cpp
  3. 34
      src/Commands/SelectSurfaceCommand.h
  4. 30
      src/Surfaces/SurfaceManager.cpp
  5. 1
      src/Surfaces/SurfaceManager.h
  6. 23
      src/Surfaces/SurfaceManagerGui.cpp
  7. 1
      src/Surfaces/SurfaceManagerGui.h

6
example/example.xcodeproj/project.pbxproj

@ -24,6 +24,7 @@
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 */; };
39A9AAEC1B053B4200AA83BC /* SelectSurfaceCommand.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAEA1B053B4200AA83BC /* SelectSurfaceCommand.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 */; };
@ -153,6 +154,8 @@
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>"; };
39A9AAEA1B053B4200AA83BC /* SelectSurfaceCommand.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SelectSurfaceCommand.cpp; path = Commands/SelectSurfaceCommand.cpp; sourceTree = "<group>"; };
39A9AAEB1B053B4200AA83BC /* SelectSurfaceCommand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SelectSurfaceCommand.h; path = Commands/SelectSurfaceCommand.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>"; };
@ -648,6 +651,8 @@
39FDD9E81AC0076200262205 /* Commands */ = {
isa = PBXGroup;
children = (
39A9AAEA1B053B4200AA83BC /* SelectSurfaceCommand.cpp */,
39A9AAEB1B053B4200AA83BC /* SelectSurfaceCommand.h */,
39A9AAE71B0518FC00AA83BC /* MoveSurfaceCommand.cpp */,
39A9AAE81B0518FC00AA83BC /* MoveSurfaceCommand.h */,
39A9AADF1B04E78600AA83BC /* RemoveSurfaceCommand.h */,
@ -890,6 +895,7 @@
39C1243519EE9589005DF557 /* ByteBuffer.cpp in Sources */,
39C1246B19F0AB96005DF557 /* TriangleSurface.cpp in Sources */,
39C1244419EE9589005DF557 /* PathFilterCollection.cpp in Sources */,
39A9AAEC1B053B4200AA83BC /* SelectSurfaceCommand.cpp in Sources */,
39C1243319EE9589005DF557 /* lz4.c in Sources */,
39C1243B19EE9589005DF557 /* DeviceFilter.cpp in Sources */,
39C1243E19EE9589005DF557 /* DirectoryWatcher.cpp in Sources */,

33
src/Commands/SelectSurfaceCommand.cpp

@ -0,0 +1,33 @@
#include "SelectSurfaceCommand.h"
namespace ofx{
namespace piMapper{
SelectSurfaceCommand::SelectSurfaceCommand(
SurfaceManager * surfaceManager,
BaseSurface * surfaceToSelect,
ProjectionEditor * projectionEditor){
_surfaceManager = surfaceManager;
_surfaceToSelect = surfaceToSelect;
_projectionEditor = projectionEditor;
}
void SelectSurfaceCommand::exec(){
_prevSelectedSurface = _surfaceManager->getSelectedSurface();
_projectionEditor->clearJoints();
_surfaceManager->selectSurface(_surfaceToSelect);
_projectionEditor->createJoints();
}
void SelectSurfaceCommand::undo(){
_projectionEditor->clearJoints();
_surfaceManager->selectSurface(_prevSelectedSurface);
_projectionEditor->createJoints();
_surfaceToSelect = 0;
_prevSelectedSurface = 0;
}
} // namespace piMapper
} // namespace ofx

34
src/Commands/SelectSurfaceCommand.h

@ -0,0 +1,34 @@
// SelectSurfaceCommand
// Provides with option to undo select surface operation.
// Created by Krisjanis Rijnieks 2015-05-14
#pragma once
#include "BaseCommand.h"
#include "BaseSurface.h"
#include "SurfaceManager.h"
#include "ProjectionEditor.h"
namespace ofx{
namespace piMapper{
class SelectSurfaceCommand : public BaseUndoableCommand{
public:
SelectSurfaceCommand(
SurfaceManager * surfaceManager,
BaseSurface * surfaceToSelect,
ProjectionEditor * projectionEditor);
void exec();
void undo();
private:
BaseSurface * _surfaceToSelect;
SurfaceManager * _surfaceManager;
BaseSurface * _prevSelectedSurface;
ProjectionEditor * _projectionEditor;
};
} // namespace piMapper
} // namespace ofx

30
src/Surfaces/SurfaceManager.cpp

@ -370,16 +370,28 @@ void SurfaceManager::loadXmlSettings(string fileName) {
mediaServer = newMediaServer;
}
BaseSurface* SurfaceManager::selectSurface(int index) {
if (index >= surfaces.size()) {
throw std::runtime_error("Surface index out of bounds.");
}
selectedSurface = surfaces[index];
BaseSurface * SurfaceManager::selectSurface(int index) {
if (index >= surfaces.size()) {
throw std::runtime_error("Surface index out of bounds.");
}
selectedSurface = surfaces[index];
// notify that a new surface has been selected
ofSendMessage("surfaceSelected");
return selectedSurface;
}
// notify that a new surface has been selected
ofSendMessage("surfaceSelected");
}
BaseSurface * SurfaceManager::selectSurface(BaseSurface * surface){
for (auto i = 0; i < surfaces.size(); i++) {
if (surfaces[i] == surface){
selectedSurface = surface;
ofSendMessage("surfaceSelected");
return selectedSurface;
}
}
deselectSurface();
return 0;
}
BaseSurface* SurfaceManager::getSelectedSurface() {
return selectedSurface;

1
src/Surfaces/SurfaceManager.h

@ -42,6 +42,7 @@ class SurfaceManager {
BaseSurface* getSurface(int index);
int size();
BaseSurface* selectSurface(int index);
BaseSurface* selectSurface(BaseSurface * surface);
BaseSurface* getSelectedSurface();
void deselectSurface();

23
src/Surfaces/SurfaceManagerGui.cpp

@ -120,18 +120,19 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) {
bSurfaceSelected = true;
}
// attempt to select surface, loop from end to beginning
if (!bSurfaceSelected) {
for (int i = surfaceManager->size() - 1; i >= 0; i--) {
if (surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))) {
projectionEditor.clearJoints();
surfaceManager->selectSurface(i);
projectionEditor.createJoints();
bSurfaceSelected = true;
break;
}
// attempt to select surface, loop from end to beginning
if (!bSurfaceSelected) {
for (int i = surfaceManager->size() - 1; i >= 0; i--) {
if (surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))) {
_commandManager->exec(new SelectSurfaceCommand(
surfaceManager,
surfaceManager->getSurface(i),
&projectionEditor));
bSurfaceSelected = true;
break;
}
}
}
}
if (bSurfaceSelected && hitJoint == NULL) {
// if not hitting the joints, start drag only if we have a selected

1
src/Surfaces/SurfaceManagerGui.h

@ -13,6 +13,7 @@
#include "GuiMode.h"
#include "CommandManager.h"
#include "MoveSurfaceCommand.h"
#include "SelectSurfaceCommand.h"
namespace ofx {
namespace piMapper {

Loading…
Cancel
Save