Skip to content

Commit

Permalink
fix to multiple input fields - rezaali/ofxUI#209
Browse files Browse the repository at this point in the history
  • Loading branch information
andreirt committed May 20, 2015
1 parent 0bb139e commit d0c31ee
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/ofApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand All @@ -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;

Expand Down Expand Up @@ -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 );
Expand All @@ -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);
Expand All @@ -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 );
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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()
Expand Down Expand Up @@ -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);
}
}
}
3 changes: 3 additions & 0 deletions src/ofApp.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,16 @@ class ofApp : public ofBaseApp{
ofxUIToggle* saveImageToggle;
bool saveImage;

std::vector<ofxUITextInput*> textInputs;

void saveCurrentImage();
void fillImageWithWhite( ofImage* image );
void reset();
void cancelConfigurationChanges();
void applyConfigurationChanges();
void hideConfigurationPanel();
void showConfigurationPanel();
void unfocusAllTextInputs(ofxUITextInput* except);

const static string CAMERA_WIDTH_LABEL;
const static string CAMERA_HEIGHT_LABEL;
Expand Down

0 comments on commit d0c31ee

Please sign in to comment.