diff --git a/src/SourcesEditor.cpp b/src/SourcesEditor.cpp index d0628b9..3bf7b51 100644 --- a/src/SourcesEditor.cpp +++ b/src/SourcesEditor.cpp @@ -66,38 +66,21 @@ namespace piMapper { ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup); } - // TODO Remove this void SourcesEditor::setup(ofEventArgs& args) { gui = new RadioList(); - - // read directory contents - /* - ofDirectory imgDir; - imgDir.listDir(defImgDir); - imgDir.sort(); - - vector vnames; - - for (int i = 0; i < (int)imgDir.size(); i++) { - // images[i].loadImage(imgDir.getPath(i)); - vnames.push_back(imgDir.getName(i)); - } - */ - - // Get only image names from media server image paths + // Get image names from media server vector vnames = mediaServer->getImageNames(); - gui->setup("Images", vnames); + gui->setup("Images", vnames, mediaServer->getImagePaths()); gui->setPosition(20, 20); - ofAddListener(gui->radioSelectedEvent, this, &SourcesEditor::guiEvent); + // Add radio selected event listener so we can load sources + ofAddListener(gui->onRadioSelected, this, &SourcesEditor::handleRadioSelected); } - // void SourcesEditor::draw() { // Don't draw if there is no source selected if (surfaceManager->getSelectedSurface() == NULL) { return; } - gui->draw(); } @@ -204,19 +187,13 @@ namespace piMapper { ofRemoveListener(mediaServer->onImageUnloaded, this, &SourcesEditor::handleImageUnloaded); } - void SourcesEditor::guiEvent(string& imageName) { - string name = imageName; - + void SourcesEditor::handleRadioSelected(string& sourcePath) { if (surfaceManager->getSelectedSurface() == NULL) { return; } - stringstream ss; - ss << defImgDir << name; - cout << "attempt to load image: " << ss.str() << endl; - ofTexture* texture = surfaceManager->loadImageSource(name, ss.str()); - surfaceManager->getSelectedSurface()->setTexture(texture); - surfaceManager->manageMemory(); + cout << "Attempt to load image: " << sourcePath << endl; + mediaServer->loadImage(sourcePath); } void SourcesEditor::clearMediaServer() { @@ -254,6 +231,9 @@ namespace piMapper { // Test image unload // mediaServer->unloadImage(path); + + ofTexture* texture = mediaServer->getImageTexture(path); + surfaceManager->getSelectedSurface()->setTexture(texture); } void SourcesEditor::handleImageUnloaded(string& path) { diff --git a/src/SourcesEditor.h b/src/SourcesEditor.h index bc2b382..0e814ec 100644 --- a/src/SourcesEditor.h +++ b/src/SourcesEditor.h @@ -55,7 +55,7 @@ class SourcesEditor { void removeMediaServerListeners(); // Handles GUI event, whenever someone has clicked on a radio button - void guiEvent(string& imageName); + void handleRadioSelected(string& sourcePath); // Careful clearing of the media server, // clears only if the media server has been initialized locally diff --git a/src/ui/RadioList.cpp b/src/ui/RadioList.cpp index c280edc..b6ef444 100644 --- a/src/ui/RadioList.cpp +++ b/src/ui/RadioList.cpp @@ -7,21 +7,22 @@ RadioList::RadioList() { storedSelectedItem = 0; } -RadioList::RadioList(vector& labels) { +RadioList::RadioList(vector& labels, vector& values) { RadioList(); - setup(labels); + setup(labels, values); } -RadioList::RadioList(string title, vector& labels) { +RadioList::RadioList(string title, vector& labels, vector& values) { RadioList(); - setup(title, labels); + setup(title, labels, values); } RadioList::~RadioList() { clear(); } -void RadioList::setup(vector& labels) { +void RadioList::setup(vector& labels, vector& values) { // Copy incomming labels for later use storedLabels = labels; + storedValues = values; // Create toggles with labels from the labels arg int i; @@ -36,11 +37,11 @@ void RadioList::setup(vector& labels) { cout << "num items: " << guiGroup.getNumControls() << endl; } -void RadioList::setup(string title, vector& labels) { +void RadioList::setup(string title, vector& labels, vector& values) { // Store title for later use storedTitle = title; guiGroup.setName(title); - setup(labels); + setup(labels, values); } void RadioList::draw() { guiGroup.draw(); } @@ -65,9 +66,10 @@ void RadioList::selectItem(int index) { toggle->removeListener(this, &RadioList::onToggleClicked); *toggle = true; // Select the specific radio button toggle->addListener(this, &RadioList::onToggleClicked); - string name = toggle->getName(); - ofNotifyEvent(radioSelectedEvent, name, this); - + //string name = toggle->getName(); + // Throw event with value that is image path instead of name + string value = storedValues[index]; + ofNotifyEvent(onRadioSelected, value, this); storedSelectedItem = index; } @@ -77,7 +79,7 @@ void RadioList::enable() { } // Rebuild everyting - setup(storedTitle, storedLabels); + setup(storedTitle, storedLabels, storedValues); // Select the stored selected item without throwing an event ofxToggle* toggle = diff --git a/src/ui/RadioList.h b/src/ui/RadioList.h index 45b7327..2926f2a 100644 --- a/src/ui/RadioList.h +++ b/src/ui/RadioList.h @@ -10,12 +10,12 @@ namespace piMapper { class RadioList { public: RadioList(); - RadioList(vector &labels); - RadioList(string title, vector &labels); + RadioList(vector& labels, vector& values); + RadioList(string title, vector& labels, vector& values); ~RadioList(); - void setup(vector &labels); - void setup(string title, vector &labels); + void setup(vector &labels, vector& values); + void setup(string title, vector& labels, vector& values); void draw(); void setTitle(string title); void setPosition(ofPoint p); @@ -37,10 +37,11 @@ class RadioList { // Use ofAddListener(RadioListInstance.radioSelectedEvent, listenerClassPtr, // &listenerClass::listenerMethod) // to listen to this. Listner method void listenerMethod(string & radioName) - ofEvent radioSelectedEvent; + ofEvent onRadioSelected; private: vector storedLabels; + vector storedValues; string storedTitle; ofxGuiGroup guiGroup; int storedSelectedItem;