Last active
December 29, 2015 17:39
-
-
Save lg3bass/7705931 to your computer and use it in GitHub Desktop.
OF>drag-n-drop file path
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//-------------------------------------------------------------- | |
void testApp::setup(){ | |
setGUI(); | |
} | |
//-------------------------------------------------------------- | |
void testApp::draw(){ | |
ofSetColor(255); | |
float dx = dragPt.x; | |
float dy = dragPt.y; | |
} | |
//-------------------------------------------------------------- | |
void testApp::guiEvent(ofxUIEventArgs &e) | |
{ | |
string name = e.widget->getName(); | |
int kind = e.widget->getKind(); | |
cout << "got event from: " << name << endl; | |
if(name == "TEXT INPUT_1") | |
{ | |
ofxUITextInput *textinput = (ofxUITextInput *) e.widget; | |
if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_ENTER) | |
{ | |
cout << "ON ENTER: "; | |
// ofUnregisterKeyEvents((testApp*)this); | |
} | |
else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_FOCUS) | |
{ | |
cout << "ON FOCUS: "; | |
} | |
else if(textinput->getTriggerType() == OFX_UI_TEXTINPUT_ON_UNFOCUS) | |
{ | |
cout << "ON BLUR: "; | |
// ofRegisterKeyEvents(this); | |
} | |
string output = textinput->getTextString(); | |
cout << output << endl; | |
} | |
} | |
void testApp::setGUI() | |
{ | |
float xInit = OFX_UI_GLOBAL_WIDGET_SPACING; | |
gui2 = new ofxUICanvas(0, 0, ofGetWidth(), ofGetHeight()); | |
gui2->addWidgetDown(new ofxUILabel("DRAG-n-DROP", OFX_UI_FONT_MEDIUM)); | |
gui2->addSpacer(); | |
gui2->addWidgetDown(new ofxUILabel("Drag a file from the finder into the text field.", OFX_UI_FONT_SMALL)); | |
gui2->setWidgetFontSize(OFX_UI_FONT_LARGE); | |
gui2->addTextInput("TEXT INPUT_1", "<empty>"); | |
ofAddListener(gui2->newGUIEvent,this,&testApp::guiEvent); | |
} | |
//-------------------------------------------------------------- | |
void testApp::exit() | |
{ | |
delete gui2; | |
} | |
//-------------------------------------------------------------- | |
void testApp::dragEvent(ofDragInfo info){ | |
if( info.files.size() > 0 ){ | |
dragPt = info.position; | |
//get the file path | |
ofxUITextInput *text1 = (ofxUITextInput *)gui2->getWidget("TEXT INPUT_1"); | |
ofxUIRectangle *rect2 = text1->getRect(); | |
if(rect2->inside(dragPt)){ | |
cout << "dropped inside" << endl; | |
text1->setTextString(info.files[0]); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment