Browse Source

Improve texture mapping mode code

master
Krisjanis Rijnieks 9 years ago
parent
commit
0f0aa49e37
  1. 44
      src/Application/States/TextureMappingState.cpp
  2. 1
      src/Application/States/TextureMappingState.h
  3. 4
      src/Surfaces/SurfaceManagerGui.cpp

44
src/Application/States/TextureMappingState.cpp

@ -20,43 +20,28 @@ TextureMappingState::TextureMappingState(){
} }
void TextureMappingState::draw(Application * app){ void TextureMappingState::draw(Application * app){
if(_drawMode == 0){
// Texture on the back
ofPushMatrix(); ofPushMatrix();
ofTranslate(_canvasTranslate.x, _canvasTranslate.y); ofTranslate(_canvasTranslate.x, _canvasTranslate.y);
app->getGui()->draw();
// Semi-transparent surfaces on the front if(_drawMode == 0){ // Semi-transparent surfaces on front
drawTexture(app);
ofPushStyle(); ofPushStyle();
ofSetColor(255, 255, 255, 150); ofSetColor(255, 255, 255, 150);
app->getSurfaceManager()->draw(); app->getSurfaceManager()->draw();
ofPopStyle(); ofPopStyle();
ofPopMatrix(); }else if(_drawMode == 1){ // Opaque surfaces on front
}else if(_drawMode == 1){ drawTexture(app);
// Testure on the background
ofPushMatrix();
ofTranslate(_canvasTranslate.x, _canvasTranslate.y);
app->getGui()->draw();
// Opaque surfaces on the front
ofPushStyle(); ofPushStyle();
ofSetColor(255, 255, 255, 255); ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->draw(); app->getSurfaceManager()->draw();
ofPopStyle(); ofPopStyle();
ofPopMatrix(); }else if(_drawMode == 2){ // Draw texture only
}else if(_drawMode == 2){
// Texture only
ofPushMatrix();
ofTranslate(_canvasTranslate.x, _canvasTranslate.y); ofTranslate(_canvasTranslate.x, _canvasTranslate.y);
app->getGui()->draw(); drawTexture(app);
ofPopMatrix();
}else{ }else{
_drawMode = 0; _drawMode = 0;
} }
ofPushMatrix();
ofTranslate(_canvasTranslate.x, _canvasTranslate.y);
if(_drawMode != 2){ if(_drawMode != 2){
Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getSurfaceHighlightWidget().setSurfaceManager(app->getSurfaceManager());
Gui::instance()->getSurfaceHighlightWidget().draw(); Gui::instance()->getSurfaceHighlightWidget().draw();
@ -65,6 +50,9 @@ void TextureMappingState::draw(Application * app){
Gui::instance()->getTextureHighlightWidget().setSurfaceManager(app->getSurfaceManager()); Gui::instance()->getTextureHighlightWidget().setSurfaceManager(app->getSurfaceManager());
Gui::instance()->getTextureHighlightWidget().draw(); Gui::instance()->getTextureHighlightWidget().draw();
// TODO: Replace with a transform widget.
app->getGui()->getTextureEditor()->draw();
ofPopMatrix(); ofPopMatrix();
} }
@ -177,6 +165,20 @@ void TextureMappingState::onMouseDragged(Application * app, ofMouseEventArgs & a
} }
} }
void TextureMappingState::drawTexture(Application * app){
if(app->getSurfaceManager()->getSelectedSurface() != 0){
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords();
ofEnableNormalizedTexCoords();
ofSetColor(255, 255, 255, 255);
app->getSurfaceManager()->getSelectedSurface()->drawTexture(ofVec2f(0, 0));
if(!normalizedTexCoords){
ofDisableNormalizedTexCoords();
}
}
}
ofPoint TextureMappingState::getTranslation(){ ofPoint TextureMappingState::getTranslation(){
return _canvasTranslate; return _canvasTranslate;
} }

1
src/Application/States/TextureMappingState.h

@ -27,6 +27,7 @@ class TextureMappingState : public ApplicationBaseState {
void onMousePressed(Application * app, ofMouseEventArgs & args); 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);
void drawTexture(Application * app);
void onGuiEvent(Application * app, GuiEvent & e){} void onGuiEvent(Application * app, GuiEvent & e){}

4
src/Surfaces/SurfaceManagerGui.cpp

@ -43,6 +43,7 @@ void SurfaceManagerGui::draw(){
if(guiMode == GuiMode::TEXTURE_MAPPING){ if(guiMode == GuiMode::TEXTURE_MAPPING){
// draw the texture of the selected surface // draw the texture of the selected surface
/*
if(surfaceManager->getSelectedSurface() != 0){ if(surfaceManager->getSelectedSurface() != 0){
bool normalizedTexCoords = ofGetUsingNormalizedTexCoords(); bool normalizedTexCoords = ofGetUsingNormalizedTexCoords();
ofEnableNormalizedTexCoords(); ofEnableNormalizedTexCoords();
@ -55,9 +56,10 @@ void SurfaceManagerGui::draw(){
ofDisableNormalizedTexCoords(); ofDisableNormalizedTexCoords();
} }
} }
*/
// draw texture editing GUI on top // draw texture editing GUI on top
textureEditor.draw(); //textureEditor.draw();
}else if(guiMode == GuiMode::PROJECTION_MAPPING){ }else if(guiMode == GuiMode::PROJECTION_MAPPING){
projectionEditor.draw(); projectionEditor.draw();
}else if(guiMode == GuiMode::SOURCE_SELECTION){ }else if(guiMode == GuiMode::SOURCE_SELECTION){

Loading…
Cancel
Save