6 changed files with 387 additions and 381 deletions
@ -1,90 +1,94 @@ |
|||||
#include "BaseSurface.h" |
#include "BaseSurface.h" |
||||
|
|
||||
namespace ofx { |
namespace ofx { |
||||
namespace piMapper { |
namespace piMapper { |
||||
|
|
||||
BaseSurface::BaseSurface() { |
BaseSurface::BaseSurface() { |
||||
ofEnableNormalizedTexCoords(); |
_moved = false; |
||||
createDefaultTexture(); |
ofEnableNormalizedTexCoords(); |
||||
} |
createDefaultTexture(); |
||||
|
} |
||||
|
|
||||
BaseSurface::~BaseSurface() { |
BaseSurface::~BaseSurface() { |
||||
delete defaultSource; |
delete defaultSource; |
||||
defaultSource = NULL; |
defaultSource = NULL; |
||||
defaultTexture.clear(); |
defaultTexture.clear(); |
||||
} |
} |
||||
|
|
||||
void BaseSurface::createDefaultTexture() { |
void BaseSurface::createDefaultTexture() { |
||||
ofPixels pixels; |
ofPixels pixels; |
||||
pixels.allocate(500, 500, 1); |
pixels.allocate(500, 500, 1); |
||||
for (int i = 0; i < pixels.size(); i++) { |
for (int i = 0; i < pixels.size(); i++) { |
||||
pixels[i] = 255; |
pixels[i] = 255; |
||||
} |
} |
||||
int squareSize = 10; // size of each test pattern square
|
int squareSize = 10; // size of each test pattern square
|
||||
bool sy = false; |
bool sy = false; |
||||
for (int y = 0; y < pixels.getWidth(); y += squareSize) { |
for (int y = 0; y < pixels.getWidth(); y += squareSize) { |
||||
bool sx = false; |
bool sx = false; |
||||
for (int x = 0; x < pixels.getHeight(); x += squareSize) { |
for (int x = 0; x < pixels.getHeight(); x += squareSize) { |
||||
for (int yi = 0; yi < squareSize; yi++) { |
for (int yi = 0; yi < squareSize; yi++) { |
||||
for (int xi = 0; xi < squareSize; xi++) { |
for (int xi = 0; xi < squareSize; xi++) { |
||||
if (sx && sy) |
if (sx && sy) |
||||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
||||
else if (sx && !sy) |
else if (sx && !sy) |
||||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
||||
else if (!sx && sy) |
else if (!sx && sy) |
||||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
pixels[(y + yi) * pixels.getWidth() + x + xi] = 0; |
||||
else |
else |
||||
pixels[(y + yi) * pixels.getWidth() + x + xi] = 255; |
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" |
#include "SurfaceManagerGui.h" |
||||
|
|
||||
namespace ofx { |
namespace ofx { |
||||
namespace piMapper { |
namespace piMapper { |
||||
SurfaceManagerGui::SurfaceManagerGui() { |
SurfaceManagerGui::SurfaceManagerGui() { |
||||
surfaceManager = NULL; |
surfaceManager = NULL; |
||||
guiMode = GuiMode::NONE; |
guiMode = GuiMode::NONE; |
||||
bDrag = false; |
bDrag = false; |
||||
registerMouseEvents(); |
registerMouseEvents(); |
||||
ofHideCursor(); |
ofHideCursor(); |
||||
_commandManager = 0; |
_commandManager = 0; |
||||
} |
} |
||||
|
|
||||
SurfaceManagerGui::~SurfaceManagerGui() { |
SurfaceManagerGui::~SurfaceManagerGui() { |
||||
unregisterMouseEvents(); |
unregisterMouseEvents(); |
||||
surfaceManager = NULL; |
surfaceManager = NULL; |
||||
_commandManager = 0; |
_commandManager = 0; |
||||
} |
} |
||||
|
|
||||
void SurfaceManagerGui::registerMouseEvents() { |
void SurfaceManagerGui::registerMouseEvents() { |
||||
ofAddListener(ofEvents().mousePressed, this, |
ofAddListener(ofEvents().mousePressed, this, |
||||
&SurfaceManagerGui::mousePressed); |
&SurfaceManagerGui::mousePressed); |
||||
ofAddListener(ofEvents().mouseReleased, this, |
ofAddListener(ofEvents().mouseReleased, this, |
||||
&SurfaceManagerGui::mouseReleased); |
&SurfaceManagerGui::mouseReleased); |
||||
ofAddListener(ofEvents().mouseDragged, this, |
ofAddListener(ofEvents().mouseDragged, this, |
||||
&SurfaceManagerGui::mouseDragged); |
&SurfaceManagerGui::mouseDragged); |
||||
} |
} |
||||
|
|
||||
void SurfaceManagerGui::unregisterMouseEvents() { |
void SurfaceManagerGui::unregisterMouseEvents() { |
||||
ofRemoveListener(ofEvents().mousePressed, this, |
ofRemoveListener(ofEvents().mousePressed, this, |
||||
&SurfaceManagerGui::mousePressed); |
&SurfaceManagerGui::mousePressed); |
||||
ofRemoveListener(ofEvents().mouseReleased, this, |
ofRemoveListener(ofEvents().mouseReleased, this, |
||||
&SurfaceManagerGui::mouseReleased); |
&SurfaceManagerGui::mouseReleased); |
||||
ofRemoveListener(ofEvents().mouseDragged, this, |
ofRemoveListener(ofEvents().mouseDragged, this, |
||||
&SurfaceManagerGui::mouseDragged); |
&SurfaceManagerGui::mouseDragged); |
||||
} |
} |
||||
|
|
||||
void SurfaceManagerGui::draw() { |
void SurfaceManagerGui::draw() { |
||||
if (surfaceManager == NULL) return; |
if (surfaceManager == NULL) return; |
||||
|
|
||||
if (guiMode == GuiMode::NONE) { |
if (guiMode == GuiMode::NONE) { |
||||
surfaceManager->draw(); |
surfaceManager->draw(); |
||||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
||||
// draw the texture of the selected surface
|
// draw the texture of the selected surface
|
||||
if (surfaceManager->getSelectedSurface() != NULL) { |
if (surfaceManager->getSelectedSurface() != NULL) { |
||||
surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); |
surfaceManager->getSelectedSurface()->drawTexture(ofVec2f(0, 0)); |
||||
} |
} |
||||
|
|
||||
// draw surfaces with opacity
|
// draw surfaces with opacity
|
||||
ofPushStyle(); |
ofPushStyle(); |
||||
ofSetColor(255, 255, 255, 200); |
ofSetColor(255, 255, 255, 200); |
||||
surfaceManager->draw(); |
surfaceManager->draw(); |
||||
ofPopStyle(); |
ofPopStyle(); |
||||
|
|
||||
// highlight selected surface
|
// highlight selected surface
|
||||
drawSelectedSurfaceHighlight(); |
drawSelectedSurfaceHighlight(); |
||||
|
|
||||
// hilight selected surface texture
|
// hilight selected surface texture
|
||||
drawSelectedSurfaceTextureHighlight(); |
drawSelectedSurfaceTextureHighlight(); |
||||
|
|
||||
// draw texture editing GUI on top
|
// draw texture editing GUI on top
|
||||
textureEditor.draw(); |
textureEditor.draw(); |
||||
|
|
||||
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { |
} else if (guiMode == GuiMode::PROJECTION_MAPPING) { |
||||
// draw projection surfaces first
|
// draw projection surfaces first
|
||||
surfaceManager->draw(); |
surfaceManager->draw(); |
||||
|
|
||||
// highlight selected surface
|
// highlight selected surface
|
||||
drawSelectedSurfaceHighlight(); |
drawSelectedSurfaceHighlight(); |
||||
|
|
||||
// draw projection mapping editing gui
|
// draw projection mapping editing gui
|
||||
projectionEditor.draw(); |
projectionEditor.draw(); |
||||
|
|
||||
} else if (guiMode == GuiMode::SOURCE_SELECTION) { |
} else if (guiMode == GuiMode::SOURCE_SELECTION) { |
||||
// draw projection surfaces first
|
// draw projection surfaces first
|
||||
surfaceManager->draw(); |
surfaceManager->draw(); |
||||
|
|
||||
// highlight selected surface
|
// highlight selected surface
|
||||
drawSelectedSurfaceHighlight(); |
drawSelectedSurfaceHighlight(); |
||||
|
|
||||
sourcesEditor.draw(); |
sourcesEditor.draw(); |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
void SurfaceManagerGui::mousePressed(ofMouseEventArgs& args) { |
||||
if (guiMode == GuiMode::NONE) { |
if (guiMode == GuiMode::NONE) { |
||||
return; |
return; |
||||
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
} else if (guiMode == GuiMode::TEXTURE_MAPPING) { |
||||
bool bSurfaceSelected = false; |
bool bSurfaceSelected = false; |
||||
|
|
||||
CircleJoint* hitJoint = |
CircleJoint* hitJoint = |
||||
textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
textureEditor.hitTestJoints(ofVec2f(args.x, args.y)); |
||||
if (hitJoint != NULL) { |
if (hitJoint != NULL) { |
||||
textureEditor.unselectAllJoints(); |
textureEditor.unselectAllJoints(); |
||||
hitJoint->select(); |
hitJoint->select(); |
||||
hitJoint->startDrag(); |
hitJoint->startDrag(); |
||||
bSurfaceSelected = true; |
bSurfaceSelected = true; |
||||
} else { |
} else { |
||||
textureEditor.unselectAllJoints(); |
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