Permalink
Browse files

updates to text input to keep up with ofxTimeline

  • Loading branch information...
1 parent cd81926 commit f00e5742331e695e59e318e69e30234f508e9b88 @obviousjim obviousjim committed Aug 12, 2012
Showing with 15 additions and 9 deletions.
  1. +13 −8 src/ofxTextInputField.cpp
  2. +2 −1 src/ofxTextInputField.h
View
@@ -27,12 +27,13 @@ ofxTextInputField::ofxTextInputField() {
}
ofxTextInputField::~ofxTextInputField(){
- if(isSetup){
- ofRemoveListener(ofEvents().mouseReleased, this, &ofxTextInputField::mouseReleased);
- }
if(isEnabled){
disable();
}
+
+ if(isSetup){
+ ofRemoveListener(ofEvents().mouseReleased, this, &ofxTextInputField::mouseReleased);
+ }
}
void ofxTextInputField::setup(){
@@ -55,6 +56,7 @@ void ofxTextInputField::disable() {
if(isEnabled){
ofRemoveListener(ofEvents().keyPressed, this, &ofxTextInputField::keyPressed);
ofSendMessage(TEXTFIELD_IS_INACTIVE);
+ ofNotifyEvent(textChanged, text, this);
isEnabled = false;
drawCursor = false;
}
@@ -90,11 +92,15 @@ void ofxTextInputField::draw() {
void ofxTextInputField::mouseReleased(ofMouseEventArgs& args){
if (bounds.inside(args.x, args.y)) {
- enable();
- clear();
+ if(!isEnabled){
+ enable();
+ clear();
+ }
}
else{
- disable();
+ if(isEnabled){
+ disable();
+ }
}
}
@@ -103,13 +109,12 @@ void ofxTextInputField::keyPressed(ofKeyEventArgs& args) {
int key = args.key;
if (key == OF_KEY_RETURN) {
-// return;
- ofNotifyEvent(evtEnter, text, this);
disable();
// if (evtEnter.empty()) {
// text.insert(text.begin()+cursorPosition, '\n');
// cursorPosition++;
// }
+ return;
}
if (key >=32 && key <=126) {
View
@@ -41,10 +41,11 @@ class ofxTextInputField {
string text;
int cursorPosition;
- ofEvent<string> evtEnter;
+ ofEvent<string> textChanged;
void keyPressed(ofKeyEventArgs &a);
protected:
+
bool isSetup;
bool isEnabled;

0 comments on commit f00e574

Please sign in to comment.