|
|
@ -1,64 +1,64 @@ |
|
|
|
#include "ProjectionEditor.h" |
|
|
|
|
|
|
|
namespace ofx { |
|
|
|
namespace piMapper { |
|
|
|
ProjectionEditor::ProjectionEditor() { |
|
|
|
namespace piMapper { |
|
|
|
ProjectionEditor::ProjectionEditor() { |
|
|
|
surfaceManager = NULL; |
|
|
|
bShiftKeyDown = false; |
|
|
|
fSnapDistance = 10.0f; |
|
|
|
enable(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
ProjectionEditor::~ProjectionEditor() { |
|
|
|
ProjectionEditor::~ProjectionEditor() { |
|
|
|
clearJoints(); |
|
|
|
surfaceManager = NULL; |
|
|
|
disable(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::registerAppEvents() { |
|
|
|
void ProjectionEditor::registerAppEvents() { |
|
|
|
ofAddListener(ofEvents().update, this, &ProjectionEditor::update); |
|
|
|
ofAddListener(ofEvents().messageEvent, this, &ProjectionEditor::gotMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::unregisterAppEvents() { |
|
|
|
void ProjectionEditor::unregisterAppEvents() { |
|
|
|
ofRemoveListener(ofEvents().update, this, &ProjectionEditor::update); |
|
|
|
ofRemoveListener(ofEvents().messageEvent, this, |
|
|
|
&ProjectionEditor::gotMessage); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::registerMouseEvents() { |
|
|
|
void ProjectionEditor::registerMouseEvents() { |
|
|
|
ofAddListener(ofEvents().mouseDragged, this, &ProjectionEditor::mouseDragged); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::unregisterMouseEvents() { |
|
|
|
void ProjectionEditor::unregisterMouseEvents() { |
|
|
|
ofRemoveListener(ofEvents().mouseDragged, this, |
|
|
|
&ProjectionEditor::mouseDragged); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::registerKeyEvents() { |
|
|
|
void ProjectionEditor::registerKeyEvents() { |
|
|
|
ofAddListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|
|
|
ofAddListener(ofEvents().keyReleased, this, &ProjectionEditor::keyReleased); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::unregisterKeyEvents() { |
|
|
|
void ProjectionEditor::unregisterKeyEvents() { |
|
|
|
ofRemoveListener(ofEvents().keyPressed, this, &ProjectionEditor::keyPressed); |
|
|
|
ofRemoveListener(ofEvents().keyReleased, this, |
|
|
|
&ProjectionEditor::keyReleased); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::enable() { |
|
|
|
void ProjectionEditor::enable() { |
|
|
|
registerAppEvents(); |
|
|
|
registerMouseEvents(); |
|
|
|
registerKeyEvents(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::disable() { |
|
|
|
void ProjectionEditor::disable() { |
|
|
|
unregisterAppEvents(); |
|
|
|
unregisterMouseEvents(); |
|
|
|
unregisterKeyEvents(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::update(ofEventArgs& args) { |
|
|
|
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()) { |
|
|
@ -74,16 +74,16 @@ void ProjectionEditor::update(ofEventArgs& args) { |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::draw() { |
|
|
|
void ProjectionEditor::draw() { |
|
|
|
if (surfaceManager == NULL) return; |
|
|
|
if (surfaceManager->getSelectedSurface() == NULL) return; |
|
|
|
if (joints.size() <= 0) createJoints(); |
|
|
|
drawJoints(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::mouseDragged(ofMouseEventArgs& args) { |
|
|
|
void ProjectionEditor::mouseDragged(ofMouseEventArgs& args) { |
|
|
|
ofVec2f mousePosition = ofVec2f(args.x, args.y); |
|
|
|
|
|
|
|
// Collect all vertices of the projection surfaces
|
|
|
@ -114,9 +114,9 @@ void ProjectionEditor::mouseDragged(ofMouseEventArgs& args) { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::keyPressed(ofKeyEventArgs& args) { |
|
|
|
void ProjectionEditor::keyPressed(ofKeyEventArgs& args) { |
|
|
|
int key = args.key; |
|
|
|
float moveStep; |
|
|
|
|
|
|
@ -142,37 +142,37 @@ void ProjectionEditor::keyPressed(ofKeyEventArgs& args) { |
|
|
|
bShiftKeyDown = true; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::keyReleased(ofKeyEventArgs& args) { |
|
|
|
void ProjectionEditor::keyReleased(ofKeyEventArgs& args) { |
|
|
|
int key = args.key; |
|
|
|
switch (key) { |
|
|
|
case OF_KEY_SHIFT: |
|
|
|
bShiftKeyDown = false; |
|
|
|
break; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::gotMessage(ofMessage& msg) { |
|
|
|
void ProjectionEditor::gotMessage(ofMessage& msg) { |
|
|
|
if (msg.message == "surfaceSelected") { |
|
|
|
// refresh gui
|
|
|
|
clearJoints(); |
|
|
|
createJoints(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|
|
|
void ProjectionEditor::setSurfaceManager(SurfaceManager* newSurfaceManager) { |
|
|
|
surfaceManager = newSurfaceManager; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::clearJoints() { |
|
|
|
void ProjectionEditor::clearJoints() { |
|
|
|
while (joints.size()) { |
|
|
|
delete joints.back(); |
|
|
|
joints.pop_back(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::createJoints() { |
|
|
|
void ProjectionEditor::createJoints() { |
|
|
|
if (surfaceManager == NULL) return; |
|
|
|
clearJoints(); |
|
|
|
|
|
|
@ -188,23 +188,23 @@ void ProjectionEditor::createJoints() { |
|
|
|
joints.push_back(new CircleJoint()); |
|
|
|
joints.back()->position = ofVec2f(vertices[i].x, vertices[i].y); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::updateJoints() { |
|
|
|
void ProjectionEditor::updateJoints() { |
|
|
|
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() { |
|
|
|
void ProjectionEditor::unselectAllJoints() { |
|
|
|
for (int i = 0; i < joints.size(); i++) { |
|
|
|
joints[i]->unselect(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::moveSelectedSurface(ofVec2f by) { |
|
|
|
void ProjectionEditor::moveSelectedSurface(ofVec2f by) { |
|
|
|
if (surfaceManager == NULL) return; |
|
|
|
if (surfaceManager->getSelectedSurface() == NULL) return; |
|
|
|
surfaceManager->getSelectedSurface()->moveBy(by); |
|
|
@ -214,15 +214,15 @@ void ProjectionEditor::moveSelectedSurface(ofVec2f by) { |
|
|
|
vertices[i] += by; |
|
|
|
}*/ |
|
|
|
updateJoints(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::stopDragJoints() { |
|
|
|
void ProjectionEditor::stopDragJoints() { |
|
|
|
for (int i = 0; i < joints.size(); i++) { |
|
|
|
joints[i]->stopDrag(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::moveSelection(ofVec2f by) { |
|
|
|
void ProjectionEditor::moveSelection(ofVec2f by) { |
|
|
|
// check if joints selected
|
|
|
|
bool bJointSelected = false; |
|
|
|
BaseJoint* selectedJoint; |
|
|
@ -239,25 +239,29 @@ void ProjectionEditor::moveSelection(ofVec2f by) { |
|
|
|
} else { |
|
|
|
moveSelectedSurface(by); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
void ProjectionEditor::setSnapDistance(float newSnapDistance) { |
|
|
|
void ProjectionEditor::setSnapDistance(float newSnapDistance) { |
|
|
|
fSnapDistance = newSnapDistance; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
CircleJoint* ProjectionEditor::hitTestJoints(ofVec2f pos) { |
|
|
|
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() { |
|
|
|
void ProjectionEditor::drawJoints() { |
|
|
|
for (int i = 0; i < joints.size(); i++) { |
|
|
|
joints[i]->draw(); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |