From d0c31eeb7eea0e60396dcc4264fbef72f11990e4 Mon Sep 17 00:00:00 2001 From: Andrei Thomaz Date: Wed, 20 May 2015 03:03:49 -0300 Subject: [PATCH] fix to multiple input fields - https://github.com/rezaali/ofxUI/issues/209 --- src/ofApp.cpp | 33 +++++++++++++++++++++++++++++++++ src/ofApp.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/src/ofApp.cpp b/src/ofApp.cpp index 3d8683f..cc43052 100644 --- a/src/ofApp.cpp +++ b/src/ofApp.cpp @@ -66,6 +66,7 @@ void ofApp::setup(){ this->cameraWidthTextInput->setDrawOutline(true); this->cameraWidthTextInput->setDrawOutlineHighLight(true); this->cameraPanel->addWidgetRight( cameraWidthTextInput ); + this->textInputs.push_back(this->cameraWidthTextInput); ofxUILabel* cameraHeightLabel = new ofxUILabel(170, ofApp::CAMERA_HEIGHT_LABEL, OFX_UI_FONT_SMALL); this->cameraPanel->addWidgetDown( cameraHeightLabel ); @@ -74,6 +75,7 @@ void ofApp::setup(){ this->cameraHeightTextInput->setDrawOutline(true); this->cameraHeightTextInput->setDrawOutlineHighLight(true); this->cameraPanel->addWidgetRight( this->cameraHeightTextInput ); + this->textInputs.push_back(this->cameraHeightTextInput); this->rotations = 0; @@ -110,6 +112,7 @@ void ofApp::setup(){ this->columnsTextInput->setDrawOutline(true); this->columnsTextInput->setDrawOutlineHighLight(true); this->imagePanel->addWidgetRight( this->columnsTextInput ); + this->textInputs.push_back(this->columnsTextInput); ofxUILabel* secondsPerImageLabel = new ofxUILabel(390, ofApp::SECONDS_PER_IMAGE_LABEL, OFX_UI_FONT_SMALL); this->imagePanel->addWidgetDown( secondsPerImageLabel ); @@ -119,6 +122,7 @@ void ofApp::setup(){ this->secondsPerImageTextInput->setDrawOutline(true); this->secondsPerImageTextInput->setDrawOutlineHighLight(true); this->imagePanel->addWidgetDown( this->secondsPerImageTextInput ); + this->textInputs.push_back(this->secondsPerImageTextInput); this->saveImageToggle = new ofxUIToggle(ofApp::SAVE_IMAGE_LABEL, true, 16, 16); this->saveImageToggle->setDrawOutline(true); @@ -131,6 +135,7 @@ void ofApp::setup(){ this->intervalToSaveTextInput->setDrawOutline(true); this->intervalToSaveTextInput->setDrawOutlineHighLight(true); this->imagePanel->addWidgetRight( this->intervalToSaveTextInput ); + this->textInputs.push_back(this->intervalToSaveTextInput); ofxUILabel* minutesLabel = new ofxUILabel(170, "minutos", OFX_UI_FONT_SMALL); this->imagePanel->addWidgetRight( minutesLabel ); @@ -426,6 +431,13 @@ void ofApp::guiEvent(ofxUIEventArgs &e) ofLaunchBrowser("http://www.funarte.gov.br/"); } } + + if (e.getKind() == OFX_UI_WIDGET_TEXTINPUT){ + ofxUITextInput *ti = (ofxUITextInput *) e.widget; + if (ti->getInputTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS){ + this->unfocusAllTextInputs(ti); + } + } } void ofApp::cameraPanelEvent(ofxUIEventArgs &e) @@ -451,6 +463,12 @@ void ofApp::cameraPanelEvent(ofxUIEventArgs &e) this->oneHundredEightyRotationToggle->setValue(false); } + if (e.getKind() == OFX_UI_WIDGET_TEXTINPUT){ + ofxUITextInput *ti = (ofxUITextInput *) e.widget; + if (ti->getInputTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS){ + this->unfocusAllTextInputs(ti); + } + } } void ofApp::imagePanelEvent(ofxUIEventArgs &e) @@ -462,6 +480,13 @@ void ofApp::imagePanelEvent(ofxUIEventArgs &e) this->screenImage.saveImage("candle_clock.png"); } } + + if (e.getKind() == OFX_UI_WIDGET_TEXTINPUT){ + ofxUITextInput *ti = (ofxUITextInput *) e.widget; + if (ti->getInputTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS){ + this->unfocusAllTextInputs(ti); + } + } } void ofApp::hideConfigurationPanel() @@ -553,3 +578,11 @@ void ofApp::applyConfigurationChanges() ofSetWindowShape(this->imageWidth, this->imageHeight); } } + +void ofApp::unfocusAllTextInputs(ofxUITextInput* except){ + for (int i = 0; i < this->textInputs.size(); i ++){ + if (except != this->textInputs[i]){ + this->textInputs[i]->setFocus(false); + } + } +} diff --git a/src/ofApp.h b/src/ofApp.h index bf0994b..7f3a418 100644 --- a/src/ofApp.h +++ b/src/ofApp.h @@ -52,6 +52,8 @@ class ofApp : public ofBaseApp{ ofxUIToggle* saveImageToggle; bool saveImage; + std::vector textInputs; + void saveCurrentImage(); void fillImageWithWhite( ofImage* image ); void reset(); @@ -59,6 +61,7 @@ class ofApp : public ofBaseApp{ void applyConfigurationChanges(); void hideConfigurationPanel(); void showConfigurationPanel(); + void unfocusAllTextInputs(ofxUITextInput* except); const static string CAMERA_WIDTH_LABEL; const static string CAMERA_HEIGHT_LABEL;