Browse Source

Add SelSourceCmd select source undoable command

master
Krisjanis Rijnieks 10 years ago
parent
commit
7e7aa93226
  1. 6
      example/example.xcodeproj/project.pbxproj
  2. 57
      src/Commands/SetSourceCmd.cpp
  3. 40
      src/Commands/SetSourceCmd.h
  4. 1
      src/Surfaces/SurfaceManagerGui.cpp
  5. 46
      src/UserInterface/SourcesEditor.cpp
  6. 15
      src/UserInterface/SourcesEditor.h

6
example/example.xcodeproj/project.pbxproj

@ -25,6 +25,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 */; };
39A867961B0D312400165378 /* SetSourceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A867941B0D312400165378 /* SetSourceCmd.cpp */; };
39A9AAE01B04E78600AA83BC /* RmSurfaceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */; };
39A9AAE91B0518FC00AA83BC /* MvSurfaceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAE71B0518FC00AA83BC /* MvSurfaceCmd.cpp */; };
39A9AAEC1B053B4200AA83BC /* SelSurfaceCmd.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 39A9AAEA1B053B4200AA83BC /* SelSurfaceCmd.cpp */; };
@ -158,6 +159,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>"; };
39A867941B0D312400165378 /* SetSourceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = SetSourceCmd.cpp; path = Commands/SetSourceCmd.cpp; sourceTree = "<group>"; };
39A867951B0D312400165378 /* SetSourceCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SetSourceCmd.h; path = Commands/SetSourceCmd.h; sourceTree = "<group>"; };
39A9AADE1B04E78600AA83BC /* RmSurfaceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = RmSurfaceCmd.cpp; path = Commands/RmSurfaceCmd.cpp; sourceTree = "<group>"; };
39A9AADF1B04E78600AA83BC /* RmSurfaceCmd.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = RmSurfaceCmd.h; path = Commands/RmSurfaceCmd.h; sourceTree = "<group>"; };
39A9AAE71B0518FC00AA83BC /* MvSurfaceCmd.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = MvSurfaceCmd.cpp; path = Commands/MvSurfaceCmd.cpp; sourceTree = "<group>"; };
@ -674,6 +677,8 @@
391717F11B0A8A7300F9A484 /* MvAllTexCoordsCmd.cpp */,
391717F61B0BCBB500F9A484 /* MvTexCoordCmd.h */,
391717F51B0BCBB500F9A484 /* MvTexCoordCmd.cpp */,
39A867951B0D312400165378 /* SetSourceCmd.h */,
39A867941B0D312400165378 /* SetSourceCmd.cpp */,
);
name = Commands;
sourceTree = "<group>";
@ -879,6 +884,7 @@
39C1245219EE95DD005DF557 /* MediaServer.cpp in Sources */,
39C1243D19EE9589005DF557 /* DirectoryUtils.cpp in Sources */,
39264843192224F90008A7F5 /* tinyxmlparser.cpp in Sources */,
39A867961B0D312400165378 /* SetSourceCmd.cpp in Sources */,
3933D5D419BB87BD000ACA55 /* ofxButton.cpp in Sources */,
39A9AAE01B04E78600AA83BC /* RmSurfaceCmd.cpp in Sources */,
39C1244519EE9589005DF557 /* RecursiveDirectoryIterator.cpp in Sources */,

57
src/Commands/SetSourceCmd.cpp

@ -0,0 +1,57 @@
#include "SetSourceCmd.h"
namespace ofx{
namespace piMapper{
SetSourceCmd::SetSourceCmd(int sourceType,
string sourceId,
BaseSurface * surface,
SourcesEditor * sourcesEditor){
_sourceType = sourceType;
_sourceId = sourceId;
_surface = surface;
_sourcesEditor = sourcesEditor;
}
void SetSourceCmd::exec(){
ofLogNotice("SetSourceCmd", "exec");
_oldSourceType = _surface->getSource()->getType();
if (_surface->getSource()->isLoadable()) {
_oldSourceId = _surface->getSource()->getPath();
} else {
_oldSourceId = _surface->getSource()->getName();
}
if (_sourceType == SourceType::SOURCE_TYPE_IMAGE) {
_sourcesEditor->setImageSource(_sourceId);
} else if (_sourceType == SourceType::SOURCE_TYPE_VIDEO) {
_sourcesEditor->setVideoSource(_sourceId);
} else if (_sourceType == SourceType::SOURCE_TYPE_FBO) {
_sourcesEditor->setFboSource(_sourceId);
} else if (_sourceType == SourceType::SOURCE_TYPE_NONE) {
_sourcesEditor->clearSource();
}
}
void SetSourceCmd::undo(){
ofLogNotice("SetSourceCmd", "undo");
if (_oldSourceType == SourceType::SOURCE_TYPE_IMAGE) {
_sourcesEditor->setImageSource(_oldSourceId);
} else if (_oldSourceType == SourceType::SOURCE_TYPE_VIDEO) {
_sourcesEditor->setVideoSource(_oldSourceId);
} else if (_oldSourceType == SourceType::SOURCE_TYPE_FBO) {
_sourcesEditor->setFboSource(_oldSourceId);
} else if (_oldSourceType == SourceType::SOURCE_TYPE_NONE) {
_sourcesEditor->clearSource();
}
_surface = 0;
_sourcesEditor = 0;
}
} // namespace piMapper
} // namespace ofx

40
src/Commands/SetSourceCmd.h

