From c436eccb35ce88e01851f75c68001454f5992b35 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Fri, 16 Sep 2016 11:51:12 +0300 Subject: [PATCH] Enable texture mapping draw mode switching with 9 and 0 keys --- .../States/TextureMappingState.cpp | 75 ++++++++++++++++--- src/Application/States/TextureMappingState.h | 3 + 2 files changed, 68 insertions(+), 10 deletions(-) diff --git a/src/Application/States/TextureMappingState.cpp b/src/Application/States/TextureMappingState.cpp index 42e6dde..db47df7 100644 --- a/src/Application/States/TextureMappingState.cpp +++ b/src/Application/States/TextureMappingState.cpp @@ -20,21 +20,47 @@ TextureMappingState::TextureMappingState(){ } void TextureMappingState::draw(Application * app){ - ofPushMatrix(); - ofTranslate(_canvasTranslate.x, _canvasTranslate.y); - app->getGui()->draw(); - ofPopMatrix(); + if(_drawMode == 0){ + // Texture on the back + ofPushMatrix(); + ofTranslate(_canvasTranslate.x, _canvasTranslate.y); + app->getGui()->draw(); - ofPushStyle(); - ofSetColor(255, 255, 255, 150); - app->getSurfaceManager()->draw(); - ofPopStyle(); + // Semi-transparent surfaces on the front + ofPushStyle(); + ofSetColor(255, 255, 255, 150); + app->getSurfaceManager()->draw(); + ofPopStyle(); + ofPopMatrix(); + }else if(_drawMode == 1){ + // Testure on the background + ofPushMatrix(); + ofTranslate(_canvasTranslate.x, _canvasTranslate.y); + app->getGui()->draw(); + + // Opaque surfaces on the front + ofPushStyle(); + ofSetColor(255, 255, 255, 255); + app->getSurfaceManager()->draw(); + ofPopStyle(); + ofPopMatrix(); + }else if(_drawMode == 2){ + // Texture only + ofPushMatrix(); + ofTranslate(_canvasTranslate.x, _canvasTranslate.y); + app->getGui()->draw(); + ofPopMatrix(); + }else{ + _drawMode = 0; + } ofPushMatrix(); ofTranslate(_canvasTranslate.x, _canvasTranslate.y); - Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager()); - Gui::instance()->getSurfaceHighlightWidget().draw(); + if(_drawMode != 2){ + Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager()); + Gui::instance()->getSurfaceHighlightWidget().draw(); + } Gui::instance()->getTextureHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getTextureHighlightWidget().draw(); @@ -78,6 +104,15 @@ void TextureMappingState::onKeyPressed(Application * app, ofKeyEventArgs & args) app->getCmdManager()->exec(new SelNextSurfaceCmd(app->getSurfaceManager())); } break; + + case '0': // Next draw mode + app->getCmdManager()->exec(new SetTexMapDrawModeCmd( this, getNextDrawMode() )); + break; + + case '9': // Prew draw mode + app->getCmdManager()->exec(new SetTexMapDrawModeCmd( this, getPrevDrawMode() )); + break; + } } @@ -159,5 +194,25 @@ int TextureMappingState::getDrawMode(){ return _drawMode; } +int TextureMappingState::getNextDrawMode(){ + int nextDrawMode = _drawMode + 1; + + if(nextDrawMode > 2){ + nextDrawMode = 0; + } + + return nextDrawMode; +} + +int TextureMappingState::getPrevDrawMode(){ + int prevDrawMode = _drawMode - 1; + + if(prevDrawMode < 0){ + prevDrawMode = 2; + } + + return prevDrawMode; +} + } // namespace piMapper } // namespace ofx \ No newline at end of file diff --git a/src/Application/States/TextureMappingState.h b/src/Application/States/TextureMappingState.h index 8370e4d..5f2348f 100644 --- a/src/Application/States/TextureMappingState.h +++ b/src/Application/States/TextureMappingState.h @@ -11,6 +11,7 @@ #include "SelNextSurfaceCmd.h" #include "ToggleAnimatedSourceCmd.h" #include "TranslateCanvasCmd.h" +#include "SetTexMapDrawModeCmd.h" #include "Gui.h" namespace ofx { @@ -34,6 +35,8 @@ class TextureMappingState : public ApplicationBaseState { void setDrawMode(int m); int getDrawMode(); + int getNextDrawMode(); + int getPrevDrawMode(); private: static TextureMappingState * _instance;