Browse Source

Add texture translate working with crop smooth

This commit is based on a number of other broken features. Work in progress.
master
Krisjanis Rijnieks 9 years ago
parent
commit
fe7933d1b4
  1. 30
      src/Application/States/TextureMappingState.cpp
  2. 1
      src/Application/States/TextureMappingState.h
  3. 31
      src/Surfaces/SurfaceManagerGui.cpp
  4. 12
      src/UserInterface/BaseJoint.cpp
  5. 12
      src/UserInterface/TextureEditor.cpp
  6. 2
      src/UserInterface/TextureEditor.h

30
src/Application/States/TextureMappingState.cpp

@ -14,6 +14,8 @@ TextureMappingState * TextureMappingState::instance(){
TextureMappingState::TextureMappingState(){ TextureMappingState::TextureMappingState(){
_bTranslateCanvas = false; _bTranslateCanvas = false;
_canvasTranslate = ofPoint(0, 0);
_clickCanvasTranslate = ofPoint(0, 0);
} }
void TextureMappingState::draw(Application * app){ void TextureMappingState::draw(Application * app){
@ -85,25 +87,43 @@ void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEv
new DeselectTexCoordCmd(app->getGui()->getTextureEditor())); new DeselectTexCoordCmd(app->getGui()->getTextureEditor()));
_bTranslateCanvas = true; _bTranslateCanvas = true;
_clickPosition = ofPoint(e.args.x, e.args.y);
_clickCanvasTranslate = _canvasTranslate; }
void TextureMappingState::onMousePressed(Application * app, ofMouseEventArgs & args){
_clickPosition = ofPoint(args.x, args.y);
// Alter mouse event args to match canvas translation
args.x -= _canvasTranslate.x;
args.y -= _canvasTranslate.y;
app->getGui()->mousePressed(args);
} }
void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){ void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){
cout << "TextureMappingState::onMouseReleased()" << endl; cout << "TextureMappingState::onMouseReleased()" << endl;
_bTranslateCanvas = false; _bTranslateCanvas = false;
_clickCanvasTranslate = _canvasTranslate;
// Alter mouse event args to match canvas translation
args.x -= _canvasTranslate.x;
args.y -= _canvasTranslate.y;
app->getGui()->mouseReleased(args);
} }
void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){ void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){
if(!_bTranslateCanvas){ if(!_bTranslateCanvas){
return; // Alter mouse event args to match canvas translation
} args.x -= _canvasTranslate.x;
args.y -= _canvasTranslate.y;
app->getGui()->mouseDragged(args);
}else{
ofPoint mousePosition = ofPoint(args.x, args.y); ofPoint mousePosition = ofPoint(args.x, args.y);
ofPoint distance = mousePosition - _clickPosition; ofPoint distance = mousePosition - _clickPosition;
_canvasTranslate = _clickCanvasTranslate + distance; _canvasTranslate = _clickCanvasTranslate + distance;
} }
}
} // namespace piMapper } // namespace piMapper
} // namespace ofx } // namespace ofx

1
src/Application/States/TextureMappingState.h