@ -0,0 +1,40 @@
// SetSourceCmd
// Set selected surface source undoable command
// Created by Krisjanis Rijnieks 2015-05-20
#pragma once
#include "BaseCmd.h"
#include "BaseSurface.h"
#include "SourcesEditor.h"
namespace ofx{
namespace piMapper{
class SourcesEditor;
class SetSourceCmd : public BaseUndoCmd{
public:
SetSourceCmd(int sourceType,
string sourceId,
BaseSurface * surface,
SourcesEditor * sourcesEditor);
void exec();
void undo();
private:
int _sourceType;
string _sourceId;
BaseSurface * _surface;
SourcesEditor * _sourcesEditor;
int _oldSourceType;
string _oldSourceId;
};
} // namespace piMapper
} // namespace ofx

1
src/Surfaces/SurfaceManagerGui.cpp

@ -235,6 +235,7 @@ namespace ofx {
void SurfaceManagerGui::setCmdManager(CmdManager * cmdManager){
_cmdManager = cmdManager;
sourcesEditor.setCmdManager(_cmdManager);
}
void SurfaceManagerGui::setMode(int newGuiMode) {

46
src/UserInterface/SourcesEditor.cpp

@ -147,6 +147,10 @@ namespace piMapper {
surfaceManager = newSurfaceManager;
}
void SourcesEditor::setCmdManager(CmdManager * cmdManager){
_cmdManager = cmdManager;
}
void SourcesEditor::setMediaServer(MediaServer* newMediaServer) {
// If the new media server is not valid
if (newMediaServer == NULL) {
@ -236,8 +240,15 @@ namespace piMapper {
ofRemoveListener(mediaServer->onFboSourceLoaded, this, &SourcesEditor::handleFboSourceLoaded);
ofRemoveListener(mediaServer->onFboSourceUnloaded, this, &SourcesEditor::handleFboSourceUnloaded);
}
void SourcesEditor::handleImageSelected(string & imagePath){
_cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_IMAGE,
imagePath,
surfaceManager->getSelectedSurface(),
(SourcesEditor *)this));
}
void SourcesEditor::handleImageSelected(string& imagePath) {
void SourcesEditor::setImageSource(string & imagePath){
// Unselect selected items
videoSelector->unselectAll();
fboSelector->unselectAll();
@ -260,7 +271,14 @@ namespace piMapper {
surface->setSource(mediaServer->loadImage(imagePath));
}
void SourcesEditor::handleVideoSelected(string& videoPath) {
void SourcesEditor::handleVideoSelected(string & videoPath){
_cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_VIDEO,
videoPath,
surfaceManager->getSelectedSurface(),
(SourcesEditor *)this));
}
void SourcesEditor::setVideoSource(string & videoPath){
// Unselect any selected items
fboSelector->unselectAll();
imageSelector->unselectAll();
@ -283,7 +301,14 @@ namespace piMapper {
surface->setSource(mediaServer->loadVideo(videoPath));
}
void SourcesEditor::handleFboSelected(string &fboName) {
void SourcesEditor::handleFboSelected(string & fboName){
_cmdManager->exec(new SetSourceCmd(SourceType::SOURCE_TYPE_FBO,
fboName,
surfaceManager->getSelectedSurface(),
(SourcesEditor *)this));
}
void SourcesEditor::setFboSource(string & fboName) {
videoSelector->unselectAll();
imageSelector->unselectAll();
@ -306,6 +331,21 @@ namespace piMapper {
surface->setSource(mediaServer->loadFboSource(fboName));
}
void SourcesEditor::clearSource(){
BaseSurface* surface = surfaceManager->getSelectedSurface();
// Unload old media
BaseSource* source = surface->getSource();
if (source->isLoadable()) {
mediaServer->unloadMedia(source->getPath());
} else {
mediaServer->unloadMedia(source->getName());
}
// Reset default source
surface->setSource(surface->getDefaultSource());
}
void SourcesEditor::clearMediaServer() {
// If mediaServer is local, clear it
if (!isMediaServerExternal) {

15
src/UserInterface/SourcesEditor.h

@ -5,6 +5,8 @@
#include "SurfaceManager.h"
#include "RadioList.h"
#include "MediaServer.h"
#include "CmdManager.h"
#include "SetSourceCmd.h"
namespace ofx {
namespace piMapper {
@ -27,6 +29,7 @@ class SourcesEditor {
void disable();
void enable();
void setSurfaceManager(SurfaceManager* newSurfaceManager);
void setCmdManager(CmdManager * cmdManager);
// Sets external MediaServer
void setMediaServer(MediaServer* newMediaServer);
@ -35,6 +38,11 @@ class SourcesEditor {
int getLoadedTexCount();
ofTexture* getTexture(int index);
void setImageSource(string & imagePath);
void setVideoSource(string & videoPath);
void setFboSource(string & fboName);
void clearSource();
private:
MediaServer* mediaServer;
@ -42,6 +50,7 @@ class SourcesEditor {
RadioList* imageSelector;
RadioList* videoSelector;
RadioList* fboSelector;
CmdManager * _cmdManager;
// Is the media server pointer local or from somewhere else?
// We use this to determine if we are allowed to clear media server locally.
@ -55,9 +64,9 @@ class SourcesEditor {
void removeMediaServerListeners();
// Handles GUI event, whenever someone has clicked on a radio button
void handleImageSelected(string& imagePath);
void handleVideoSelected(string& videoPath);
void handleFboSelected(string& fboName);
void handleImageSelected(string & imagePath);
void handleVideoSelected(string & videoPath);
void handleFboSelected(string & fboName);
// Careful clearing of the media server,
// clears only if the media server has been initialized locally

Loading…
Cancel
Save