6 changed files with 387 additions and 381 deletions
@ -1,90 +1,94 @@ |
|||
#include "BaseSurface.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
|
|||
BaseSurface::BaseSurface() { |
|||
ofEnableNormalizedTexCoords(); |
|||
createDefaultTexture(); |
|||
} |
|||
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; |
|||
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; |
|||
} |
|||
} |
|||
sx = !sx; |
|||
|
|||
//ofTexture* BaseSurface::getDefaultTexture() { return &defaultTexture; }
|
|||
BaseSource* BaseSurface::getDefaultSource() { |
|||
return defaultSource; |
|||
} |
|||
|
|||
void BaseSurface::setMoved(bool moved){ _moved = moved; } |
|||
bool BaseSurface::getMoved(){ return _moved; } |
|||
} |
|||
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; |
|||
} |
|||
} |
|||
} |
@ -1,262 +1,268 @@ |
|||
#include "SurfaceManagerGui.h" |
|||
|
|||
namespace ofx { |
|||
namespace piMapper { |
|||
SurfaceManagerGui::SurfaceManagerGui() { |
|||
surfaceManager = NULL; |
|||
guiMode = GuiMode::NONE; |
|||
bDrag = false; |
|||
registerMouseEvents(); |
|||
ofHideCursor(); |
|||
_commandManager = 0; |
|||
} |
|||
|
|||
SurfaceManagerGui::~SurfaceManagerGui() { |
|||
unregisterMouseEvents(); |
|||
surfaceManager = NULL; |
|||
_commandManager = 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) { |
|||
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; |
|||
} else { |
|||
textureEditor.unselectAllJoints(); |
|||
namespace piMapper { |
|||
SurfaceManagerGui::SurfaceManagerGui() { |
|||
surfaceManager = NULL; |
|||
guiMode = GuiMode::NONE; |
|||
bDrag = false; |
|||
registerMouseEvents(); |
|||
ofHideCursor(); |
|||
_commandManager = 0; |
|||
} |
|||
|
|||
SurfaceManagerGui::~SurfaceManagerGui() { |
|||
unregisterMouseEvents(); |
|||
surfaceManager = NULL; |
|||
_commandManager = 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) { |
|||
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; |
|||
} 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)) { |
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
} |
|||
} |
|||
|
|||
} 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(); |
|||
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))) { |
|||
|
|||
// TODO: Do not repeat this command if attempting to select an
|
|||
// already selected surface.
|
|||
_commandManager->exec(new SelectSurfaceCommand( |
|||
surfaceManager, |
|||
surfaceManager->getSurface(i), |
|||
&projectionEditor)); |
|||
bSurfaceSelected = true; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (bSurfaceSelected && hitJoint == NULL) { |
|||
// if not hitting the joints, start drag only if we have a selected
|
|||
// surface
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
|
|||
// TODO: Undo this command if surface not moved on mouse release
|
|||
_commandManager->exec( |
|||
new MoveSurfaceCommand( |
|||
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()->getMoved()) { |
|||
_commandManager->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::setCommandManager(CommandManager * commandManager){ |
|||
_commandManager = commandManager; |
|||
} |
|||
|
|||
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(); |
|||
} |
|||
} |
|||
|
|||
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; } |
|||
} |
|||
|
|||
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)) { |
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
} |
|||
} |
|||
|
|||
} 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(); |
|||
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))) { |
|||
_commandManager->exec(new SelectSurfaceCommand( |
|||
surfaceManager, |
|||
surfaceManager->getSurface(i), |
|||
&projectionEditor)); |
|||
bSurfaceSelected = true; |
|||
break; |
|||
} |
|||
} |
|||
} |
|||
|
|||
if (bSurfaceSelected && hitJoint == NULL) { |
|||
// if not hitting the joints, start drag only if we have a selected
|
|||
// surface
|
|||
clickPosition = ofVec2f(args.x, args.y); |
|||
startDrag(); |
|||
|
|||
_commandManager->exec( |
|||
new MoveSurfaceCommand( |
|||
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(); |
|||
} |
|||
|
|||
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::setCommandManager(CommandManager * commandManager){ |
|||
_commandManager = commandManager; |
|||
} |
|||
|
|||
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(); |
|||
} |
|||
} |
|||
|
|||
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; } |
|||
} |
|||
} |
Loading…
Reference in new issue