Browse Source

Try out texture dragging

master
Krisjanis Rijnieks 9 years ago
parent
commit
8ac6d9dff2
  1. 36
      src/Application/States/TextureMappingState.cpp
  2. 10
      src/Application/States/TextureMappingState.h

36
src/Application/States/TextureMappingState.cpp

@ -12,19 +12,31 @@ TextureMappingState * TextureMappingState::instance(){
return _instance; return _instance;
} }
TextureMappingState::TextureMappingState(){
_bTranslateCanvas = false;
}
void TextureMappingState::draw(Application * app){ void TextureMappingState::draw(Application * app){
ofPushMatrix();
ofTranslate(_canvasTranslate.x, _canvasTranslate.y);
app->getGui()->draw(); app->getGui()->draw();
ofPopMatrix();
ofPushStyle(); ofPushStyle();
ofSetColor(255, 255, 255, 150); ofSetColor(255, 255, 255, 150);
app->getSurfaceManager()->draw(); app->getSurfaceManager()->draw();
ofPopStyle(); ofPopStyle();
ofPushMatrix();
ofTranslate(_canvasTranslate.x, _canvasTranslate.y);
Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager());
Gui::instance()->getSurfaceHighlightWidget().draw(); Gui::instance()->getSurfaceHighlightWidget().draw();
Gui::instance()->getTextureHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getTextureHighlightWidget().setSurfaceManager(app->getSurfaceManager());
Gui::instance()->getTextureHighlightWidget().draw(); Gui::instance()->getTextureHighlightWidget().draw();
ofPopMatrix();
} }
void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args){
@ -67,8 +79,30 @@ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args)
} }
void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){ void TextureMappingState::onBackgroundPressed(Application * app, GuiBackgroundEvent & e){
app->getCmdManager()->exec( cout << "TextureMappingState::onBackgroundPressed()" << endl;
app->getCmdManager()->exec(
new DeselectTexCoordCmd(app->getGui()->getTextureEditor())); new DeselectTexCoordCmd(app->getGui()->getTextureEditor()));
_bTranslateCanvas = true;
_clickPosition = ofPoint(e.args.x, e.args.y);
_clickCanvasTranslate = _canvasTranslate;
}
void TextureMappingState::onMouseReleased(Application * app, ofMouseEventArgs & args){
cout << "TextureMappingState::onMouseReleased()" << endl;
_bTranslateCanvas = false;
}
void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & args){
if(!_bTranslateCanvas){
return;
}
ofPoint mousePosition = ofPoint(args.x, args.y);
ofPoint distance = mousePosition - _clickPosition;
_canvasTranslate = _clickCanvasTranslate + distance;
} }
} // namespace piMapper } // namespace piMapper

10
src/Application/States/TextureMappingState.h

@ -22,11 +22,21 @@ 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 onMouseReleased(Application * app, ofMouseEventArgs & args);
void onMouseDragged(Application * app, ofMouseEventArgs & args);
void onGuiEvent(Application * app, GuiEvent & e){} void onGuiEvent(Application * app, GuiEvent & e){}
private: private:
static TextureMappingState * _instance; static TextureMappingState * _instance;
TextureMappingState();
bool _bTranslateCanvas;
ofPoint _clickPosition;
ofPoint _canvasTranslate;
ofPoint _clickCanvasTranslate;
}; };

Loading…
Cancel
Save