From 533f82abdc6ceda8f012758d48afaee500b463dd Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Sat, 10 May 2014 14:42:19 +0200 Subject: [PATCH] Fix surface GUI setMode method and add mode switching with 1,2,3 keys to the example --- example/src/ofApp.cpp | 14 ++++++++++---- src/ofxSurfaceGui.cpp | 8 +++++--- 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp index bbd4655..14da4f2 100644 --- a/example/src/ofApp.cpp +++ b/example/src/ofApp.cpp @@ -2,12 +2,11 @@ void ofApp::setup() { - //ofGetCurrentRenderer()->setLineSmoothing(true); - // Load test pattern image image.loadImage("TestPatternInvert.jpg"); - // Create a triangle surface - //triangleSurface.setup( ofVec2f(30,40), ofVec2f(500,500), ofVec2f(0,600), ofVec2f(0,0), ofVec2f(1,1), ofVec2f(0,1), &image.getTextureReference() ); + triangleSurface.setup(ofVec2f(30,40), ofVec2f(500,500), ofVec2f(0,600), + ofVec2f(0,0), ofVec2f(1,1), ofVec2f(0,1), + &image.getTextureReference()); gui.setup(triangleSurface); } @@ -38,6 +37,13 @@ void ofApp::draw() void ofApp::keyPressed(int key) { cout << "Key pressed: " << static_cast(key) << endl; + + switch (key) { + case '1': gui.setMode(ofxSurfaceGui::NONE); break; + case '2': gui.setMode(ofxSurfaceGui::TEXTURE_MAPPING); break; + case '3': gui.setMode(ofxSurfaceGui::PROJECTION_MAPPING); break; + default: break; + } } void ofApp::mousePressed(int x, int y, int button) diff --git a/src/ofxSurfaceGui.cpp b/src/ofxSurfaceGui.cpp index 2461736..32dad03 100644 --- a/src/ofxSurfaceGui.cpp +++ b/src/ofxSurfaceGui.cpp @@ -3,7 +3,7 @@ ofxSurfaceGui::ofxSurfaceGui() { surface = NULL; - mode = TEXTURE_MAPPING; + mode = NONE; } ofxSurfaceGui::~ofxSurfaceGui() @@ -107,11 +107,13 @@ void ofxSurfaceGui::mouseDragged(int x, int y, int button) void ofxSurfaceGui::setMode(ofxSurfaceGui::editMode newMode) { - if (mode != NONE || - mode != PROJECTION_MAPPING || + if (mode != NONE && + mode != PROJECTION_MAPPING && mode != TEXTURE_MAPPING) { throw std::runtime_error("Trying to set invalid mode."); }; + + mode = newMode; } ofxSurfaceGui::editMode ofxSurfaceGui::getMode()