@ -22,6 +22,7 @@ class TextureMappingState : public ApplicationBaseState {
void draw(Application * app); void draw(Application * app);
void onKeyPressed(Application * app, ofKeyEventArgs & args); void onKeyPressed(Application * app, ofKeyEventArgs & args);
void onBackgroundPressed(Application * app, GuiBackgroundEvent & e); void onBackgroundPressed(Application * app, GuiBackgroundEvent & e);
void onMousePressed(Application * app, ofMouseEventArgs & args);
void onMouseReleased(Application * app, ofMouseEventArgs & args); void onMouseReleased(Application * app, ofMouseEventArgs & args);
void onMouseDragged(Application * app, ofMouseEventArgs & args); void onMouseDragged(Application * app, ofMouseEventArgs & args);

31
src/Surfaces/SurfaceManagerGui.cpp

@ -19,21 +19,21 @@ SurfaceManagerGui::~SurfaceManagerGui(){
} }
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(){
@ -78,6 +78,8 @@ void SurfaceManagerGui::mousePressed(ofMouseEventArgs & args){
if(hitJoint != 0){ if(hitJoint != 0){
hitJoint->mousePressed(args);
textureEditor.unselectAllJoints(); textureEditor.unselectAllJoints();
hitJoint->select(); hitJoint->select();
hitJoint->startDrag(); hitJoint->startDrag();
@ -155,13 +157,14 @@ void SurfaceManagerGui::mouseReleased(ofMouseEventArgs & args){
if(!surfaceManager->getSelectedSurface()->getMoved()){ if(!surfaceManager->getSelectedSurface()->getMoved()){
// TODO: emit event through the gui singleton // TODO: emit event through the gui singleton
_cmdManager->undo(); //_cmdManager->undo();
} }
} }
} }
void SurfaceManagerGui::mouseDragged(ofMouseEventArgs & args){ void SurfaceManagerGui::mouseDragged(ofMouseEventArgs & args){
textureEditor.mouseDragged(args);
if(bDrag){ if(bDrag){
ofVec2f mousePosition = ofVec2f(args.x, args.y); ofVec2f mousePosition = ofVec2f(args.x, args.y);
ofVec2f distance = mousePosition - clickPosition; ofVec2f distance = mousePosition - clickPosition;

12
src/UserInterface/BaseJoint.cpp

@ -14,16 +14,18 @@ BaseJoint::~BaseJoint(){
} }
void BaseJoint::registerMouseEvents(){ void BaseJoint::registerMouseEvents(){
ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); //ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); //ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
} }
void BaseJoint::unregisterMouseEvents(){ void BaseJoint::unregisterMouseEvents(){
ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed); //ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged); //ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
} }
void BaseJoint::mousePressed(ofMouseEventArgs & args){ void BaseJoint::mousePressed(ofMouseEventArgs & args){
cout << "BaseJoint::mousePressed()" << endl;
if(hitTest(ofVec2f(args.x, args.y))){ if(hitTest(ofVec2f(args.x, args.y))){
// selected = true; // selected = true;
clickDistance = position - ofVec2f(args.x, args.y); clickDistance = position - ofVec2f(args.x, args.y);
@ -36,6 +38,8 @@ void BaseJoint::mouseReleased(int x, int y, int button){
} }
void BaseJoint::mouseDragged(ofMouseEventArgs & args){ void BaseJoint::mouseDragged(ofMouseEventArgs & args){
cout << "BaseJoint::mouseDragged()" << endl;
if(!bDrag){ if(!bDrag){
return; return;
} }

12
src/UserInterface/TextureEditor.cpp

@ -152,6 +152,18 @@ void TextureEditor::keyReleased(ofKeyEventArgs & args){
} }
} }
void TextureEditor::mousePressed(ofMouseEventArgs & args){
for(unsigned int i = 0; i < joints.size(); ++i){
joints[i]->mousePressed(args);
}
}
void TextureEditor::mouseDragged(ofMouseEventArgs & args){
for(unsigned int i = 0; i < joints.size(); ++i){
joints[i]->mouseDragged(args);
}
}
void TextureEditor::draw(){ void TextureEditor::draw(){
if(surface == 0){ if(surface == 0){
return; return;

2
src/UserInterface/TextureEditor.h

@ -26,6 +26,8 @@ class TextureEditor {
void update(ofEventArgs & args); void update(ofEventArgs & args);
void keyPressed(ofKeyEventArgs & args); void keyPressed(ofKeyEventArgs & args);
void keyReleased(ofKeyEventArgs & args); void keyReleased(ofKeyEventArgs & args);
void mousePressed(ofMouseEventArgs & args);
void mouseDragged(ofMouseEventArgs & args);
void draw(); void draw();
void drawJoints(); void drawJoints();
void setSurface(BaseSurface * newSurface); void setSurface(BaseSurface * newSurface);

Loading…
Cancel
Save