73 changed files with 4869 additions and 4658 deletions
@ -1,17 +1,18 @@ |
|||
#include "PresentationState.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
PresentationState * PresentationState::_instance = 0; |
|||
|
|||
PresentationState * PresentationState::instance() { |
|||
if (_instance == 0) { |
|||
_instance = new ofx::piMapper::PresentationState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void PresentationState::draw(Application * app) {} |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
PresentationState * PresentationState::_instance = 0; |
|||
|
|||
PresentationState * PresentationState::instance(){ |
|||
if(_instance == 0){ |
|||
_instance = new ofx::piMapper::PresentationState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void PresentationState::draw(Application * app){} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,46 +1,47 @@ |
|||
#include "ProjectionMappingState.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
ProjectionMappingState * ProjectionMappingState::_instance = 0; |
|||
|
|||
ProjectionMappingState * ProjectionMappingState::instance() { |
|||
if (_instance == 0) { |
|||
_instance = new ofx::piMapper::ProjectionMappingState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void ProjectionMappingState::draw(Application * app) {} |
|||
|
|||
void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args) { |
|||
switch (args.key) { |
|||
|
|||
case 't': |
|||
app->getOfxPiMapper()->getCmdManager().exec( |
|||
new AddSurfaceCmd( |
|||
app->getOfxPiMapper(), |
|||
SurfaceType::TRIANGLE_SURFACE) |
|||
); |
|||
break; |
|||
|
|||
case 'q': |
|||
app->getOfxPiMapper()->getCmdManager().exec( |
|||
new AddSurfaceCmd( |
|||
app->getOfxPiMapper(), |
|||
SurfaceType::QUAD_SURFACE) |
|||
); |
|||
break; |
|||
|
|||
case OF_KEY_BACKSPACE: |
|||
app->getOfxPiMapper()->getCmdManager().exec( |
|||
new RmSurfaceCmd(app->getOfxPiMapper())); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
ProjectionMappingState * ProjectionMappingState::_instance = 0; |
|||
|
|||
ProjectionMappingState * ProjectionMappingState::instance(){ |
|||
if(_instance == 0){ |
|||
_instance = new ofx::piMapper::ProjectionMappingState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void ProjectionMappingState::draw(Application * app){} |
|||
|
|||
void ProjectionMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){ |
|||
switch(args.key){ |
|||
|
|||
case 't': |
|||
app->getOfxPiMapper()->getCmdManager().exec( |
|||
new AddSurfaceCmd( |
|||
app->getOfxPiMapper(), |
|||
SurfaceType::TRIANGLE_SURFACE) |
|||
); |
|||
break; |
|||
|
|||
case 'q': |
|||
app->getOfxPiMapper()->getCmdManager().exec( |
|||
new AddSurfaceCmd( |
|||
app->getOfxPiMapper(), |
|||
SurfaceType::QUAD_SURFACE) |
|||
); |
|||
break; |
|||
|
|||
case OF_KEY_BACKSPACE: |
|||
app->getOfxPiMapper()->getCmdManager().exec( |
|||
new RmSurfaceCmd(app->getOfxPiMapper())); |
|||
break; |
|||
|
|||
default: |
|||
break; |
|||
} |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,17 +1,18 @@ |
|||
#include "SourceSelectionState.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
SourceSelectionState * SourceSelectionState::_instance = 0; |
|||
|
|||
SourceSelectionState * SourceSelectionState::instance() { |
|||
if (_instance == 0) { |
|||
_instance = new ofx::piMapper::SourceSelectionState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void SourceSelectionState::draw(Application * app) {} |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
SourceSelectionState * SourceSelectionState::_instance = 0; |
|||
|
|||
SourceSelectionState * SourceSelectionState::instance(){ |
|||
if(_instance == 0){ |
|||
_instance = new ofx::piMapper::SourceSelectionState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void SourceSelectionState::draw(Application * app){} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,17 +1,18 @@ |
|||
#include "TextureMappingState.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
TextureMappingState * TextureMappingState::_instance = 0; |
|||
|
|||
TextureMappingState * TextureMappingState::instance() { |
|||
if (_instance == 0) { |
|||
_instance = new ofx::piMapper::TextureMappingState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void TextureMappingState::draw(Application * app) {} |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
TextureMappingState * TextureMappingState::_instance = 0; |
|||
|
|||
TextureMappingState * TextureMappingState::instance(){ |
|||
if(_instance == 0){ |
|||
_instance = new ofx::piMapper::TextureMappingState(); |
|||
} |
|||
return _instance; |
|||
} |
|||
|
|||
void TextureMappingState::draw(Application * app){} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,61 +1,61 @@ |
|||
#include "AddSurfaceCmd.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
AddSurfaceCmd::AddSurfaceCmd(ofxPiMapper * app, int surfaceType){ |
|||
_app = app; |
|||
_surfaceType = surfaceType; |
|||
} |
|||
|
|||
void AddSurfaceCmd::exec(){ |
|||
if (_surfaceType == SurfaceType::TRIANGLE_SURFACE) { |
|||
addTriangleSurface(); |
|||
} else if (_surfaceType == SurfaceType::QUAD_SURFACE) { |
|||
addQuadSurface(); |
|||
} |
|||
} |
|||
|
|||
void AddSurfaceCmd::undo(){ |
|||
ofLogNotice("AddSurfaceCmd", "undo"); |
|||
_app->getSurfaceManager().removeSurface(); |
|||
} |
|||
|
|||
void AddSurfaceCmd::addTriangleSurface() { |
|||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|||
|
|||
vector<ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(0.5f, 0.0f)); |
|||
texCoords.push_back(ofVec2f(1.0f, 1.0f)); |
|||
texCoords.push_back(ofVec2f(0.0f, 1.0f)); |
|||
_app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords); |
|||
} |
|||
|
|||
void AddSurfaceCmd::addQuadSurface() { |
|||
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
|||
|
|||
vector<ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f(margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
|||
|
|||
_app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords); |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
AddSurfaceCmd::AddSurfaceCmd(ofxPiMapper * app, int surfaceType){ |
|||
_app = app; |
|||
_surfaceType = surfaceType; |
|||
} |
|||
|
|||
void AddSurfaceCmd::exec(){ |
|||
if(_surfaceType == SurfaceType::TRIANGLE_SURFACE){ |
|||
addTriangleSurface(); |
|||
}else if(_surfaceType == SurfaceType::QUAD_SURFACE){ |
|||
addQuadSurface(); |
|||
} |
|||
} |
|||
|
|||
void AddSurfaceCmd::undo(){ |
|||
ofLogNotice("AddSurfaceCmd", "undo"); |
|||
_app->getSurfaceManager().removeSurface(); |
|||
} |
|||
|
|||
void AddSurfaceCmd::addTriangleSurface(){ |
|||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|||
|
|||
vector <ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector <ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(0.5f, 0.0f)); |
|||
texCoords.push_back(ofVec2f(1.0f, 1.0f)); |
|||
texCoords.push_back(ofVec2f(0.0f, 1.0f)); |
|||
_app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords); |
|||
} |
|||
|
|||
void AddSurfaceCmd::addQuadSurface(){ |
|||
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
|||
|
|||
vector <ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f(margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector <ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
|||
|
|||
_app->getSurfaceManager().addSurface(surfaceType, vertices, texCoords); |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,28 +1,28 @@ |
|||
#include "CmdManager.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
void CmdManager::exec(BaseCmd * cmd){ |
|||
cmd->exec(); |
|||
if (cmd->isUndoable()){ |
|||
cmdStack.push_back(static_cast<BaseUndoCmd *>(cmd)); |
|||
} |
|||
} |
|||
|
|||
void CmdManager::undo(){ |
|||
ofLogNotice("CmdManager", "undo"); |
|||
if (cmdStack.size() > 0){ |
|||
BaseUndoCmd * cmd = cmdStack.back(); |
|||
cmd->undo(); |
|||
|
|||
// Delete last command now, change this when implementing redo.
|
|||
delete cmdStack.back(); |
|||
cmdStack.pop_back(); |
|||
} else { |
|||
ofLogNotice("CmdManager", "Nothing to undo"); |
|||
} |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
void CmdManager::exec(BaseCmd * cmd){ |
|||
cmd->exec(); |
|||
if(cmd->isUndoable()){ |
|||
cmdStack.push_back(static_cast <BaseUndoCmd *>(cmd)); |
|||
} |
|||
} |
|||
|
|||
void CmdManager::undo(){ |
|||
ofLogNotice("CmdManager", "undo"); |
|||
if(cmdStack.size() > 0){ |
|||
BaseUndoCmd * cmd = cmdStack.back(); |
|||
cmd->undo(); |
|||
|
|||
// Delete last command now, change this when implementing redo.
|
|||
delete cmdStack.back(); |
|||
cmdStack.pop_back(); |
|||
}else{ |
|||
ofLogNotice("CmdManager", "Nothing to undo"); |
|||
} |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,27 +1,27 @@ |
|||
#include "MvAllTexCoordsCmd.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
MvAllTexCoordsCmd::MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor){ |
|||
_surface = surface; |
|||
_texEditor = texEditor; |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
void MvAllTexCoordsCmd::exec(){ |
|||
ofLogNotice("MvAllTexCoordsCmd", "exec"); |
|||
_texCoords = _surface->getTexCoords(); |
|||
} |
|||
|
|||
void MvAllTexCoordsCmd::undo(){ |
|||
ofLogNotice("MvAllTexCoordsCmd", "undo"); |
|||
ofVec2f dist = _texCoords[0] - _surface->getTexCoords()[0]; |
|||
dist.x = _surface->getSource()->getTexture()->getWidth() * dist.x; |
|||
dist.y = _surface->getSource()->getTexture()->getHeight() * dist.y; |
|||
_texEditor->moveTexCoords(dist); |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
MvAllTexCoordsCmd::MvAllTexCoordsCmd(BaseSurface * surface, TextureEditor * texEditor){ |
|||
_surface = surface; |
|||
_texEditor = texEditor; |
|||
} |
|||
|
|||
void MvAllTexCoordsCmd::exec(){ |
|||
ofLogNotice("MvAllTexCoordsCmd", "exec"); |
|||
_texCoords = _surface->getTexCoords(); |
|||
} |
|||
|
|||
void MvAllTexCoordsCmd::undo(){ |
|||
ofLogNotice("MvAllTexCoordsCmd", "undo"); |
|||
ofVec2f dist = _texCoords[0] - _surface->getTexCoords()[0]; |
|||
dist.x = _surface->getSource()->getTexture()->getWidth() * dist.x; |
|||
dist.y = _surface->getSource()->getTexture()->getHeight() * dist.y; |
|||
_texEditor->moveTexCoords(dist); |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,30 +1,29 @@ |
|||
#include "MvSurfaceCmd.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
MvSurfaceCmd::MvSurfaceCmd( |
|||
BaseSurface * surface, |
|||
ProjectionEditor * projectionEditor){ |
|||
|
|||
_surface = surface; |
|||
_projectionEditor = projectionEditor; |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
void MvSurfaceCmd::exec(){ |
|||
ofLogNotice("MvSurfaceCmd", "exec"); |
|||
_previousVertices = _surface->getVertices(); |
|||
_surface->setMoved(false); |
|||
} |
|||
|
|||
void MvSurfaceCmd::undo(){ |
|||
ofLogNotice("MvSurfaceCmd", "undo"); |
|||
_surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]); |
|||
_projectionEditor->updateJoints(); |
|||
_previousVertices.clear(); |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
MvSurfaceCmd::MvSurfaceCmd(BaseSurface * surface, |
|||
ProjectionEditor * projectionEditor){ |
|||
|
|||
_surface = surface; |
|||
_projectionEditor = projectionEditor; |
|||
} |
|||
|
|||
void MvSurfaceCmd::exec(){ |
|||
ofLogNotice("MvSurfaceCmd", "exec"); |
|||
_previousVertices = _surface->getVertices(); |
|||
_surface->setMoved(false); |
|||
} |
|||
|
|||
void MvSurfaceCmd::undo(){ |
|||
ofLogNotice("MvSurfaceCmd", "undo"); |
|||
_surface->moveBy(_previousVertices[0] - _surface->getVertices()[0]); |
|||
_projectionEditor->updateJoints(); |
|||
_previousVertices.clear(); |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,31 +1,30 @@ |
|||
#include "MvSurfaceVertCmd.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
MvSurfaceVertCmd::MvSurfaceVertCmd( |
|||
int vertIndex, |
|||
BaseSurface * surface, |
|||
ProjectionEditor * projectionEditor){ |
|||
|
|||
_vertIndex = vertIndex; |
|||
_surface = surface; |
|||
_projectionEditor = projectionEditor; |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
void MvSurfaceVertCmd::exec(){ |
|||
ofLogNotice("MvSurfaceVertCommand", "exec"); |
|||
_prevVertPos = _surface->getVertices()[_vertIndex]; |
|||
} |
|||
|
|||
void MvSurfaceVertCmd::undo(){ |
|||
ofLogNotice("MvSurfaceVertCommand", "undo"); |
|||
_surface->setVertex(_vertIndex, _prevVertPos); |
|||
_projectionEditor->updateJoints(); |
|||
_projectionEditor = 0; |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
MvSurfaceVertCmd::MvSurfaceVertCmd(int vertIndex, |
|||
BaseSurface * surface, |
|||
ProjectionEditor * projectionEditor){ |
|||
|
|||
_vertIndex = vertIndex; |
|||
_surface = surface; |
|||
_projectionEditor = projectionEditor; |
|||
} |
|||
|
|||
void MvSurfaceVertCmd::exec(){ |
|||
ofLogNotice("MvSurfaceVertCommand", "exec"); |
|||
_prevVertPos = _surface->getVertices()[_vertIndex]; |
|||
} |
|||
|
|||
void MvSurfaceVertCmd::undo(){ |
|||
ofLogNotice("MvSurfaceVertCommand", "undo"); |
|||
_surface->setVertex(_vertIndex, _prevVertPos); |
|||
_projectionEditor->updateJoints(); |
|||
_projectionEditor = 0; |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,26 +1,26 @@ |
|||
#include "MvTexCoordCmd.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
MvTexCoordCmd::MvTexCoordCmd(int jointIndex, TextureEditor * texEditor){ |
|||
_jointIndex = jointIndex; |
|||
_texEditor = texEditor; |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
void MvTexCoordCmd::exec(){ |
|||
ofLogNotice("MvTexCoordCmd", "exec"); |
|||
_jointPosition = _texEditor->getJoints()[_jointIndex]->position; |
|||
} |
|||
|
|||
void MvTexCoordCmd::undo(){ |
|||
ofLogNotice("MvTexCoordCmd", "undo"); |
|||
_texEditor->unselectAllJoints(); |
|||
_texEditor->getJoints()[_jointIndex]->select(); |
|||
_texEditor->getJoints()[_jointIndex]->position = _jointPosition; |
|||
_texEditor = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
MvTexCoordCmd::MvTexCoordCmd(int jointIndex, TextureEditor * texEditor){ |
|||
_jointIndex = jointIndex; |
|||
_texEditor = texEditor; |
|||
} |
|||
|
|||
void MvTexCoordCmd::exec(){ |
|||
ofLogNotice("MvTexCoordCmd", "exec"); |
|||
_jointPosition = _texEditor->getJoints()[_jointIndex]->position; |
|||
} |
|||
|
|||
void MvTexCoordCmd::undo(){ |
|||
ofLogNotice("MvTexCoordCmd", "undo"); |
|||
_texEditor->unselectAllJoints(); |
|||
_texEditor->getJoints()[_jointIndex]->select(); |
|||
_texEditor->getJoints()[_jointIndex]->position = _jointPosition; |
|||
_texEditor = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,30 +1,30 @@ |
|||
#include "RmSurfaceCmd.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
RmSurfaceCmd::RmSurfaceCmd(ofxPiMapper * app){ |
|||
_app = app; |
|||
_surface = 0; |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
void RmSurfaceCmd::exec(){ |
|||
// Store the surface, this implies that the surfaceManager's
|
|||
// removeSelectedSurface does not destroy the surface.
|
|||
_surface = _app->surfaceManager.getSelectedSurface(); |
|||
_app->surfaceManager.removeSelectedSurface(); |
|||
} |
|||
|
|||
void RmSurfaceCmd::undo(){ |
|||
ofLogNotice("RmSurfaceCmd", "undo"); |
|||
if (_surface == 0) { |
|||
ofLogError("RmSurfaceCmd", "No surface stored"); |
|||
} |
|||
_app->surfaceManager.addSurface(_surface); |
|||
_app->surfaceManager.selectSurface(_surface); |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
RmSurfaceCmd::RmSurfaceCmd(ofxPiMapper * app){ |
|||
_app = app; |
|||
_surface = 0; |
|||
} |
|||
|
|||
void RmSurfaceCmd::exec(){ |
|||
// Store the surface, this implies that the surfaceManager's
|
|||
// removeSelectedSurface does not destroy the surface.
|
|||
_surface = _app->surfaceManager.getSelectedSurface(); |
|||
_app->surfaceManager.removeSelectedSurface(); |
|||
} |
|||
|
|||
void RmSurfaceCmd::undo(){ |
|||
ofLogNotice("RmSurfaceCmd", "undo"); |
|||
if(_surface == 0){ |
|||
ofLogError("RmSurfaceCmd", "No surface stored"); |
|||
} |
|||
_app->surfaceManager.addSurface(_surface); |
|||
_app->surfaceManager.selectSurface(_surface); |
|||
_surface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,34 +1,33 @@ |
|||
#include "SelSurfaceCmd.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
|
|||
SelSurfaceCmd::SelSurfaceCmd( |
|||
SurfaceManager * surfaceManager, |
|||
BaseSurface * surfaceToSelect, |
|||
ProjectionEditor * projectionEditor){ |
|||
|
|||
_surfaceManager = surfaceManager; |
|||
_surfaceToSelect = surfaceToSelect; |
|||
_projectionEditor = projectionEditor; |
|||
} |
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
void SelSurfaceCmd::exec(){ |
|||
_prevSelectedSurface = _surfaceManager->getSelectedSurface(); |
|||
_projectionEditor->clearJoints(); |
|||
_surfaceManager->selectSurface(_surfaceToSelect); |
|||
_projectionEditor->createJoints(); |
|||
} |
|||
|
|||
void SelSurfaceCmd::undo(){ |
|||
ofLogNotice("SelSurfaceCmd", "undo"); |
|||
_projectionEditor->clearJoints(); |
|||
_surfaceManager->selectSurface(_prevSelectedSurface); |
|||
_projectionEditor->createJoints(); |
|||
_surfaceToSelect = 0; |
|||
_prevSelectedSurface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
SelSurfaceCmd::SelSurfaceCmd(SurfaceManager * surfaceManager, |
|||
BaseSurface * surfaceToSelect, |
|||
ProjectionEditor * projectionEditor){ |
|||
|
|||
_surfaceManager = surfaceManager; |
|||
_surfaceToSelect = surfaceToSelect; |
|||
_projectionEditor = projectionEditor; |
|||
} |
|||
|
|||
void SelSurfaceCmd::exec(){ |
|||
_prevSelectedSurface = _surfaceManager->getSelectedSurface(); |
|||
_projectionEditor->clearJoints(); |
|||
_surfaceManager->selectSurface(_surfaceToSelect); |
|||
_projectionEditor->createJoints(); |
|||
} |
|||
|
|||
void SelSurfaceCmd::undo(){ |
|||
ofLogNotice("SelSurfaceCmd", "undo"); |
|||
_projectionEditor->clearJoints(); |
|||
_surfaceManager->selectSurface(_prevSelectedSurface); |
|||
_projectionEditor->createJoints(); |
|||
_surfaceToSelect = 0; |
|||
_prevSelectedSurface = 0; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,42 +1,40 @@ |
|||
#include "SetApplicationStateCmd.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
SetApplicationStateCmd::SetApplicationStateCmd( |
|||
Application * app, |
|||
ApplicationBaseState * st, |
|||
|
|||
SurfaceManagerGui * gui, |
|||
int mode) { |
|||
|
|||
_application = app; |
|||
_prevApplicationState = 0; |
|||
_applicationState = st; |
|||
|
|||
// TODO: To be removed
|
|||
_gui = gui; |
|||
_prevGuiMode = -1; |
|||
_mode = mode; |
|||
} |
|||
|
|||
void SetApplicationStateCmd::exec() { |
|||
_prevApplicationState = _application->getState(); |
|||
_application->setState(_applicationState); |
|||
|
|||
// TODO: To be removed.
|
|||
_prevGuiMode = _gui->getMode(); |
|||
_gui->setMode(_mode); |
|||
} |
|||
|
|||
void SetApplicationStateCmd::undo() { |
|||
ofLogNotice("SetApplicationStateCmd", "undo"); |
|||
_application->setState(_prevApplicationState); |
|||
|
|||
// TODO: To be removed.
|
|||
_gui->setMode(_prevGuiMode); |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
namespace piMapper { |
|||
|
|||
SetApplicationStateCmd::SetApplicationStateCmd(Application * app, |
|||
ApplicationBaseState * st, |
|||
SurfaceManagerGui * gui, |
|||
int mode){ |
|||
|
|||
_application = app; |
|||
_prevApplicationState = 0; |
|||
_applicationState = st; |
|||
|
|||
// TODO: To be removed
|
|||
_gui = gui; |
|||
_prevGuiMode = -1; |
|||
_mode = mode; |
|||
} |
|||
|
|||
void SetApplicationStateCmd::exec(){ |
|||
_prevApplicationState = _application->getState(); |
|||
_application->setState(_applicationState); |
|||
|
|||
// TODO: To be removed.
|
|||
_prevGuiMode = _gui->getMode(); |
|||
_gui->setMode(_mode); |
|||
} |
|||
|
|||
void SetApplicationStateCmd::undo(){ |
|||
ofLogNotice("SetApplicationStateCmd", "undo"); |
|||
_application->setState(_prevApplicationState); |
|||
|
|||
// TODO: To be removed.
|
|||
_gui->setMode(_prevGuiMode); |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
|||
|
@ -1,57 +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 { |
|||
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
|
|||
|
|||
|
@ -1,59 +1,61 @@ |
|||
#include "BaseSource.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
BaseSource::BaseSource() { |
|||
//cout << "BaseSource" << endl;
|
|||
init(); |
|||
} |
|||
|
|||
BaseSource::BaseSource(ofTexture* newTexture) { |
|||
init(); |
|||
texture = newTexture; |
|||
} |
|||
|
|||
BaseSource::~BaseSource() {} |
|||
|
|||
ofTexture* BaseSource::getTexture() { |
|||
return texture; |
|||
} |
|||
|
|||
std::string& BaseSource::getName() { |
|||
return name; |
|||
} |
|||
|
|||
bool BaseSource::isLoadable() { |
|||
return loadable; |
|||
} |
|||
|
|||
bool BaseSource::isLoaded() { |
|||
return loaded; |
|||
} |
|||
|
|||
int BaseSource::getType() { |
|||
return type; |
|||
} |
|||
|
|||
std::string& BaseSource::getPath() { |
|||
return path; |
|||
} |
|||
|
|||
void BaseSource::init() { |
|||
texture = NULL; |
|||
name = ""; |
|||
path = ""; |
|||
loadable = false; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_NONE; |
|||
referenceCount = 1; // We have one instance on init
|
|||
} |
|||
|
|||
void BaseSource::setNameFromPath(std::string& fullPath) { |
|||
std::vector<string> pathParts; |
|||
//cout << "fullPath: " << fullPath << endl;
|
|||
pathParts = ofSplitString(fullPath, "/"); // Maybe on win "/" is "\", have to test
|
|||
//cout << "lastPathPart: " << pathParts[pathParts.size() - 1] << endl;
|
|||
name = pathParts[pathParts.size() - 1]; |
|||
} |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
BaseSource::BaseSource(){ |
|||
//cout << "BaseSource" << endl;
|
|||
init(); |
|||
} |
|||
|
|||
BaseSource::BaseSource(ofTexture * newTexture){ |
|||
init(); |
|||
texture = newTexture; |
|||
} |
|||
|
|||
BaseSource::~BaseSource(){} |
|||
|
|||
ofTexture * BaseSource::getTexture(){ |
|||
return texture; |
|||
} |
|||
|
|||
std::string & BaseSource::getName(){ |
|||
return name; |
|||
} |
|||
|
|||
bool BaseSource::isLoadable(){ |
|||
return loadable; |
|||
} |
|||
|
|||
bool BaseSource::isLoaded(){ |
|||
return loaded; |
|||
} |
|||
|
|||
int BaseSource::getType(){ |
|||
return type; |
|||
} |
|||
|
|||
std::string & BaseSource::getPath(){ |
|||
return path; |
|||
} |
|||
|
|||
void BaseSource::init(){ |
|||
texture = NULL; |
|||
name = ""; |
|||
path = ""; |
|||
loadable = false; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_NONE; |
|||
referenceCount = 1; // We have one instance on init
|
|||
} |
|||
|
|||
void BaseSource::setNameFromPath(std::string & fullPath){ |
|||
std::vector <string> pathParts; |
|||
//cout << "fullPath: " << fullPath << endl;
|
|||
pathParts = ofSplitString(fullPath, "/"); // Maybe on win "/" is "\", have to test
|
|||
//cout << "lastPathPart: " << pathParts[pathParts.size() - 1] << endl;
|
|||
name = pathParts[pathParts.size() - 1]; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,115 +1,115 @@ |
|||
#include "FboSource.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
FboSource::FboSource() : fbo(NULL) { |
|||
name = PIMAPPER_FBO_SOURCE_DEF_NAME; |
|||
loadable = false; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_FBO; |
|||
ofAddListener(ofEvents().setup, this, |
|||
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
|||
} |
|||
|
|||
FboSource::~FboSource() { |
|||
removeAppListeners(); |
|||
clear(); |
|||
} |
|||
|
|||
void FboSource::addAppListeners() { |
|||
ofLogNotice("FboSource") << "Adding app listeners"; |
|||
ofAddListener(ofEvents().update, this, |
|||
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofAddListener(ofEvents().draw, this, |
|||
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofAddListener(ofEvents().exit, this, |
|||
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
|||
} |
|||
|
|||
void FboSource::removeAppListeners() { |
|||
ofLogNotice("FboSource") << "Removing app listeners"; |
|||
ofRemoveListener(ofEvents().update, this, |
|||
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofRemoveListener(ofEvents().draw, this, |
|||
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofRemoveListener(ofEvents().exit, this, |
|||
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
|||
} |
|||
|
|||
void FboSource::onAppSetup(ofEventArgs &args) { |
|||
ofRemoveListener(ofEvents().setup, this, |
|||
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
|||
setup(); |
|||
|
|||
// Check if FBO was allocated in user defined setup
|
|||
// If not, show warning and alocate to avoid panic
|
|||
if (!fbo->isAllocated()) { |
|||
ofLogWarning("FboSource::onAppSetup") << |
|||
"FBO not allocated, allocating with default values"; |
|||
allocate(PIMAPPER_FBO_SOURCE_DEF_WIDTH, |
|||
PIMAPPER_FBO_SOURCE_DEF_HEIGHT); |
|||
} |
|||
} |
|||
|
|||
void FboSource::onAppUpdate(ofEventArgs &args) { |
|||
if (fbo == NULL || !fbo->isAllocated()) { |
|||
ofLogWarning("FboSource") << "FBO not allocated"; |
|||
return; |
|||
} |
|||
update(); |
|||
} |
|||
|
|||
void FboSource::onAppDraw(ofEventArgs &args) { |
|||
if (fbo == NULL || !fbo->isAllocated()) { |
|||
ofLogWarning("FboSource") << "FBO not allocated"; |
|||
return; |
|||
} |
|||
fbo->begin(); |
|||
draw(); |
|||
fbo->end(); |
|||
} |
|||
|
|||
void FboSource::onAppExit(ofEventArgs &args) { |
|||
exit(); |
|||
} |
|||
|
|||
void FboSource::allocate(int width, int height) { |
|||
clear(); |
|||
fbo = new ofFbo(); |
|||
fbo->allocate(width, height); |
|||
|
|||
// Clear FBO
|
|||
fbo->begin(); |
|||
ofClear(0); |
|||
fbo->end(); |
|||
|
|||
texture = &(fbo->getTextureReference()); |
|||
} |
|||
|
|||
void FboSource::clear() { |
|||
texture = NULL; |
|||
if (fbo != NULL) { |
|||
delete fbo; |
|||
fbo = NULL; |
|||
} |
|||
} |
|||
|
|||
int FboSource::getWidth() { |
|||
if (fbo->isAllocated()) { |
|||
return fbo->getWidth(); |
|||
} else { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
int FboSource::getHeight() { |
|||
if (fbo->isAllocated()) { |
|||
return fbo->getHeight(); |
|||
} else { |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
namespace piMapper { |
|||
|
|||
FboSource::FboSource() : fbo(NULL){ |
|||
name = PIMAPPER_FBO_SOURCE_DEF_NAME; |
|||
loadable = false; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_FBO; |
|||
ofAddListener(ofEvents().setup, this, |
|||
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
|||
} |
|||
|
|||
FboSource::~FboSource(){ |
|||
removeAppListeners(); |
|||
clear(); |
|||
} |
|||
|
|||
void FboSource::addAppListeners(){ |
|||
ofLogNotice("FboSource") << "Adding app listeners"; |
|||
ofAddListener(ofEvents().update, this, |
|||
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofAddListener(ofEvents().draw, this, |
|||
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofAddListener(ofEvents().exit, this, |
|||
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
|||
} |
|||
|
|||
void FboSource::removeAppListeners(){ |
|||
ofLogNotice("FboSource") << "Removing app listeners"; |
|||
ofRemoveListener(ofEvents().update, this, |
|||
&FboSource::onAppUpdate, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofRemoveListener(ofEvents().draw, this, |
|||
&FboSource::onAppDraw, OF_EVENT_ORDER_BEFORE_APP); |
|||
ofRemoveListener(ofEvents().exit, this, |
|||
&FboSource::onAppExit, OF_EVENT_ORDER_AFTER_APP); |
|||
} |
|||
|
|||
void FboSource::onAppSetup(ofEventArgs & args){ |
|||
ofRemoveListener(ofEvents().setup, this, |
|||
&FboSource::onAppSetup, OF_EVENT_ORDER_BEFORE_APP); |
|||
setup(); |
|||
|
|||
// Check if FBO was allocated in user defined setup
|
|||
// If not, show warning and alocate to avoid panic
|
|||
if(!fbo->isAllocated()){ |
|||
ofLogWarning("FboSource::onAppSetup") |
|||
<< "FBO not allocated, allocating with default values"; |
|||
allocate(PIMAPPER_FBO_SOURCE_DEF_WIDTH, |
|||
PIMAPPER_FBO_SOURCE_DEF_HEIGHT); |
|||
} |
|||
} |
|||
|
|||
void FboSource::onAppUpdate(ofEventArgs & args){ |
|||
if(fbo == NULL || !fbo->isAllocated()){ |
|||
ofLogWarning("FboSource") << "FBO not allocated"; |
|||
return; |
|||
} |
|||
update(); |
|||
} |
|||
|
|||
void FboSource::onAppDraw(ofEventArgs & args){ |
|||
if(fbo == NULL || !fbo->isAllocated()){ |
|||
ofLogWarning("FboSource") << "FBO not allocated"; |
|||
return; |
|||
} |
|||
fbo->begin(); |
|||
draw(); |
|||
fbo->end(); |
|||
} |
|||
|
|||
void FboSource::onAppExit(ofEventArgs & args){ |
|||
exit(); |
|||
} |
|||
|
|||
void FboSource::allocate(int width, int height){ |
|||
clear(); |
|||
fbo = new ofFbo(); |
|||
fbo->allocate(width, height); |
|||
|
|||
// Clear FBO
|
|||
fbo->begin(); |
|||
ofClear(0); |
|||
fbo->end(); |
|||
|
|||
texture = &(fbo->getTextureReference()); |
|||
} |
|||
|
|||
void FboSource::clear(){ |
|||
texture = NULL; |
|||
if(fbo != NULL){ |
|||
delete fbo; |
|||
fbo = NULL; |
|||
} |
|||
} |
|||
|
|||
int FboSource::getWidth(){ |
|||
if(fbo->isAllocated()){ |
|||
return fbo->getWidth(); |
|||
}else{ |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
int FboSource::getHeight(){ |
|||
if(fbo->isAllocated()){ |
|||
return fbo->getHeight(); |
|||
}else{ |
|||
return 0; |
|||
} |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,39 +1,40 @@ |
|||
#include "ImageSource.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
ImageSource::ImageSource() { |
|||
//cout << "ImageSource" << endl;
|
|||
loadable = true; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_IMAGE; |
|||
} |
|||
|
|||
ImageSource::~ImageSource() {} |
|||
|
|||
void ImageSource::loadImage(std::string& filePath) { |
|||
path = filePath; |
|||
//cout << "loading image: " << filePath << endl;
|
|||
setNameFromPath(filePath); |
|||
//cout << "path: " << path << endl;
|
|||
image = new ofImage(); |
|||
if (!image->loadImage(filePath)) { |
|||
ofLogWarning("ImageSource") << "Could not load image"; |
|||
//std::exit(EXIT_FAILURE);
|
|||
} |
|||
texture = &image->getTextureReference(); |
|||
loaded = true; |
|||
} |
|||
|
|||
void ImageSource::clear() { |
|||
texture = NULL; |
|||
image->clear(); |
|||
delete image; |
|||
image = NULL; |
|||
//path = "";
|
|||
//name = "";
|
|||
loaded = false; |
|||
} |
|||
|
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
ImageSource::ImageSource(){ |
|||
//cout << "ImageSource" << endl;
|
|||
loadable = true; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_IMAGE; |
|||
} |
|||
|
|||
ImageSource::~ImageSource(){} |
|||
|
|||
void ImageSource::loadImage(std::string & filePath){ |
|||
path = filePath; |
|||
//cout << "loading image: " << filePath << endl;
|
|||
setNameFromPath(filePath); |
|||
//cout << "path: " << path << endl;
|
|||
image = new ofImage(); |
|||
if(!image->loadImage(filePath)){ |
|||
ofLogWarning("ImageSource") << "Could not load image"; |
|||
//std::exit(EXIT_FAILURE);
|
|||
} |
|||
texture = &image->getTextureReference(); |
|||
loaded = true; |
|||
} |
|||
|
|||
void ImageSource::clear(){ |
|||
texture = NULL; |
|||
image->clear(); |
|||
delete image; |
|||
image = NULL; |
|||
//path = "";
|
|||
//name = "";
|
|||
loaded = false; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,70 +1,71 @@ |
|||
#include "VideoSource.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
bool VideoSource::enableAudio = false; |
|||
|
|||
VideoSource::VideoSource() { |
|||
loadable = true; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_VIDEO; |
|||
#ifdef TARGET_RASPBERRY_PI |
|||
omxPlayer = NULL; |
|||
#else |
|||
videoPlayer = NULL; |
|||
#endif |
|||
} |
|||
|
|||
VideoSource::~VideoSource() {} |
|||
|
|||
void VideoSource::loadVideo(std::string & filePath) { |
|||
path = filePath; |
|||
setNameFromPath(filePath); |
|||
#ifdef TARGET_RASPBERRY_PI |
|||
ofxOMXPlayerSettings settings; |
|||
settings.videoPath = filePath; |
|||
settings.useHDMIForAudio = true; |
|||
settings.enableTexture = true; |
|||
settings.enableLooping = true; |
|||
settings.enableAudio = VideoSource::enableAudio; |
|||
omxPlayer = new ofxOMXPlayer(); |
|||
omxPlayer->setup(settings); |
|||
texture = &(omxPlayer->getTextureReference()); |
|||
#else |
|||
videoPlayer = new ofVideoPlayer(); |
|||
videoPlayer->load(filePath); |
|||
videoPlayer->setLoopState(OF_LOOP_NORMAL); |
|||
videoPlayer->setVolume(VideoSource::enableAudio ? 1.0f : 0.0f); |
|||
videoPlayer->play(); |
|||
texture = &(videoPlayer->getTexture()); |
|||
ofAddListener(ofEvents().update, this, &VideoSource::update); |
|||
#endif |
|||
loaded = true; |
|||
} |
|||
|
|||
void VideoSource::clear() { |
|||
texture = NULL; |
|||
#ifdef TARGET_RASPBERRY_PI |
|||
omxPlayer->close(); |
|||
delete omxPlayer; |
|||
omxPlayer = NULL; |
|||
#else |
|||
ofRemoveListener(ofEvents().update, this, &VideoSource::update); |
|||
videoPlayer->stop(); |
|||
videoPlayer->close(); |
|||
delete videoPlayer; |
|||
videoPlayer = NULL; |
|||
#endif |
|||
loaded = false; |
|||
} |
|||
|
|||
namespace piMapper { |
|||
|
|||
bool VideoSource::enableAudio = false; |
|||
|
|||
VideoSource::VideoSource(){ |
|||
loadable = true; |
|||
loaded = false; |
|||
type = SourceType::SOURCE_TYPE_VIDEO; |
|||
#ifdef TARGET_RASPBERRY_PI |
|||
omxPlayer = NULL; |
|||
#else |
|||
videoPlayer = NULL; |
|||
#endif |
|||
} |
|||
|
|||
VideoSource::~VideoSource(){} |
|||
|
|||
void VideoSource::loadVideo(std::string & filePath){ |
|||
path = filePath; |
|||
setNameFromPath(filePath); |
|||
#ifdef TARGET_RASPBERRY_PI |
|||
ofxOMXPlayerSettings settings; |
|||
settings.videoPath = filePath; |
|||
settings.useHDMIForAudio = true; |
|||
settings.enableTexture = true; |
|||
settings.enableLooping = true; |
|||
settings.enableAudio = VideoSource::enableAudio; |
|||
omxPlayer = new ofxOMXPlayer(); |
|||
omxPlayer->setup(settings); |
|||
texture = &(omxPlayer->getTextureReference()); |
|||
#else |
|||
videoPlayer = new ofVideoPlayer(); |
|||
videoPlayer->load(filePath); |
|||
videoPlayer->setLoopState(OF_LOOP_NORMAL); |
|||
videoPlayer->setVolume(VideoSource::enableAudio ? 1.0f : 0.0f); |
|||
videoPlayer->play(); |
|||
texture = &(videoPlayer->getTexture()); |
|||
ofAddListener(ofEvents().update, this, &VideoSource::update); |
|||
#endif |
|||
loaded = true; |
|||
} |
|||
|
|||
void VideoSource::clear(){ |
|||
texture = NULL; |
|||
#ifdef TARGET_RASPBERRY_PI |
|||
omxPlayer->close(); |
|||
delete omxPlayer; |
|||
omxPlayer = NULL; |
|||
#else |
|||
ofRemoveListener(ofEvents().update, this, &VideoSource::update); |
|||
videoPlayer->stop(); |
|||
videoPlayer->close(); |
|||
delete videoPlayer; |
|||
videoPlayer = NULL; |
|||
#endif |
|||
loaded = false; |
|||
} |
|||
|
|||
#ifndef TARGET_RASPBERRY_PI |
|||
void VideoSource::update(ofEventArgs & args) { |
|||
if (videoPlayer != NULL) { |
|||
videoPlayer->update(); |
|||
} |
|||
} |
|||
void VideoSource::update(ofEventArgs & args){ |
|||
if(videoPlayer != NULL){ |
|||
videoPlayer->update(); |
|||
} |
|||
} |
|||
#endif |
|||
} // namespace piMapper
|
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,94 +1,100 @@ |
|||
#include "BaseSurface.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
BaseSurface::BaseSurface() { |
|||
_moved = false; |
|||
ofEnableNormalizedTexCoords(); |
|||
createDefaultTexture(); |
|||
} |
|||
|
|||
BaseSurface::~BaseSurface() { |
|||
delete defaultSource; |
|||
defaultSource = NULL; |
|||
defaultTexture.clear(); |
|||
} |
|||
|
|||
void BaseSurface::createDefaultTexture() { |
|||
ofPixels pixels; |
|||
pixels.allocate(500, 500, 1); |
|||
for (int i = 0; i < pixels.size(); i++) { |
|||
pixels[i] = 255; |
|||
} |
|||
int squareSize = 10; // size of each test pattern square
|
|||
bool sy = false; |
|||
for (int y = 0; y < pixels.getWidth(); y += squareSize) { |
|||
bool sx = false; |
|||
for (int x = 0; x < pixels.getHeight(); x += squareSize) { |
|||
for (int yi = 0; yi < squareSize; yi++) { |
|||
for (int xi = 0; xi < squareSize; xi++) { |
|||
if (sx && sy) |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
|||
else if (sx && !sy) |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
|||
else if (!sx && sy) |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
|||
else |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
|||
} |
|||
} |
|||
sx = !sx; |
|||
} |
|||
sy = !sy; |
|||
} |
|||
|
|||
// load pixels into texture
|
|||
defaultTexture.loadData(pixels); |
|||
// Create new source to be the default
|
|||
defaultSource = new BaseSource(&defaultTexture); |
|||
source = defaultSource; |
|||
} |
|||
|
|||
void BaseSurface::drawTexture(ofVec2f position) { |
|||
if (source->getTexture() == NULL) { |
|||
ofLogWarning("BaseSurface") << "Source texture empty. Not drawing."; |
|||
return; |
|||
} |
|||
|
|||
ofMesh texMesh; |
|||
texMesh.addVertex(position); |
|||
texMesh.addVertex(position + ofVec2f(source->getTexture()->getWidth(), 0.0f)); |
|||
texMesh.addVertex(position + |
|||
ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight())); |
|||
texMesh.addVertex(position + ofVec2f(0.0f, source->getTexture()->getHeight())); |
|||
texMesh.addTriangle(0, 2, 3); |
|||
texMesh.addTriangle(0, 1, 2); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); |
|||
source->getTexture()->bind(); |
|||
texMesh.draw(); |
|||
source->getTexture()->unbind(); |
|||
} |
|||
|
|||
//void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; }
|
|||
void BaseSurface::setSource(BaseSource* newSource) { |
|||
source = newSource; |
|||
} |
|||
|
|||
//ofTexture* BaseSurface::getTexture() { return texture; }
|
|||
BaseSource* BaseSurface::getSource() { |
|||
return source; |
|||
} |
|||
|
|||
//ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; }
|
|||
BaseSource* BaseSurface::getDefaultSource() { |
|||
return defaultSource; |
|||
} |
|||
|
|||
void BaseSurface::setMoved(bool moved){ _moved = moved; } |
|||
bool BaseSurface::getMoved(){ return _moved; } |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
BaseSurface::BaseSurface(){ |
|||
_moved = false; |
|||
ofEnableNormalizedTexCoords(); |
|||
createDefaultTexture(); |
|||
} |
|||
|
|||
BaseSurface::~BaseSurface(){ |
|||
delete defaultSource; |
|||
defaultSource = NULL; |
|||
defaultTexture.clear(); |
|||
} |
|||
|
|||
void BaseSurface::createDefaultTexture(){ |
|||
ofPixels pixels; |
|||
pixels.allocate(500, 500, 1); |
|||
for(int i = 0; i < pixels.size(); i++){ |
|||
pixels[i] = 255; |
|||
} |
|||
int squareSize = 10; // size of each test pattern square
|
|||
bool sy = false; |
|||
for(int y = 0; y < pixels.getWidth(); y += squareSize){ |
|||
bool sx = false; |
|||
for(int x = 0; x < pixels.getHeight(); x += squareSize){ |
|||
for(int yi = 0; yi < squareSize; yi++){ |
|||
for(int xi = 0; xi < squareSize; xi++){ |
|||
if(sx && sy){ |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
|||
}else if(sx && !sy){ |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
|||
}else if(!sx && sy){ |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
|||
}else{ |
|||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
|||
} |
|||
} |
|||
} |
|||
sx = !sx; |
|||
} |
|||
sy = !sy; |
|||
} |
|||
|
|||
// load pixels into texture
|
|||
defaultTexture.loadData(pixels); |
|||
// Create new source to be the default
|
|||
defaultSource = new BaseSource(&defaultTexture); |
|||
source = defaultSource; |
|||
} |
|||
|
|||
void BaseSurface::drawTexture(ofVec2f position){ |
|||
if(source->getTexture() == NULL){ |
|||
ofLogWarning("BaseSurface") << "Source texture empty. Not drawing."; |
|||
return; |
|||
} |
|||
|
|||
ofMesh texMesh; |
|||
texMesh.addVertex(position); |
|||
texMesh.addVertex(position + ofVec2f(source->getTexture()->getWidth(), 0.0f)); |
|||
texMesh.addVertex(position |
|||
+ ofVec2f(source->getTexture()->getWidth(), source->getTexture()->getHeight())); |
|||
texMesh.addVertex(position + ofVec2f(0.0f, source->getTexture()->getHeight())); |
|||
texMesh.addTriangle(0, 2, 3); |
|||
texMesh.addTriangle(0, 1, 2); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 0.0f)); |
|||
texMesh.addTexCoord(ofVec2f(1.0f, 1.0f)); |
|||
texMesh.addTexCoord(ofVec2f(0.0f, 1.0f)); |
|||
source->getTexture()->bind(); |
|||
texMesh.draw(); |
|||
source->getTexture()->unbind(); |
|||
} |
|||
|
|||
//void BaseSurface::setTexture(ofTexture* texturePtr) { texture = texturePtr; }
|
|||
void BaseSurface::setSource(BaseSource * newSource){ |
|||
source = newSource; |
|||
} |
|||
|
|||
//ofTexture* BaseSurface::getTexture() { return texture; }
|
|||
BaseSource * BaseSurface::getSource(){ |
|||
return source; |
|||
} |
|||
|
|||
//ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; }
|
|||
BaseSource * BaseSurface::getDefaultSource(){ |
|||
return defaultSource; |
|||
} |
|||
|
|||
void BaseSurface::setMoved(bool moved){ |
|||
_moved = moved; |
|||
} |
|||
bool BaseSurface::getMoved(){ |
|||
return _moved; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,311 +1,322 @@ |
|||
#include "SurfaceManagerGui.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
SurfaceManagerGui::SurfaceManagerGui() { |
|||
surfaceManager = NULL; |
|||
guiMode = GuiMode::NONE; |
|||
bDrag = false; |
|||
registerMouseEvents(); |
|||
ofHideCursor(); |
|||
_cmdManager = 0; |
|||
} |
|||
|
|||
SurfaceManagerGui::~SurfaceManagerGui() { |
|||
unregisterMouseEvents(); |
|||
surfaceManager = NULL; |
|||
_cmdManager = 0; |
|||
} |
|||
|
|||
void SurfaceManagerGui::registerMouseEvents() { |
|||
ofAddListener(ofEvents().mousePressed, this, |
|||
&SurfaceManagerGui::mousePressed); |
|||
ofAddListener(ofEvents().mouseReleased, this, |
|||
&SurfaceManagerGui::mouseReleased); |
|||
ofAddListener(ofEvents().mouseDragged, this, |
|||
&SurfaceManagerGui::mouseDragged); |
|||
} |
|||
|
|||
void SurfaceManagerGui::unregisterMouseEvents() { |
|||
ofRemoveListener(ofEvents().mousePressed, this, |
|||
&SurfaceManagerGui::mousePressed); |
|||
ofRemoveListener(ofEvents().mouseReleased, this, |
|||
&SurfaceManagerGui::mouseReleased); |
|||
ofRemoveListener(ofEvents().mouseDragged, this, |
|||
&SurfaceManagerGui::mouseDragged); |
|||
} |
|||
|
|||
void SurfaceManagerGui::draw() { |
|||
if (surfaceManager == NULL) return; |
|||
|
|||
if (guiMode == GuiMode::NONE) { |
|||
surfaceManager->draw(); |
|||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
// draw the texture of the selected surface
|
|||
if (surfaceManager->getSelectedSurface() != NULL) { |
|||
// Reset default color to white first
|
|||
ofSetColor(255, 255, 255, 255); |
|||
surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); |
|||
} |
|||
|
|||
// draw surfaces with opacity
|
|||
ofPushStyle(); |
|||
ofSetColor(255, 255, 255, 200); |
|||
surfaceManager->draw(); |
|||
ofPopStyle(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// hilight selected surface texture
|
|||
drawSelectedSurfaceTextureHighlight(); |
|||
|
|||
// draw texture editing GUI on top
|
|||
textureEditor.draw(); |
|||
|
|||
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// draw projection mapping editing gui
|
|||
projectionEditor.draw(); |
|||
|
|||
} else if (guiMode == GuiMode::SOURCE_SELECTION) { |
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
sourcesEditor.draw(); |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
|||
if (guiMode == GuiMode::NONE) { |
|||
return; |
|||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
bool bSurfaceSelected = false; |
|||
CircleJoint* hitJoint = |
|||
textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if (hitJoint != NULL) { |
|||
textureEditor.unselectAllJoints(); |
|||
|
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
bSurfaceSelected = true; |
|||
|
|||
int jointIndex = -1; |
|||
for (int i = 0; i < textureEditor.getJoints().size(); i++) { |
|||
if (textureEditor.getJoints()[i] == hitJoint) { |
|||
jointIndex = i; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (jointIndex != -1) { |
|||
_cmdManager->exec(new MvTexCoordCmd(jointIndex, &textureEditor)); |
|||
} |
|||
|
|||
} else { |
|||
textureEditor.unselectAllJoints(); |
|||
} |
|||
|
|||
if (surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected) { |
|||
// hittest texture area to see if we are hitting the texture surface
|
|||
if (surfaceManager->getSelectedSurface()->getTextureHitArea().inside( |
|||
args.x, args.y)) { |
|||
|
|||
// TODO: move these to a separate routine
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
|
|||
_cmdManager->exec(new MvAllTexCoordsCmd( |
|||
surfaceManager->getSelectedSurface(), |
|||
&textureEditor)); |
|||
|
|||
} |
|||
} |
|||
|
|||
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
bool bSurfaceSelected = false; |
|||
|
|||
CircleJoint* hitJoint = |
|||
projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if (hitJoint != NULL) { |
|||
projectionEditor.unselectAllJoints(); |
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
int jointVertIndex = 0; |
|||
for (int i = 0; i < projectionEditor.getJoints()->size(); i++) { |
|||
if ((*projectionEditor.getJoints())[i] == hitJoint) { |
|||
jointVertIndex = i; |
|||
break; |
|||
} |
|||
} |
|||
_cmdManager->exec(new MvSurfaceVertCmd( |
|||
jointVertIndex, |
|||
surfaceManager->getSelectedSurface(), |
|||
&projectionEditor)); |
|||
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))) { |
|||
|
|||
// Do not repeat this command if attempting to select an
|
|||
// already selected surface.
|
|||
if (surfaceManager->getSelectedSurface() != surfaceManager->getSurface(i)){ |
|||
_cmdManager->exec(new SelSurfaceCmd( |
|||
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 surface
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
|
|||
_cmdManager->exec( |
|||
new MvSurfaceCmd( |
|||
surfaceManager->getSelectedSurface(), |
|||
&projectionEditor)); |
|||
} |
|||
|
|||
if (!bSurfaceSelected) { |
|||
// unselect if no surface selected
|
|||
projectionEditor.clearJoints(); |
|||
surfaceManager->deselectSurface(); |
|||
} |
|||
} else if (guiMode == GuiMode::SOURCE_SELECTION) { |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) { |
|||
stopDrag(); |
|||
projectionEditor.stopDragJoints(); |
|||
textureEditor.stopDragJoints(); |
|||
|
|||
// Check if surface has moved
|
|||
if (surfaceManager->getSelectedSurface()){ |
|||
if (!surfaceManager->getSelectedSurface()->getMoved()) { |
|||
_cmdManager->undo(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { |
|||
if (bDrag) { |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
ofVec2f distance = mousePosition - clickPosition; |
|||
|
|||
if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
// add this distance to all vertices in surface
|
|||
projectionEditor.moveSelectedSurface(distance); |
|||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
textureEditor.moveTexCoords(distance); |
|||
} |
|||
clickPosition = mousePosition; |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|||
surfaceManager = newSurfaceManager; |
|||
projectionEditor.setSurfaceManager(surfaceManager); |
|||
sourcesEditor.setSurfaceManager(surfaceManager); |
|||
} |
|||
|
|||
// Set external media server so we can access it from wherever we need
|
|||
void SurfaceManagerGui::setMediaServer(MediaServer* newMediaServer) { |
|||
mediaServer = newMediaServer; |
|||
// Set the media server of the sources editor here
|
|||
sourcesEditor.setMediaServer(mediaServer); |
|||
} |
|||
|
|||
void SurfaceManagerGui::setCmdManager(CmdManager * cmdManager){ |
|||
_cmdManager = cmdManager; |
|||
sourcesEditor.setCmdManager(_cmdManager); |
|||
} |
|||
|
|||
void SurfaceManagerGui::setMode(int newGuiMode) { |
|||
if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && |
|||
newGuiMode != GuiMode::PROJECTION_MAPPING && |
|||
newGuiMode != GuiMode::SOURCE_SELECTION) { |
|||
throw std::runtime_error("Trying to set invalid mode."); |
|||
} |
|||
|
|||
if (newGuiMode == GuiMode::NONE) { |
|||
ofHideCursor(); |
|||
} else { |
|||
ofShowCursor(); |
|||
} |
|||
|
|||
guiMode = newGuiMode; |
|||
|
|||
if (guiMode == GuiMode::SOURCE_SELECTION) { |
|||
sourcesEditor.enable(); |
|||
//string sourceName = surfaceManager->getSelectedSurfaceSourceName();
|
|||
//sourcesEditor.selectImageSourceRadioButton(sourceName);
|
|||
} else { |
|||
sourcesEditor.disable(); |
|||
} |
|||
|
|||
if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|||
textureEditor.enable(); |
|||
// refresh texture editor surface reference
|
|||
textureEditor.setSurface(surfaceManager->getSelectedSurface()); |
|||
} else { |
|||
textureEditor.disable(); |
|||
} |
|||
|
|||
if (guiMode == GuiMode::PROJECTION_MAPPING) { |
|||
projectionEditor.enable(); |
|||
} else { |
|||
projectionEditor.disable(); |
|||
} |
|||
} |
|||
|
|||
int SurfaceManagerGui::getMode(){ |
|||
return guiMode; |
|||
} |
|||
|
|||
void SurfaceManagerGui::drawSelectedSurfaceHighlight() { |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); |
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 255, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
} |
|||
|
|||
void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight() { |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); |
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 0, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
} |
|||
|
|||
void SurfaceManagerGui::startDrag() { bDrag = true; } |
|||
|
|||
void SurfaceManagerGui::stopDrag() { bDrag = false; } |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
SurfaceManagerGui::SurfaceManagerGui(){ |
|||
surfaceManager = NULL; |
|||
guiMode = GuiMode::NONE; |
|||
bDrag = false; |
|||
registerMouseEvents(); |
|||
ofHideCursor(); |
|||
_cmdManager = 0; |
|||
} |
|||
|
|||
SurfaceManagerGui::~SurfaceManagerGui(){ |
|||
unregisterMouseEvents(); |
|||
surfaceManager = NULL; |
|||
_cmdManager = 0; |
|||
} |
|||
|
|||
void SurfaceManagerGui::registerMouseEvents(){ |
|||
ofAddListener(ofEvents().mousePressed, this, |
|||
&SurfaceManagerGui::mousePressed); |
|||
ofAddListener(ofEvents().mouseReleased, this, |
|||
&SurfaceManagerGui::mouseReleased); |
|||
ofAddListener(ofEvents().mouseDragged, this, |
|||
&SurfaceManagerGui::mouseDragged); |
|||
} |
|||
|
|||
void SurfaceManagerGui::unregisterMouseEvents(){ |
|||
ofRemoveListener(ofEvents().mousePressed, this, |
|||
&SurfaceManagerGui::mousePressed); |
|||
ofRemoveListener(ofEvents().mouseReleased, this, |
|||
&SurfaceManagerGui::mouseReleased); |
|||
ofRemoveListener(ofEvents().mouseDragged, this, |
|||
&SurfaceManagerGui::mouseDragged); |
|||
} |
|||
|
|||
void SurfaceManagerGui::draw(){ |
|||
if(surfaceManager == NULL){ |
|||
return; |
|||
} |
|||
|
|||
if(guiMode == GuiMode::NONE){ |
|||
surfaceManager->draw(); |
|||
}else if(guiMode == GuiMode::TEXTURE_MAPPING){ |
|||
// draw the texture of the selected surface
|
|||
if(surfaceManager->getSelectedSurface() != NULL){ |
|||
// Reset default color to white first
|
|||
ofSetColor(255, 255, 255, 255); |
|||
surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); |
|||
} |
|||
|
|||
// draw surfaces with opacity
|
|||
ofPushStyle(); |
|||
ofSetColor(255, 255, 255, 200); |
|||
surfaceManager->draw(); |
|||
ofPopStyle(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// hilight selected surface texture
|
|||
drawSelectedSurfaceTextureHighlight(); |
|||
|
|||
// draw texture editing GUI on top
|
|||
textureEditor.draw(); |
|||
|
|||
}else if(guiMode == GuiMode::PROJECTION_MAPPING){ |
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
// draw projection mapping editing gui
|
|||
projectionEditor.draw(); |
|||
|
|||
}else if(guiMode == GuiMode::SOURCE_SELECTION){ |
|||
// draw projection surfaces first
|
|||
surfaceManager->draw(); |
|||
|
|||
// highlight selected surface
|
|||
drawSelectedSurfaceHighlight(); |
|||
|
|||
sourcesEditor.draw(); |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::mousePressed(ofMouseEventArgs & args){ |
|||
if(guiMode == GuiMode::NONE){ |
|||
return; |
|||
}else if(guiMode == GuiMode::TEXTURE_MAPPING){ |
|||
bool bSurfaceSelected = false; |
|||
CircleJoint * hitJoint = |
|||
textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if(hitJoint != NULL){ |
|||
textureEditor.unselectAllJoints(); |
|||
|
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
bSurfaceSelected = true; |
|||
|
|||
int jointIndex = -1; |
|||
for(int i = 0; i < textureEditor.getJoints().size(); i++){ |
|||
if(textureEditor.getJoints()[i] == hitJoint){ |
|||
jointIndex = i; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if(jointIndex != -1){ |
|||
_cmdManager->exec(new MvTexCoordCmd(jointIndex, &textureEditor)); |
|||
} |
|||
|
|||
}else{ |
|||
textureEditor.unselectAllJoints(); |
|||
} |
|||
|
|||
if(surfaceManager->getSelectedSurface() != NULL && !bSurfaceSelected){ |
|||
// hittest texture area to see if we are hitting the texture surface
|
|||
if(surfaceManager->getSelectedSurface()->getTextureHitArea().inside( |
|||
args.x, args.y)){ |
|||
|
|||
// TODO: move these to a separate routine
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
|
|||
_cmdManager->exec(new MvAllTexCoordsCmd( |
|||
surfaceManager->getSelectedSurface(), |
|||
&textureEditor)); |
|||
|
|||
} |
|||
} |
|||
|
|||
}else if(guiMode == GuiMode::PROJECTION_MAPPING){ |
|||
bool bSurfaceSelected = false; |
|||
|
|||
CircleJoint * hitJoint = |
|||
projectionEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
|||
if(hitJoint != NULL){ |
|||
projectionEditor.unselectAllJoints(); |
|||
hitJoint->select(); |
|||
hitJoint->startDrag(); |
|||
int jointVertIndex = 0; |
|||
for(int i = 0; i < projectionEditor.getJoints()->size(); i++){ |
|||
if((*projectionEditor.getJoints())[i] == hitJoint){ |
|||
jointVertIndex = i; |
|||
break; |
|||
} |
|||
} |
|||
_cmdManager->exec(new MvSurfaceVertCmd( |
|||
jointVertIndex, |
|||
surfaceManager->getSelectedSurface(), |
|||
&projectionEditor)); |
|||
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))){ |
|||
|
|||
// Do not repeat this command if attempting to select an
|
|||
// already selected surface.
|
|||
if(surfaceManager->getSelectedSurface() != surfaceManager->getSurface(i)){ |
|||
_cmdManager->exec(new SelSurfaceCmd( |
|||
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 surface
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
|
|||
_cmdManager->exec( |
|||
new MvSurfaceCmd( |
|||
surfaceManager->getSelectedSurface(), |
|||
&projectionEditor)); |
|||
} |
|||
|
|||
if(!bSurfaceSelected){ |
|||
// unselect if no surface selected
|
|||
projectionEditor.clearJoints(); |
|||
surfaceManager->deselectSurface(); |
|||
} |
|||
}else if(guiMode == GuiMode::SOURCE_SELECTION){} |
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs & args){ |
|||
stopDrag(); |
|||
projectionEditor.stopDragJoints(); |
|||
textureEditor.stopDragJoints(); |
|||
|
|||
// Check if surface has moved
|
|||
if(surfaceManager->getSelectedSurface()){ |
|||
if(!surfaceManager->getSelectedSurface()->getMoved()){ |
|||
_cmdManager->undo(); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs & args){ |
|||
if(bDrag){ |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
ofVec2f distance = mousePosition - clickPosition; |
|||
|
|||
if(guiMode == GuiMode::PROJECTION_MAPPING){ |
|||
// add this distance to all vertices in surface
|
|||
projectionEditor.moveSelectedSurface(distance); |
|||
}else if(guiMode == GuiMode::TEXTURE_MAPPING){ |
|||
textureEditor.moveTexCoords(distance); |
|||
} |
|||
clickPosition = mousePosition; |
|||
} |
|||
} |
|||
|
|||
void SurfaceManagerGui::setSurfaceManager(SurfaceManager * newSurfaceManager){ |
|||
surfaceManager = newSurfaceManager; |
|||
projectionEditor.setSurfaceManager(surfaceManager); |
|||
sourcesEditor.setSurfaceManager(surfaceManager); |
|||
} |
|||
|
|||
// Set external media server so we can access it from wherever we need
|
|||
void SurfaceManagerGui::setMediaServer(MediaServer * newMediaServer){ |
|||
mediaServer = newMediaServer; |
|||
// Set the media server of the sources editor here
|
|||
sourcesEditor.setMediaServer(mediaServer); |
|||
} |
|||
|
|||
void SurfaceManagerGui::setCmdManager(CmdManager * cmdManager){ |
|||
_cmdManager = cmdManager; |
|||
sourcesEditor.setCmdManager(_cmdManager); |
|||
} |
|||
|
|||
void SurfaceManagerGui::setMode(int newGuiMode){ |
|||
if(newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && |
|||
newGuiMode != GuiMode::PROJECTION_MAPPING && |
|||
newGuiMode != GuiMode::SOURCE_SELECTION){ |
|||
throw std::runtime_error("Trying to set invalid mode."); |
|||
} |
|||
|
|||
if(newGuiMode == GuiMode::NONE){ |
|||
ofHideCursor(); |
|||
}else{ |
|||
ofShowCursor(); |
|||
} |
|||
|
|||
guiMode = newGuiMode; |
|||
|
|||
if(guiMode == GuiMode::SOURCE_SELECTION){ |
|||
sourcesEditor.enable(); |
|||
//string sourceName = surfaceManager->getSelectedSurfaceSourceName();
|
|||
//sourcesEditor.selectImageSourceRadioButton(sourceName);
|
|||
}else{ |
|||
sourcesEditor.disable(); |
|||
} |
|||
|
|||
if(guiMode == GuiMode::TEXTURE_MAPPING){ |
|||
textureEditor.enable(); |
|||
// refresh texture editor surface reference
|
|||
textureEditor.setSurface(surfaceManager->getSelectedSurface()); |
|||
}else{ |
|||
textureEditor.disable(); |
|||
} |
|||
|
|||
if(guiMode == GuiMode::PROJECTION_MAPPING){ |
|||
projectionEditor.enable(); |
|||
}else{ |
|||
projectionEditor.disable(); |
|||
} |
|||
} |
|||
|
|||
int SurfaceManagerGui::getMode(){ |
|||
return guiMode; |
|||
} |
|||
|
|||
void SurfaceManagerGui::drawSelectedSurfaceHighlight(){ |
|||
if(surfaceManager->getSelectedSurface() == NULL){ |
|||
return; |
|||
} |
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getHitArea(); |
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 255, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
} |
|||
|
|||
void SurfaceManagerGui::drawSelectedSurfaceTextureHighlight(){ |
|||
if(surfaceManager->getSelectedSurface() == NULL){ |
|||
return; |
|||
} |
|||
ofPolyline line = surfaceManager->getSelectedSurface()->getTextureHitArea(); |
|||
ofPushStyle(); |
|||
ofSetLineWidth(1); |
|||
ofSetColor(255, 255, 0, 255); |
|||
line.draw(); |
|||
ofPopStyle(); |
|||
} |
|||
|
|||
void SurfaceManagerGui::startDrag(){ |
|||
bDrag = true; |
|||
} |
|||
|
|||
void SurfaceManagerGui::stopDrag(){ |
|||
bDrag = false; |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,9 +1,13 @@ |
|||
#pragma once |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
struct SurfaceType { |
|||
enum { TRIANGLE_SURFACE, QUAD_SURFACE }; |
|||
}; |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
struct SurfaceType { |
|||
enum { |
|||
TRIANGLE_SURFACE, QUAD_SURFACE |
|||
}; |
|||
}; |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,270 +1,289 @@ |
|||
#include "ProjectionEditor.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
ProjectionEditor::ProjectionEditor() { |
|||
surfaceManager = NULL; |
|||
bShiftKeyDown = false; |
|||
fSnapDistance = 10.0f; |
|||
enable(); |
|||
} |
|||
|
|||
ProjectionEditor::~ProjectionEditor() { |
|||
clearJoints(); |
|||
surfaceManager = NULL; |
|||
disable(); |
|||
} |
|||
|
|||
void ProjectionEditor::registerAppEvents() { |
|||
ofAddListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterAppEvents() { |
|||
ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofRemoveListener(ofEvents().messageEvent, this, |
|||
&ProjectionEditor::gotMessage); |
|||
} |
|||
|
|||
void ProjectionEditor::registerMouseEvents() { |
|||
ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterMouseEvents() { |
|||
ofRemoveListener(ofEvents().mouseDragged, this, |
|||
&ProjectionEditor::mouseDragged); |
|||
} |
|||
|
|||
void ProjectionEditor::registerKeyEvents() { |
|||
ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterKeyEvents() { |
|||
ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofRemoveListener(ofEvents().keyReleased, this, |
|||
&ProjectionEditor::keyReleased); |
|||
} |
|||
|
|||
void ProjectionEditor::enable() { |
|||
registerAppEvents(); |
|||
registerMouseEvents(); |
|||
registerKeyEvents(); |
|||
} |
|||
|
|||
void ProjectionEditor::disable() { |
|||
unregisterAppEvents(); |
|||
unregisterMouseEvents(); |
|||
unregisterKeyEvents(); |
|||
} |
|||
|
|||
void ProjectionEditor::update(ofEventArgs& args) { |
|||
// update surface if one of the joints is being dragged
|
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isDragged() || joints[i]->isSelected()) { |
|||
if (surfaceManager->getSelectedSurface() != NULL) { |
|||
// update vertex to new location
|
|||
surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position); |
|||
} else { |
|||
// clear joints if there is no surface selected
|
|||
// as the remove selected surface in the surface manager
|
|||
// is not supposed to access joints here
|
|||
joints.clear(); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::draw() { |
|||
if (surfaceManager == NULL) return; |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
if (joints.size() <= 0) createJoints(); |
|||
drawJoints(); |
|||
} |
|||
|
|||
void ProjectionEditor::mouseDragged(ofMouseEventArgs& args) { |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
|
|||
// Collect all vertices of the projection surfaces
|
|||
vector<ofVec3f*> allVertices; |
|||
for (int i = 0; i < surfaceManager->size(); i++) { |
|||
BaseSurface* surface = surfaceManager->getSurface(i); |
|||
if (surface == surfaceManager->getSelectedSurface()) { |
|||
continue; // Don't add vertices of selected surface
|
|||
} |
|||
for (int j = 0; j < surface->getVertices().size(); j++) { |
|||
allVertices.push_back(&surface->getVertices()[j]); |
|||
} |
|||
} |
|||
|
|||
// Snap currently dragged joint to nearest vertex
|
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isDragged()) { |
|||
// Snap it!
|
|||
for (int j = 0; j < allVertices.size(); j++) { |
|||
float distance = mousePosition.distance(*allVertices[j]); |
|||
// cout << "distance: " << distance << endl;
|
|||
if (distance < fSnapDistance) { |
|||
joints[i]->position = *allVertices[j]; |
|||
ofVec2f clickDistance = joints[i]->position - ofVec2f(args.x, args.y); |
|||
joints[i]->setClickDistance(clickDistance); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::keyPressed(ofKeyEventArgs& args) { |
|||
int key = args.key; |
|||
float moveStep; |
|||
|
|||
if (bShiftKeyDown) |
|||
moveStep = 10.0f; |
|||
else |
|||
moveStep = 0.5f; |
|||
|
|||
switch (key) { |
|||
case OF_KEY_LEFT: |
|||
moveSelection(ofVec2f(-moveStep, 0.0f)); |
|||
break; |
|||
case OF_KEY_RIGHT: |
|||
moveSelection(ofVec2f(moveStep, 0.0f)); |
|||
break; |
|||
case OF_KEY_UP: |
|||
moveSelection(ofVec2f(0.0f, -moveStep)); |
|||
break; |
|||
case OF_KEY_DOWN: |
|||
moveSelection(ofVec2f(0.0f, moveStep)); |
|||
break; |
|||
case OF_KEY_SHIFT: |
|||
bShiftKeyDown = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::keyReleased(ofKeyEventArgs& args) { |
|||
int key = args.key; |
|||
switch (key) { |
|||
case OF_KEY_SHIFT: |
|||
bShiftKeyDown = false; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::gotMessage(ofMessage& msg) { |
|||
if (msg.message == "surfaceSelected") { |
|||
// refresh gui
|
|||
clearJoints(); |
|||
createJoints(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|||
surfaceManager = newSurfaceManager; |
|||
} |
|||
|
|||
void ProjectionEditor::clearJoints() { |
|||
while (joints.size()) { |
|||
delete joints.back(); |
|||
joints.pop_back(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::createJoints() { |
|||
if (surfaceManager == NULL) return; |
|||
clearJoints(); |
|||
|
|||
if (surfaceManager->getSelectedSurface() == NULL) { |
|||
ofLog(OF_LOG_WARNING, "Trying to create joints while no surface selected."); |
|||
return; |
|||
} |
|||
|
|||
vector<ofVec3f>& vertices = |
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
|
|||
for (int i = 0; i < vertices.size(); i++) { |
|||
joints.push_back(new CircleJoint()); |
|||
joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::updateJoints() { |
|||
if (surfaceManager->getSelectedSurface()) { |
|||
vector<ofVec3f>& vertices = |
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
for (int i = 0; i < vertices.size(); i++) { |
|||
joints[i]->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
void ProjectionEditor::unselectAllJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->unselect(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::moveSelectedSurface(ofVec2f by) { |
|||
if (surfaceManager == NULL) return; |
|||
if (surfaceManager->getSelectedSurface() == NULL) return; |
|||
surfaceManager->getSelectedSurface()->moveBy(by); |
|||
/*vector<ofVec3f>& vertices =
|
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
for (int i=0; i<vertices.size(); i++) { |
|||
vertices[i] += by; |
|||
}*/ |
|||
updateJoints(); |
|||
} |
|||
|
|||
void ProjectionEditor::stopDragJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->stopDrag(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::moveSelection(ofVec2f by) { |
|||
// check if joints selected
|
|||
bool bJointSelected = false; |
|||
BaseJoint* selectedJoint; |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->isSelected()) { |
|||
bJointSelected = true; |
|||
selectedJoint = joints[i]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if (bJointSelected) { |
|||
selectedJoint->position += by; |
|||
} else { |
|||
moveSelectedSurface(by); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::setSnapDistance(float newSnapDistance) { |
|||
fSnapDistance = newSnapDistance; |
|||
} |
|||
|
|||
CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos) { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
if (joints[i]->hitTest(pos)) { |
|||
return joints[i]; |
|||
} |
|||
} |
|||
return NULL; |
|||
} |
|||
|
|||
vector<CircleJoint *> * ProjectionEditor::getJoints(){ |
|||
return &joints; |
|||
} |
|||
|
|||
void ProjectionEditor::drawJoints() { |
|||
for (int i = 0; i < joints.size(); i++) { |
|||
joints[i]->draw(); |
|||
} |
|||
} |
|||
} |
|||
} |
|||
namespace piMapper { |
|||
|
|||
ProjectionEditor::ProjectionEditor(){ |
|||
surfaceManager = NULL; |
|||
bShiftKeyDown = false; |
|||
fSnapDistance = 10.0f; |
|||
enable(); |
|||
} |
|||
|
|||
ProjectionEditor::~ProjectionEditor(){ |
|||
clearJoints(); |
|||
surfaceManager = NULL; |
|||
disable(); |
|||
} |
|||
|
|||
void ProjectionEditor::registerAppEvents(){ |
|||
ofAddListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterAppEvents(){ |
|||
ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update); |
|||
ofRemoveListener(ofEvents().messageEvent, this, |
|||
&ProjectionEditor::gotMessage); |
|||
} |
|||
|
|||
void ProjectionEditor::registerMouseEvents(){ |
|||
ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterMouseEvents(){ |
|||
ofRemoveListener(ofEvents().mouseDragged, this, |
|||
&ProjectionEditor::mouseDragged); |
|||
} |
|||
|
|||
void ProjectionEditor::registerKeyEvents(){ |
|||
ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); |
|||
} |
|||
|
|||
void ProjectionEditor::unregisterKeyEvents(){ |
|||
ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|||
ofRemoveListener(ofEvents().keyReleased, this, |
|||
&ProjectionEditor::keyReleased); |
|||
} |
|||
|
|||
void ProjectionEditor::enable(){ |
|||
registerAppEvents(); |
|||
registerMouseEvents(); |
|||
registerKeyEvents(); |
|||
} |
|||
|
|||
void ProjectionEditor::disable(){ |
|||
unregisterAppEvents(); |
|||
unregisterMouseEvents(); |
|||
unregisterKeyEvents(); |
|||
} |
|||
|
|||
void ProjectionEditor::update(ofEventArgs & args){ |
|||
// update surface if one of the joints is being dragged
|
|||
for(int i = 0; i < joints.size(); i++){ |
|||
if(joints[i]->isDragged() || joints[i]->isSelected()){ |
|||
if(surfaceManager->getSelectedSurface() != NULL){ |
|||
// update vertex to new location
|
|||
surfaceManager->getSelectedSurface()->setVertex(i, joints[i]->position); |
|||
}else{ |
|||
// clear joints if there is no surface selected
|
|||
// as the remove selected surface in the surface manager
|
|||
// is not supposed to access joints here
|
|||
joints.clear(); |
|||
} |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::draw(){ |
|||
if(surfaceManager == NULL){ |
|||
return; |
|||
} |
|||
if(surfaceManager->getSelectedSurface() == NULL){ |
|||
return; |
|||
} |
|||
if(joints.size() <= 0){ |
|||
createJoints(); |
|||
} |
|||
drawJoints(); |
|||
} |
|||
|
|||
void ProjectionEditor::mouseDragged(ofMouseEventArgs & args){ |
|||
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|||
|
|||
// Collect all vertices of the projection surfaces
|
|||
vector <ofVec3f *> allVertices; |
|||
for(int i = 0; i < surfaceManager->size(); i++){ |
|||
BaseSurface * surface = surfaceManager->getSurface(i); |
|||
if(surface == surfaceManager->getSelectedSurface()){ |
|||
continue; // Don't add vertices of selected surface
|
|||
} |
|||
for(int j = 0; j < surface->getVertices().size(); j++){ |
|||
allVertices.push_back(&surface->getVertices()[j]); |
|||
} |
|||
} |
|||
|
|||
// Snap currently dragged joint to nearest vertex
|
|||
for(int i = 0; i < joints.size(); i++){ |
|||
if(joints[i]->isDragged()){ |
|||
// Snap it!
|
|||
for(int j = 0; j < allVertices.size(); j++){ |
|||
float distance = mousePosition.distance(*allVertices[j]); |
|||
// cout << "distance: " << distance << endl;
|
|||
if(distance < fSnapDistance){ |
|||
joints[i]->position = *allVertices[j]; |
|||
ofVec2f clickDistance = joints[i]->position - ofVec2f(args.x, args.y); |
|||
joints[i]->setClickDistance(clickDistance); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::keyPressed(ofKeyEventArgs & args){ |
|||
int key = args.key; |
|||
float moveStep; |
|||
|
|||
if(bShiftKeyDown){ |
|||
moveStep = 10.0f; |
|||
}else{ |
|||
moveStep = 0.5f; |
|||
} |
|||
|
|||
switch(key){ |
|||
case OF_KEY_LEFT: |
|||
moveSelection(ofVec2f(-moveStep, 0.0f)); |
|||
break; |
|||
|
|||
case OF_KEY_RIGHT: |
|||
moveSelection(ofVec2f(moveStep, 0.0f)); |
|||
break; |
|||
|
|||
case OF_KEY_UP: |
|||
moveSelection(ofVec2f(0.0f, -moveStep)); |
|||
break; |
|||
|
|||
case OF_KEY_DOWN: |
|||
moveSelection(ofVec2f(0.0f, moveStep)); |
|||
break; |
|||
|
|||
case OF_KEY_SHIFT: |
|||
bShiftKeyDown = true; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::keyReleased(ofKeyEventArgs & args){ |
|||
int key = args.key; |
|||
switch(key){ |
|||
case OF_KEY_SHIFT: |
|||
bShiftKeyDown = false; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::gotMessage(ofMessage & msg){ |
|||
if(msg.message == "surfaceSelected"){ |
|||
// refresh gui
|
|||
clearJoints(); |
|||
createJoints(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::setSurfaceManager(SurfaceManager * newSurfaceManager){ |
|||
surfaceManager = newSurfaceManager; |
|||
} |
|||
|
|||
void ProjectionEditor::clearJoints(){ |
|||
while(joints.size()){ |
|||
delete joints.back(); |
|||
joints.pop_back(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::createJoints(){ |
|||
if(surfaceManager == NULL){ |
|||
return; |
|||
} |
|||
clearJoints(); |
|||
|
|||
if(surfaceManager->getSelectedSurface() == NULL){ |
|||
ofLog(OF_LOG_WARNING, "Trying to create joints while no surface selected."); |
|||
return; |
|||
} |
|||
|
|||
vector <ofVec3f> & vertices = |
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
|
|||
for(int i = 0; i < vertices.size(); i++){ |
|||
joints.push_back(new CircleJoint()); |
|||
joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::updateJoints(){ |
|||
if(surfaceManager->getSelectedSurface()){ |
|||
vector <ofVec3f> & vertices = |
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
for(int i = 0; i < vertices.size(); i++){ |
|||
joints[i]->position = ofVec2f(vertices[i].x, vertices[i].y); |
|||
} |
|||
} |
|||
|
|||
} |
|||
|
|||
void ProjectionEditor::unselectAllJoints(){ |
|||
for(int i = 0; i < joints.size(); i++){ |
|||
joints[i]->unselect(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::moveSelectedSurface(ofVec2f by){ |
|||
if(surfaceManager == NULL){ |
|||
return; |
|||
} |
|||
if(surfaceManager->getSelectedSurface() == NULL){ |
|||
return; |
|||
} |
|||
surfaceManager->getSelectedSurface()->moveBy(by); |
|||
/*vector<ofVec3f>& vertices =
|
|||
surfaceManager->getSelectedSurface()->getVertices(); |
|||
for (int i=0; i<vertices.size(); i++) { |
|||
vertices[i] += by; |
|||
}*/ |
|||
updateJoints(); |
|||
} |
|||
|
|||
void ProjectionEditor::stopDragJoints(){ |
|||
for(int i = 0; i < joints.size(); i++){ |
|||
joints[i]->stopDrag(); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::moveSelection(ofVec2f by){ |
|||
// check if joints selected
|
|||
bool bJointSelected = false; |
|||
BaseJoint * selectedJoint; |
|||
for(int i = 0; i < joints.size(); i++){ |
|||
if(joints[i]->isSelected()){ |
|||
bJointSelected = true; |
|||
selectedJoint = joints[i]; |
|||
break; |
|||
} |
|||
} |
|||
|
|||
if(bJointSelected){ |
|||
selectedJoint->position += by; |
|||
}else{ |
|||
moveSelectedSurface(by); |
|||
} |
|||
} |
|||
|
|||
void ProjectionEditor::setSnapDistance(float newSnapDistance){ |
|||
fSnapDistance = newSnapDistance; |
|||
} |
|||
|
|||
CircleJoint * ProjectionEditor::hitTestJoints(ofVec2f pos){ |
|||
for(int i = 0; i < joints.size(); i++){ |
|||
if(joints[i]->hitTest(pos)){ |
|||
return joints[i]; |
|||
} |
|||
} |
|||
return NULL; |
|||
} |
|||
|
|||
vector <CircleJoint *> * ProjectionEditor::getJoints(){ |
|||
return &joints; |
|||
} |
|||
|
|||
void ProjectionEditor::drawJoints(){ |
|||
for(int i = 0; i < joints.size(); i++){ |
|||
joints[i]->draw(); |
|||
} |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
@ -1,199 +1,201 @@ |
|||
#include "RadioList.h" |
|||
|
|||
namespace ofx{ |
|||
namespace piMapper{ |
|||
RadioList::RadioList(){ |
|||
storedTitle = ""; |
|||
storedSelectedItem = 0; |
|||
} |
|||
|
|||
RadioList::RadioList(vector<string> & labels, vector<string> & values){ |
|||
RadioList(); |
|||
setup(labels, values); |
|||
} |
|||
|
|||
RadioList::RadioList(string title, vector<string> & labels, vector<string> & values){ |
|||
RadioList(); |
|||
setup(title, labels, values); |
|||
} |
|||
|
|||
RadioList::~RadioList(){ |
|||
clear(); |
|||
} |
|||
|
|||
void RadioList::setup(vector<string> & labels, vector<string> & values){ |
|||
|
|||
// Copy incomming labels for later use
|
|||
storedLabels = labels; |
|||
storedValues = values; |
|||
|
|||
// Create toggles with labels from the labels arg
|
|||
int i; |
|||
for(i = 0; i < labels.size(); i++){ |
|||
ofxToggle * toggle = new ofxToggle(); |
|||
toggle->setup(false); |
|||
toggle->setName(labels[i]); |
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
guiGroup.add(toggle); |
|||
#if OF_VERSION_MAJOR == 0 && (OF_VERSION_MINOR >= 8 && OF_VERSION_PATCH >= 2) || (OF_VERSION_MINOR >= 9 && OF_VERSION_PATCH >= 0) |
|||
toggle->registerMouseEvents(); |
|||
#endif |
|||
} |
|||
} |
|||
|
|||
void RadioList::setup(string title, vector<string> & labels, vector<string> & values){ |
|||
|
|||
// Store title for later use
|
|||
storedTitle = title; |
|||
guiGroup.setName(title); |
|||
setup(labels, values); |
|||
} |
|||
|
|||
void RadioList::draw(){ |
|||
guiGroup.draw(); |
|||
} |
|||
|
|||
void RadioList::setTitle(string title){ |
|||
storedTitle = title; |
|||
guiGroup.setName(title); |
|||
} |
|||
|
|||
void RadioList::setPosition(ofPoint p){ |
|||
guiGroup.setPosition(p); |
|||
} |
|||
|
|||
void RadioList::setPosition(float x, float y){ |
|||
guiGroup.setPosition(x, y); |
|||
} |
|||
|
|||
void RadioList::selectItem(int index){ |
|||
if(index >= guiGroup.getNumControls()){ |
|||
return; |
|||
} |
|||
|
|||
unselectAll(); |
|||
|
|||
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(index)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = true; // Select the specific radio button
|
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
//string name = toggle->getName();
|
|||
// Throw event with value that is image path instead of name
|
|||
string value = storedValues[index]; |
|||
ofNotifyEvent(onRadioSelected, value, this); |
|||
storedSelectedItem = index; |
|||
} |
|||
|
|||
bool RadioList::selectItemByValue(std::string itemValue){ |
|||
if(itemValue == ""){ |
|||
ofLogNotice("RadioList") << "Item value empty"; |
|||
return false; |
|||
} |
|||
unselectAll(); |
|||
int itemIndex = -1; |
|||
for(int i = 0; i < storedValues.size(); i++){ |
|||
if(itemValue == storedValues[i]){ |
|||
itemIndex = i; |
|||
break; |
|||
} |
|||
} |
|||
if(itemIndex >= 0){ |
|||
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(itemIndex)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = true; // Select the specific radio button
|
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
return true; |
|||
} |
|||
ofLogNotice("RadioList") << "Item with value " << itemValue << " not found"; |
|||
return false; |
|||
} |
|||
|
|||
void RadioList::enable(){ |
|||
if(guiGroup.getNumControls() > 0){ |
|||
clear(); |
|||
} |
|||
|
|||
// Rebuild everyting
|
|||
setup(storedTitle, storedLabels, storedValues); |
|||
|
|||
// Select the stored selected item without throwing an event
|
|||
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(storedSelectedItem)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = true; |
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
|
|||
cout << "num items after enable: " << guiGroup.getNumControls() << endl; |
|||
} |
|||
|
|||
void RadioList::disable(){ |
|||
// Just remove everything
|
|||
clear(); |
|||
} |
|||
|
|||
void RadioList::clear(){ |
|||
int i; |
|||
for(i = 0; i < guiGroup.getNumControls(); i++){ |
|||
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
delete toggle; |
|||
} |
|||
guiGroup.clear(); |
|||
} |
|||
|
|||
void RadioList::unselectAll(){ |
|||
int i; |
|||
for(i = 0; i < guiGroup.getNumControls(); i++){ |
|||
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); |
|||
ofParameter<bool> * paramPtr = static_cast<ofParameter<bool> *>(&toggle->getParameter()); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = false; |
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
} |
|||
} |
|||
|
|||
ofPoint RadioList::getPosition(){ |
|||
return guiGroup.getPosition(); |
|||
} |
|||
|
|||
float RadioList::getWidth(){ |
|||
return guiGroup.getWidth(); |
|||
} |
|||
|
|||
float RadioList::getHeight(){ |
|||
return guiGroup.getHeight(); |
|||
} |
|||
|
|||
string RadioList::getTitle(){ |
|||
return guiGroup.getName(); |
|||
} |
|||
|
|||
string RadioList::getItemName(int index){ |
|||
if(index >= guiGroup.getNumControls()){ |
|||
return ""; |
|||
} |
|||
|
|||
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(index)); |
|||
return toggle->getName(); |
|||
} |
|||
|
|||
int RadioList::size(){ |
|||
return storedValues.size(); |
|||
} |
|||
|
|||
void RadioList::onToggleClicked(bool & toggleValue){ |
|||
unselectAll(); |
|||
|
|||
// Search for the actual toggle triggering the event
|
|||
int i; |
|||
for(i = 0; i < guiGroup.getNumControls(); i++){ |
|||
ofxToggle * toggle = static_cast<ofxToggle *>(guiGroup.getControl(i)); |
|||
ofParameter<bool> * paramPtr = static_cast<ofParameter<bool> *>(&toggle->getParameter()); |
|||
|
|||
if(&(paramPtr->get()) == &toggleValue){ |
|||
selectItem(i); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
} // namespace piMapper
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
RadioList::RadioList(){ |
|||
storedTitle = ""; |
|||
storedSelectedItem = 0; |
|||
} |
|||
|
|||
RadioList::RadioList(vector <string> & labels, vector <string> & values){ |
|||
RadioList(); |
|||
setup(labels, values); |
|||
} |
|||
|
|||
RadioList::RadioList(string title, vector <string> & labels, vector <string> & values){ |
|||
RadioList(); |
|||
setup(title, labels, values); |
|||
} |
|||
|
|||
RadioList::~RadioList(){ |
|||
clear(); |
|||
} |
|||
|
|||
void RadioList::setup(vector <string> & labels, vector <string> & values){ |
|||
|
|||
// Copy incomming labels for later use
|
|||
storedLabels = labels; |
|||
storedValues = values; |
|||
|
|||
// Create toggles with labels from the labels arg
|
|||
int i; |
|||
for(i = 0; i < labels.size(); i++){ |
|||
ofxToggle * toggle = new ofxToggle(); |
|||
toggle->setup(false); |
|||
toggle->setName(labels[i]); |
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
guiGroup.add(toggle); |
|||
#if OF_VERSION_MAJOR == 0 && (OF_VERSION_MINOR >= 8 && OF_VERSION_PATCH >= 2) || (OF_VERSION_MINOR >= 9 && OF_VERSION_PATCH >= 0) |
|||
toggle->registerMouseEvents(); |
|||
#endif |
|||
} |
|||
} |
|||
|
|||
void RadioList::setup(string title, vector <string> & labels, vector <string> & values){ |
|||
|
|||
// Store title for later use
|
|||
storedTitle = title; |
|||
guiGroup.setName(title); |
|||
setup(labels, values); |
|||
} |
|||
|
|||
void RadioList::draw(){ |
|||
guiGroup.draw(); |
|||
} |
|||
|
|||
void RadioList::setTitle(string title){ |
|||
storedTitle = title; |
|||
guiGroup.setName(title); |
|||
} |
|||
|
|||
void RadioList::setPosition(ofPoint p){ |
|||
guiGroup.setPosition(p); |
|||
} |
|||
|
|||
void RadioList::setPosition(float x, float y){ |
|||
guiGroup.setPosition(x, y); |
|||
} |
|||
|
|||
void RadioList::selectItem(int index){ |
|||
if(index >= guiGroup.getNumControls()){ |
|||
return; |
|||
} |
|||
|
|||
unselectAll(); |
|||
|
|||
ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(index)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = true; // Select the specific radio button
|
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
//string name = toggle->getName();
|
|||
// Throw event with value that is image path instead of name
|
|||
string value = storedValues[index]; |
|||
ofNotifyEvent(onRadioSelected, value, this); |
|||
storedSelectedItem = index; |
|||
} |
|||
|
|||
bool RadioList::selectItemByValue(std::string itemValue){ |
|||
if(itemValue == ""){ |
|||
ofLogNotice("RadioList") << "Item value empty"; |
|||
return false; |
|||
} |
|||
unselectAll(); |
|||
int itemIndex = -1; |
|||
for(int i = 0; i < storedValues.size(); i++){ |
|||
if(itemValue == storedValues[i]){ |
|||
itemIndex = i; |
|||
break; |
|||
} |
|||
} |
|||
if(itemIndex >= 0){ |
|||
ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(itemIndex)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = true; // Select the specific radio button
|
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
return true; |
|||
} |
|||
ofLogNotice("RadioList") << "Item with value " << itemValue << " not found"; |
|||
return false; |
|||
} |
|||
|
|||
void RadioList::enable(){ |
|||
if(guiGroup.getNumControls() > 0){ |
|||
clear(); |
|||
} |
|||
|
|||
// Rebuild everyting
|
|||
setup(storedTitle, storedLabels, storedValues); |
|||
|
|||
// Select the stored selected item without throwing an event
|
|||
ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(storedSelectedItem)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = true; |
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
|
|||
cout << "num items after enable: " << guiGroup.getNumControls() << endl; |
|||
} |
|||
|
|||
void RadioList::disable(){ |
|||
// Just remove everything
|
|||
clear(); |
|||
} |
|||
|
|||
void RadioList::clear(){ |
|||
int i; |
|||
for(i = 0; i < guiGroup.getNumControls(); i++){ |
|||
ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(i)); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
delete toggle; |
|||
} |
|||
guiGroup.clear(); |
|||
} |
|||
|
|||
void RadioList::unselectAll(){ |
|||
int i; |
|||
for(i = 0; i < guiGroup.getNumControls(); i++){ |
|||
ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(i)); |
|||
ofParameter <bool> * paramPtr = static_cast <ofParameter <bool> *>(&toggle->getParameter()); |
|||
toggle->removeListener(this, &RadioList::onToggleClicked); |
|||
*toggle = false; |
|||
toggle->addListener(this, &RadioList::onToggleClicked); |
|||
} |
|||
} |
|||
|
|||
ofPoint RadioList::getPosition(){ |
|||
return guiGroup.getPosition(); |
|||
} |
|||
|
|||
float RadioList::getWidth(){ |
|||
return guiGroup.getWidth(); |
|||
} |
|||
|
|||
float RadioList::getHeight(){ |
|||
return guiGroup.getHeight(); |
|||
} |
|||
|
|||
string RadioList::getTitle(){ |
|||
return guiGroup.getName(); |
|||
} |
|||
|
|||
string RadioList::getItemName(int index){ |
|||
if(index >= guiGroup.getNumControls()){ |
|||
return ""; |
|||
} |
|||
|
|||
ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(index)); |
|||
return toggle->getName(); |
|||
} |
|||
|
|||
int RadioList::size(){ |
|||
return storedValues.size(); |
|||
} |
|||
|
|||
void RadioList::onToggleClicked(bool & toggleValue){ |
|||
unselectAll(); |
|||
|
|||
// Search for the actual toggle triggering the event
|
|||
int i; |
|||
for(i = 0; i < guiGroup.getNumControls(); i++){ |
|||
ofxToggle * toggle = static_cast <ofxToggle *>(guiGroup.getControl(i)); |
|||
ofParameter <bool> * paramPtr = static_cast <ofParameter <bool> *>(&toggle->getParameter()); |
|||
|
|||
if(&(paramPtr->get()) == &toggleValue){ |
|||
selectItem(i); |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
} // namespace piMapper
|
|||
} // namespace ofx
|
|||
|
@ -1,117 +1,117 @@ |
|||
#include "ofxPiMapper.h" |
|||
|
|||
ofxPiMapper::ofxPiMapper() { |
|||
bShowInfo = false; |
|||
isSetUp = false; |
|||
ofxPiMapper::ofxPiMapper(){ |
|||
bShowInfo = false; |
|||
isSetUp = false; |
|||
} |
|||
|
|||
void ofxPiMapper::setup() { |
|||
ofLogNotice("ofxPiMapper") << "Setting up..."; |
|||
|
|||
surfaceManager.setMediaServer(&mediaServer); |
|||
gui.setMediaServer(&mediaServer); |
|||
gui.setCmdManager(&cmdManager); |
|||
|
|||
if (ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){ |
|||
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE; |
|||
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE); |
|||
} else { |
|||
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE; |
|||
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE); |
|||
} |
|||
|
|||
gui.setSurfaceManager(&surfaceManager); |
|||
isSetUp = true; |
|||
ofLogNotice("ofxPiMapper") << "Done setting up"; |
|||
_application = new ofx::piMapper::Application(this); |
|||
void ofxPiMapper::setup(){ |
|||
ofLogNotice("ofxPiMapper") << "Setting up..."; |
|||
|
|||
surfaceManager.setMediaServer(&mediaServer); |
|||
gui.setMediaServer(&mediaServer); |
|||
gui.setCmdManager(&cmdManager); |
|||
|
|||
if(ofFile::doesFileExist(PIMAPPER_USER_SURFACES_XML_FILE)){ |
|||
ofLogNotice("ofxPiMapper") << "Loading user surfaces from " << PIMAPPER_USER_SURFACES_XML_FILE; |
|||
surfaceManager.loadXmlSettings(PIMAPPER_USER_SURFACES_XML_FILE); |
|||
}else{ |
|||
ofLogNotice("ofxPiMapper") << "Loading default surfaces from " << PIMAPPER_DEF_SURFACES_XML_FILE; |
|||
surfaceManager.loadXmlSettings(PIMAPPER_DEF_SURFACES_XML_FILE); |
|||
} |
|||
|
|||
gui.setSurfaceManager(&surfaceManager); |
|||
isSetUp = true; |
|||
ofLogNotice("ofxPiMapper") << "Done setting up"; |
|||
_application = new ofx::piMapper::Application(this); |
|||
} |
|||
|
|||
void ofxPiMapper::draw() { |
|||
if (!isSetUp) { |
|||
return; |
|||
} |
|||
|
|||
gui.draw(); |
|||
|
|||
if (bShowInfo){ |
|||
stringstream ss; |
|||
ss << "There are 4 modes:\n\n"; |
|||
ss << " 1. Presentation mode\n"; |
|||
ss << " 2. Texture mapping mode\n"; |
|||
ss << " 3. Projection mapping mode\n"; |
|||
ss << " 4. Source selection mode\n\n"; |
|||
ss << "You can switch between the modes by using <1>, <2>, <3> and <4> " |
|||
"keys on the keyboard.\n\n"; |
|||
ss << "Press <t> to add new triangle surface\n"; |
|||
ss << "Press <q> to add new quad surface\n"; |
|||
ss << "Press <s> to save the composition\n"; |
|||
ss << "Press <f> to toggle fullscreen\n"; |
|||
ss << "Press <i> to hide this message"; |
|||
ofDrawBitmapStringHighlight(ss.str(), 10, 20, |
|||
ofColor(0, 0, 0, 100), |
|||
ofColor(255, 255, 255, 200)); |
|||
} |
|||
|
|||
_application->draw(); |
|||
void ofxPiMapper::draw(){ |
|||
if(!isSetUp){ |
|||
return; |
|||
} |
|||
|
|||
gui.draw(); |
|||
|
|||
if(bShowInfo){ |
|||
stringstream ss; |
|||
ss << "There are 4 modes:\n\n"; |
|||
ss << " 1. Presentation mode\n"; |
|||
ss << " 2. Texture mapping mode\n"; |
|||
ss << " 3. Projection mapping mode\n"; |
|||
ss << " 4. Source selection mode\n\n"; |
|||
ss << "You can switch between the modes by using <1>, <2>, <3> and <4> " |
|||
"keys on the keyboard.\n\n"; |
|||
ss << "Press <t> to add new triangle surface\n"; |
|||
ss << "Press <q> to add new quad surface\n"; |
|||
ss << "Press <s> to save the composition\n"; |
|||
ss << "Press <f> to toggle fullscreen\n"; |
|||
ss << "Press <i> to hide this message"; |
|||
ofDrawBitmapStringHighlight(ss.str(), 10, 20, |
|||
ofColor(0, 0, 0, 100), |
|||
ofColor(255, 255, 255, 200)); |
|||
} |
|||
|
|||
_application->draw(); |
|||
} // draw
|
|||
|
|||
void ofxPiMapper::registerFboSource(ofx::piMapper::FboSource & fboSource) { |
|||
mediaServer.addFboSource(fboSource); |
|||
void ofxPiMapper::registerFboSource(ofx::piMapper::FboSource & fboSource){ |
|||
mediaServer.addFboSource(fboSource); |
|||
} |
|||
|
|||
void ofxPiMapper::addTriangleSurface() { |
|||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|||
|
|||
vector<ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(0.5f, 0.0f)); |
|||
texCoords.push_back(ofVec2f(1.0f, 1.0f)); |
|||
texCoords.push_back(ofVec2f(0.0f, 1.0f)); |
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// Select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|||
void ofxPiMapper::addTriangleSurface(){ |
|||
int surfaceType = ofx::piMapper::SurfaceType::TRIANGLE_SURFACE; |
|||
|
|||
vector <ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() / 2.0f, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector <ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(0.5f, 0.0f)); |
|||
texCoords.push_back(ofVec2f(1.0f, 1.0f)); |
|||
texCoords.push_back(ofVec2f(0.0f, 1.0f)); |
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// Select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|||
} // addTriangleSurface
|
|||
|
|||
void ofxPiMapper::addQuadSurface() { |
|||
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
|||
|
|||
vector<ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f(margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector<ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
|||
|
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|||
void ofxPiMapper::addQuadSurface(){ |
|||
int surfaceType = ofx::piMapper::SurfaceType::QUAD_SURFACE; |
|||
|
|||
vector <ofVec2f> vertices; |
|||
float margin = 50.0f; |
|||
vertices.push_back(ofVec2f(margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, margin)); |
|||
vertices.push_back(ofVec2f((float)ofGetWidth() - margin, (float)ofGetHeight() - margin)); |
|||
vertices.push_back(ofVec2f(margin, (float)ofGetHeight() - margin)); |
|||
|
|||
vector <ofVec2f> texCoords; |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 0.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(1.0f, 1.0f))); |
|||
texCoords.push_back(ofVec2f(ofVec2f(0.0f, 1.0f))); |
|||
|
|||
surfaceManager.addSurface(surfaceType, vertices, texCoords); |
|||
|
|||
// select this surface right away
|
|||
surfaceManager.selectSurface(surfaceManager.size() - 1); |
|||
} // addQuadSurface
|
|||
|
|||
ofx::piMapper::CmdManager & ofxPiMapper::getCmdManager() { |
|||
return cmdManager; |
|||
ofx::piMapper::CmdManager & ofxPiMapper::getCmdManager(){ |
|||
return cmdManager; |
|||
} |
|||
|
|||
ofx::piMapper::SurfaceManagerGui & ofxPiMapper::getGui() { |
|||
return gui; |
|||
ofx::piMapper::SurfaceManagerGui & ofxPiMapper::getGui(){ |
|||
return gui; |
|||
} |
|||
|
|||
ofx::piMapper::MediaServer & ofxPiMapper::getMediaServer() { |
|||
return mediaServer; |
|||
ofx::piMapper::MediaServer & ofxPiMapper::getMediaServer(){ |
|||
return mediaServer; |
|||
} |
|||
|
|||
ofx::piMapper::SurfaceManager & ofxPiMapper::getSurfaceManager() { |
|||
return surfaceManager; |
|||
ofx::piMapper::SurfaceManager & ofxPiMapper::getSurfaceManager(){ |
|||
return surfaceManager; |
|||
} |
Loading…
Reference in new issue