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)
{
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<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") {
ofxUIToggle* toggle = (ofxUIToggle*)radio->getActive();
if ( toggle != NULL ) {
toggle->setValue(false);
}
gui->unselectAll();
return;
} else {
for ( int i=0; i<widgets.size(); i++ ) {
string widgetName = widgets[i]->getName();
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;

6
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<ofImage*> images;
vector<string> imageNames;
//ofxPanel imgSrcPanel;

Loading…
Cancel
Save