diff --git a/src/ofxSourcesEditor.cpp b/src/ofxSourcesEditor.cpp index 372f13d..34c9e07 100644 --- a/src/ofxSourcesEditor.cpp +++ b/src/ofxSourcesEditor.cpp @@ -28,9 +28,7 @@ void ofxSourcesEditor::unregisterAppEvents() void ofxSourcesEditor::setup(ofEventArgs& args) { - gui = new ofxUICanvas(); - gui->disable(); - gui->disableAppDrawCallback(); + gui = new ofxRadioList(); // read directory contents ofDirectory imgDir; @@ -44,11 +42,15 @@ void ofxSourcesEditor::setup(ofEventArgs& args) vnames.push_back(imgDir.getName(i)); } - gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); - ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL); - radio->activateToggle("image0.png"); + gui->setup("Images", vnames); + ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent); + - ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent); + //gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); + //ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL); + //radio->activateToggle("image0.png"); + + //ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent); } void ofxSourcesEditor::draw() @@ -83,29 +85,14 @@ void ofxSourcesEditor::setSurfaceManager(ofxSurfaceManager *newSurfaceManager) void ofxSourcesEditor::selectImageSourceRadioButton(string name) { - vector widgets = gui->getWidgets(); - - // find radio list item - ofxUIRadio* radio; - for ( int i=0; igetKind(); - if ( widgetKind == OFX_UI_WIDGET_RADIO ){ - radio = (ofxUIRadio*)widgets[i]; - break; - } - } - if (name == "none") { - ofxUIToggle* toggle = (ofxUIToggle*)radio->getActive(); - if ( toggle != NULL ) { - toggle->setValue(false); - } + gui->unselectAll(); return; } else { - for ( int i=0; igetName(); - if ( name == widgetName ) { - radio->activateToggle(name); + int i; + for (i = 0; i < gui->size(); i++) { + if (gui->getItemName(i) == name) { + gui->selectItem(i); return; } } @@ -126,24 +113,14 @@ ofTexture* ofxSourcesEditor::getTexture(int index) return &images[index]->getTextureReference(); } -void ofxSourcesEditor::guiEvent(ofxUIEventArgs &e) +void ofxSourcesEditor::guiEvent(string &imageName) { - string name = e.widget->getName(); - int kind = e.widget->getKind(); - - if(kind == OFX_UI_WIDGET_TOGGLE){ - ofxUIToggle *toggle = (ofxUIToggle *) e.widget; - cout << name << "\t value: " << toggle->getValue() << endl; - } + string name = imageName; if ( surfaceManager->getSelectedSurface() == NULL ) { return; } - if (name == "images") { - return; - } - stringstream ss; ss << defImgDir << name; cout << "attempt to load image: " << ss.str() << endl; diff --git a/src/ofxSourcesEditor.h b/src/ofxSourcesEditor.h index 7344e33..cab567e 100644 --- a/src/ofxSourcesEditor.h +++ b/src/ofxSourcesEditor.h @@ -3,8 +3,8 @@ #include "ofGraphics.h" #include "ofEvents.h" -#include "ofxUI.h" #include "ofxSurfaceManager.h" +#include "ofxRadioList.h" #define DEFAULT_IMAGES_DIR "sources/images/"; @@ -30,9 +30,9 @@ public: private: ofxSurfaceManager* surfaceManager; + ofxRadioList* gui; string defImgDir; - ofxUICanvas *gui; - void guiEvent(ofxUIEventArgs &e); + void guiEvent(string &imageName); vector images; vector imageNames; //ofxPanel imgSrcPanel;