Browse Source

Fix ofxSourcesEditor to work with ofxRadioList

master
Krisjanis Rijnieks 11 years ago
parent
commit
88d3b51bdf
  1. 55
      src/ofxSourcesEditor.cpp
  2. 6
      src/ofxSourcesEditor.h

55
src/ofxSourcesEditor.cpp

@ -28,9 +28,7 @@ void ofxSourcesEditor::unregisterAppEvents()
void ofxSourcesEditor::setup(ofEventArgs& args) void ofxSourcesEditor::setup(ofEventArgs& args)
{ {
gui = new ofxUICanvas(); gui = new ofxRadioList();
gui->disable();
gui->disableAppDrawCallback();
// read directory contents // read directory contents
ofDirectory imgDir; ofDirectory imgDir;
@ -44,11 +42,15 @@ void ofxSourcesEditor::setup(ofEventArgs& args)
vnames.push_back(imgDir.getName(i)); vnames.push_back(imgDir.getName(i));
} }
gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); gui->setup("Images", vnames);
ofxUIRadio *radio = gui->addRadio("images", vnames, OFX_UI_ORIENTATION_VERTICAL); ofAddListener(gui->radioSelectedEvent, this, &ofxSourcesEditor::guiEvent);
radio->activateToggle("image0.png");
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() void ofxSourcesEditor::draw()
@ -83,29 +85,14 @@ void ofxSourcesEditor::setSurfaceManager(ofxSurfaceManager *newSurfaceManager)
void ofxSourcesEditor::selectImageSourceRadioButton(string name) void ofxSourcesEditor::selectImageSourceRadioButton(string name)
{ {
vector<ofxUIWidget*> widgets = gui->getWidgets();
// find radio list item
ofxUIRadio* radio;
for ( int i=0; i<widgets.size(); i++ ) {
int widgetKind = widgets[i]->getKind();
if ( widgetKind == OFX_UI_WIDGET_RADIO ){
radio = (ofxUIRadio*)widgets[i];
break;
}
}
if (name == "none") { if (name == "none") {
ofxUIToggle* toggle = (ofxUIToggle*)radio->getActive(); gui->unselectAll();
if ( toggle != NULL ) {
toggle->setValue(false);
}
return; return;
} else { } else {
for ( int i=0; i<widgets.size(); i++ ) { int i;
string widgetName = widgets[i]->getName(); for (i = 0; i < gui->size(); i++) {
if ( name == widgetName ) { if (gui->getItemName(i) == name) {
radio->activateToggle(name); gui->selectItem(i);
return; return;
} }
} }
@ -126,24 +113,14 @@ ofTexture* ofxSourcesEditor::getTexture(int index)
return &images[index]->getTextureReference(); return &images[index]->getTextureReference();
} }
void ofxSourcesEditor::guiEvent(ofxUIEventArgs &e) void ofxSourcesEditor::guiEvent(string &imageName)
{ {
string name = e.widget->getName(); string name = imageName;
int kind = e.widget->getKind();
if(kind == OFX_UI_WIDGET_TOGGLE){
ofxUIToggle *toggle = (ofxUIToggle *) e.widget;
cout << name << "\t value: " << toggle->getValue() << endl;
}
if ( surfaceManager->getSelectedSurface() == NULL ) { if ( surfaceManager->getSelectedSurface() == NULL ) {
return; return;
} }
if (name == "images") {
return;
}
stringstream ss; stringstream ss;
ss << defImgDir << name; ss << defImgDir << name;
cout << "attempt to load image: " << ss.str() << endl; cout << "attempt to load image: " << ss.str() << endl;

6
src/ofxSourcesEditor.h

@ -3,8 +3,8 @@
#include "ofGraphics.h" #include "ofGraphics.h"
#include "ofEvents.h" #include "ofEvents.h"
#include "ofxUI.h"
#include "ofxSurfaceManager.h" #include "ofxSurfaceManager.h"
#include "ofxRadioList.h"
#define DEFAULT_IMAGES_DIR "sources/images/"; #define DEFAULT_IMAGES_DIR "sources/images/";
@ -30,9 +30,9 @@ public:
private: private:
ofxSurfaceManager* surfaceManager; ofxSurfaceManager* surfaceManager;
ofxRadioList* gui;
string defImgDir; string defImgDir;
ofxUICanvas *gui; void guiEvent(string &imageName);
void guiEvent(ofxUIEventArgs &e);
vector<ofImage*> images; vector<ofImage*> images;
vector<string> imageNames; vector<string> imageNames;
//ofxPanel imgSrcPanel; //ofxPanel imgSrcPanel;

Loading…
Cancel
Save