|
|
@ -1,41 +1,41 @@ |
|
|
|
#include "SurfaceManagerGui.h" |
|
|
|
|
|
|
|
namespace ofx { |
|
|
|
namespace piMapper { |
|
|
|
SurfaceManagerGui::SurfaceManagerGui() { |
|
|
|
namespace piMapper { |
|
|
|
SurfaceManagerGui::SurfaceManagerGui() { |
|
|
|
surfaceManager = NULL; |
|
|
|
guiMode = GuiMode::NONE; |
|
|
|
bDrag = false; |
|
|
|
registerMouseEvents(); |
|
|
|
ofHideCursor(); |
|
|
|
_commandManager = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
SurfaceManagerGui::~SurfaceManagerGui() { |
|
|
|
SurfaceManagerGui::~SurfaceManagerGui() { |
|
|
|
unregisterMouseEvents(); |
|
|
|
surfaceManager = NULL; |
|
|
|
_commandManager = 0; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::registerMouseEvents() { |
|
|
|
void SurfaceManagerGui::registerMouseEvents() { |
|
|
|
ofAddListener(ofEvents().mousePressed, this, |
|
|
|
&SurfaceManagerGui::mousePressed); |
|
|
|
ofAddListener(ofEvents().mouseReleased, this, |
|
|
|
&SurfaceManagerGui::mouseReleased); |
|
|
|
ofAddListener(ofEvents().mouseDragged, this, |
|
|
|
&SurfaceManagerGui::mouseDragged); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::unregisterMouseEvents() { |
|
|
|
void SurfaceManagerGui::unregisterMouseEvents() { |
|
|
|
ofRemoveListener(ofEvents().mousePressed, this, |
|
|
|
&SurfaceManagerGui::mousePressed); |
|
|
|
ofRemoveListener(ofEvents().mouseReleased, this, |
|
|
|
&SurfaceManagerGui::mouseReleased); |
|
|
|
ofRemoveListener(ofEvents().mouseDragged, this, |
|
|
|
&SurfaceManagerGui::mouseDragged); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::draw() { |
|
|
|
void SurfaceManagerGui::draw() { |
|
|
|
if (surfaceManager == NULL) return; |
|
|
|
|
|
|
|
if (guiMode == GuiMode::NONE) { |
|
|
@ -80,9 +80,9 @@ void SurfaceManagerGui::draw() { |
|
|
|
|
|
|
|
sourcesEditor.draw(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
|
|
|
void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
|
|
|
if (guiMode == GuiMode::NONE) { |
|
|
|
return; |
|
|
|
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
|
|
@ -124,6 +124,9 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
|
|
|
if (!bSurfaceSelected) { |
|
|
|
for (int i = surfaceManager->size() - 1; i >= 0; i--) { |
|
|
|
if (surfaceManager->getSurface(i)->hitTest(ofVec2f(args.x, args.y))) { |
|
|
|
|
|
|
|
// TODO: Do not repeat this command if attempting to select an
|
|
|
|
// already selected surface.
|
|
|
|
_commandManager->exec(new SelectSurfaceCommand( |
|
|
|
surfaceManager, |
|
|
|
surfaceManager->getSurface(i), |
|
|
@ -140,6 +143,7 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
|
|
|
clickPosition = ofVec2f(args.x, args.y); |
|
|
|
startDrag(); |
|
|
|
|
|
|
|
// TODO: Undo this command if surface not moved on mouse release
|
|
|
|
_commandManager->exec( |
|
|
|
new MoveSurfaceCommand( |
|
|
|
surfaceManager->getSelectedSurface(), |
|
|
@ -153,15 +157,21 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
|
|
|
} |
|
|
|
} else if (guiMode == GuiMode::SOURCE_SELECTION) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) { |
|
|
|
void SurfaceManagerGui::mouseReleased(ofMouseEventArgs& args) { |
|
|
|
stopDrag(); |
|
|
|
projectionEditor.stopDragJoints(); |
|
|
|
textureEditor.stopDragJoints(); |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { |
|
|
|
// Check if surface has moved
|
|
|
|
if (!surfaceManager->getSelectedSurface()->getMoved()) { |
|
|
|
_commandManager->undo(); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { |
|
|
|
if (bDrag) { |
|
|
|
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|
|
|
ofVec2f distance = mousePosition - clickPosition; |
|
|
@ -174,13 +184,13 @@ void SurfaceManagerGui::mouseDragged(ofMouseEventArgs& args) { |
|
|
|
} |
|
|
|
clickPosition = mousePosition; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|
|
|
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) { |
|
|
@ -193,7 +203,7 @@ void SurfaceManagerGui::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|
|
|
_commandManager = commandManager; |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::setMode(int newGuiMode) { |
|
|
|
void SurfaceManagerGui::setMode(int newGuiMode) { |
|
|
|
if (newGuiMode != GuiMode::NONE && newGuiMode != GuiMode::TEXTURE_MAPPING && |
|
|
|
newGuiMode != GuiMode::PROJECTION_MAPPING && |
|
|
|
newGuiMode != GuiMode::SOURCE_SELECTION) { |
|
|
@ -229,34 +239,30 @@ void SurfaceManagerGui::setMode(int newGuiMode) { |
|
|
|
} else { |
|
|
|
projectionEditor.disable(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void SurfaceManagerGui::drawSelectedSurfaceHighlight() { |
|
|
|
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() { |
|
|
|
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::startDrag() { bDrag = true; } |
|
|
|
|
|
|
|
void SurfaceManagerGui::stopDrag() { bDrag = false; } |
|
|
|
} |
|
|
|
void SurfaceManagerGui::stopDrag() { bDrag = false; } |
|
|
|
} |
|
|
|
} |