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(){
_bTranslateCanvas = false;
_canvasTranslate = ofPoint(0, 0);
_clickCanvasTranslate = ofPoint(0, 0);
}
void TextureMappingState::draw(Application * app){
@ -85,25 +87,43 @@ void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEv
new DeselectTexCoordCmd(app->getGui()->getTextureEditor()));
_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){
cout << "TextureMappingState::onMouseReleased()" << endl;
_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){
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 distance = mousePosition - _clickPosition;
_canvasTranslate = _clickCanvasTranslate + distance;
}
}
} // namespace piMapper
} // namespace ofx

1
src/Application/States/TextureMappingState.h

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

31
src/Surfaces/SurfaceManagerGui.cpp

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

12
src/UserInterface/BaseJoint.cpp

@ -14,16 +14,18 @@ BaseJoint::~BaseJoint(){
}
void BaseJoint::registerMouseEvents(){
ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
//ofAddListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
//ofAddListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
}
void BaseJoint::unregisterMouseEvents(){
ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
//ofRemoveListener(ofEvents().mousePressed, this, &BaseJoint::mousePressed);
//ofRemoveListener(ofEvents().mouseDragged, this, &BaseJoint::mouseDragged);
}
void BaseJoint::mousePressed(ofMouseEventArgs & args){
cout << "BaseJoint::mousePressed()" << endl;
if(hitTest(ofVec2f(args.x, args.y))){
// selected = true;
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){
cout << "BaseJoint::mouseDragged()" << endl;
if(!bDrag){
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(){
if(surface == 0){
return;

2
src/UserInterface/TextureEditor.h

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

Loading…
Cancel
Save