Browse Source

Add gui mode/state switch undo command

master
Krisjanis Rijnieks 10 years ago
parent
commit
c69ca799b4
  1. 6
      example/example.xcodeproj/project.pbxproj
  2. 24
      src/Commands/SetGuiModeCmd.cpp
  3. 28
      src/Commands/SetGuiModeCmd.h
  4. 4
      src/Surfaces/SurfaceManagerGui.cpp
  5. 1
      src/Surfaces/SurfaceManagerGui.h
  6. 20
      src/ofxPiMapper.cpp
  7. 1
      src/ofxPiMapper.h

6
example/example.xcodeproj/project.pbxproj

@ -7,6 +7,7 @@
objects = {
/* Begin PBXBuildFile section */
391717EF1B08FFDA00F9A484 /* SetGuiModeCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */; };
3926483B192224DA0008A7F5 /* ofxXmlSettings.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39264839192224DA0008A7F5 /* ofxXmlSettings.cpp */; };
39264841192224F90008A7F5 /* tinyxml.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3926483D192224F90008A7F5 /* tinyxml.cpp */; };
39264842192224F90008A7F5 /* tinyxmlerror.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 3926483F192224F90008A7F5 /* tinyxmlerror.cpp */; };
@ -120,6 +121,8 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SetGuiModeCmd.cpp; path = Commands/SetGuiModeCmd.cpp; sourceTree = "<group>"; };
391717EE1B08FFDA00F9A484 /* SetGuiModeCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SetGuiModeCmd.h; path = Commands/SetGuiModeCmd.h; sourceTree = "<group>"; };
39264839192224DA0008A7F5 /* ofxXmlSettings.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = ofxXmlSettings.cpp; path = ../../ofxXmlSettings/src/ofxXmlSettings.cpp; sourceTree = "<group>"; };
3926483A192224DA0008A7F5 /* ofxXmlSettings.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = ofxXmlSettings.h; path = ../../ofxXmlSettings/src/ofxXmlSettings.h; sourceTree = "<group>"; };
3926483D192224F90008A7F5 /* tinyxml.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = tinyxml.cpp; sourceTree = "<group>"; };
@ -659,6 +662,8 @@
39A9AAE71B0518FC00AA83BC /* MvSurfaceCmd.cpp */,
39A9AADF1B04E78600AA83BC /* RmSurfaceCmd.h */,
39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */,
391717EE1B08FFDA00F9A484 /* SetGuiModeCmd.h */,
391717ED1B08FFDA00F9A484 /* SetGuiModeCmd.cpp */,
);
name = Commands;
sourceTree = "<group>";
@ -885,6 +890,7 @@
39C1244219EE9589005DF557 /* HiddenFileFilter.cpp in Sources */,
39C1244819EE9589005DF557 /* SearchPath.cpp in Sources */,
39C1248019F187D5005DF557 /* SourcesEditor.cpp in Sources */,
391717EF1B08FFDA00F9A484 /* SetGuiModeCmd.cpp in Sources */,
39C1243F19EE9589005DF557 /* DirectoryWatcherManager.cpp in Sources */,
39C1243519EE9589005DF557 /* ByteBuffer.cpp in Sources */,
39C1246B19F0AB96005DF557 /* TriangleSurface.cpp in Sources */,

24
src/Commands/SetGuiModeCmd.cpp

@ -0,0 +1,24 @@
#include "SetGuiModeCmd.h"
namespace ofx{
namespace piMapper{
SetGuiModeCmd::SetGuiModeCmd(SurfaceManagerGui * gui, int mode){
_gui = gui;
_prevGuiMode = -1;
_mode = mode;
}
void SetGuiModeCmd::exec(){
_prevGuiMode = _gui->getMode();
_gui->setMode(_mode);
}
void SetGuiModeCmd::undo(){
ofLogNotice("SetGuiModeCmd", "undo");
_gui->setMode(_prevGuiMode);
}
} // namespace piMapper
} // namespace ofx

28
src/Commands/SetGuiModeCmd.h

@ -0,0 +1,28 @@
// SetGuiModeCmd
// Provides undo operation for setting the GUI mode/state
// Created by Krisjanis Rijnieks 2015-05-14
#pragma once
#include "SurfaceManagerGui.h"
#include "BaseCmd.h"
namespace ofx{
namespace piMapper{
class SetGuiModeCmd : public BaseUndoCmd{
public:
SetGuiModeCmd(SurfaceManagerGui * gui, int mode);
void exec();
void undo();
private:
SurfaceManagerGui * _gui;
int _prevGuiMode;
int _mode;
};
} // namespace piMapper
} // namespace ofx

4
src/Surfaces/SurfaceManagerGui.cpp

@ -254,6 +254,10 @@ namespace ofx {
}
}
int SurfaceManagerGui::getMode(){
return guiMode;
}
void SurfaceManagerGui::drawSelectedSurfaceHighlight() {
if (surfaceManager->getSelectedSurface() == NULL) return;
ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea();

1
src/Surfaces/SurfaceManagerGui.h

@ -36,6 +36,7 @@ namespace ofx {
void setCmdManager(CmdManager * cmdManager);
void setMode(int newGuiMode);
int getMode();
void drawSelectedSurfaceHighlight();
void drawSelectedSurfaceTextureHighlight();
void startDrag();

20
src/ofxPiMapper.cpp

@ -72,16 +72,28 @@ void ofxPiMapper::keyPressed(ofKeyEventArgs &args){
switch (args.key) {
case '1':
gui.setMode(ofx::piMapper::GuiMode::NONE);
if (gui.getMode() != ofx::piMapper::GuiMode::NONE) {
cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui,
ofx::piMapper::GuiMode::NONE));
}
break;
case '2':
gui.setMode(ofx::piMapper::GuiMode::TEXTURE_MAPPING);
if (gui.getMode() != ofx::piMapper::GuiMode::TEXTURE_MAPPING) {
cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui,
ofx::piMapper::GuiMode::TEXTURE_MAPPING));
}
break;
case '3':
gui.setMode(ofx::piMapper::GuiMode::PROJECTION_MAPPING);
if (gui.getMode() != ofx::piMapper::GuiMode::PROJECTION_MAPPING) {
cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui,
ofx::piMapper::GuiMode::PROJECTION_MAPPING));
}
break;
case '4':
gui.setMode(ofx::piMapper::GuiMode::SOURCE_SELECTION);
if (gui.getMode() != ofx::piMapper::GuiMode::SOURCE_SELECTION) {
cmdManager.exec(new ofx::piMapper::SetGuiModeCmd(&gui,
ofx::piMapper::GuiMode::SOURCE_SELECTION));
}
break;
case 'i':
bShowInfo = !bShowInfo;

1
src/ofxPiMapper.h

@ -16,6 +16,7 @@
#include "BaseCmd.h"
#include "CmdManager.h"
#include "RmSurfaceCmd.h"
#include "SetGuiModeCmd.h"
#define PIMAPPER_DEF_SURFACES_XML_FILE "defaultSurfaces.xml"
#define PIMAPPER_USER_SURFACES_XML_FILE "surfaces.xml"

Loading…
Cancel
Save