Browse Source

Add load images using media server and change radio selected events and handlers to be more consistant

master
Krisjanis Rijnieks 11 years ago
parent
commit
29da680512
  1. 40
      src/SourcesEditor.cpp
  2. 2
      src/SourcesEditor.h
  3. 24
      src/ui/RadioList.cpp
  4. 11
      src/ui/RadioList.h

40
src/SourcesEditor.cpp

@ -66,38 +66,21 @@ namespace piMapper {
ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup); ofRemoveListener(ofEvents().setup, this, &SourcesEditor::setup);
} }
// TODO Remove this
void SourcesEditor::setup(ofEventArgs& args) { void SourcesEditor::setup(ofEventArgs& args) {
gui = new RadioList(); gui = new RadioList();
// Get image names from media server
// read directory contents
/*
ofDirectory imgDir;
imgDir.listDir(defImgDir);
imgDir.sort();
vector<string> 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
vector<string> vnames = mediaServer->getImageNames(); vector<string> vnames = mediaServer->getImageNames();
gui->setup("Images", vnames); gui->setup("Images", vnames, mediaServer->getImagePaths());
gui->setPosition(20, 20); 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() { void SourcesEditor::draw() {
// Don't draw if there is no source selected // Don't draw if there is no source selected
if (surfaceManager->getSelectedSurface() == NULL) { if (surfaceManager->getSelectedSurface() == NULL) {
return; return;
} }
gui->draw(); gui->draw();
} }
@ -204,19 +187,13 @@ namespace piMapper {
ofRemoveListener(mediaServer->onImageUnloaded, this, &SourcesEditor::handleImageUnloaded); ofRemoveListener(mediaServer->onImageUnloaded, this, &SourcesEditor::handleImageUnloaded);
} }
void SourcesEditor::guiEvent(string& imageName) { void SourcesEditor::handleRadioSelected(string& sourcePath) {
string name = imageName;
if (surfaceManager->getSelectedSurface() == NULL) { if (surfaceManager->getSelectedSurface() == NULL) {
return; return;
} }
stringstream ss; cout << "Attempt to load image: " << sourcePath << endl;
ss << defImgDir << name; mediaServer->loadImage(sourcePath);
cout << "attempt to load image: " << ss.str() << endl;
ofTexture* texture = surfaceManager->loadImageSource(name, ss.str());
surfaceManager->getSelectedSurface()->setTexture(texture);
surfaceManager->manageMemory();
} }
void SourcesEditor::clearMediaServer() { void SourcesEditor::clearMediaServer() {
@ -254,6 +231,9 @@ namespace piMapper {
// Test image unload // Test image unload
// mediaServer->unloadImage(path); // mediaServer->unloadImage(path);
ofTexture* texture = mediaServer->getImageTexture(path);
surfaceManager->getSelectedSurface()->setTexture(texture);
} }
void SourcesEditor::handleImageUnloaded(string& path) { void SourcesEditor::handleImageUnloaded(string& path) {

2
src/SourcesEditor.h

@ -55,7 +55,7 @@ class SourcesEditor {
void removeMediaServerListeners(); void removeMediaServerListeners();
// Handles GUI event, whenever someone has clicked on a radio button // 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, // Careful clearing of the media server,
// clears only if the media server has been initialized locally // clears only if the media server has been initialized locally

24
src/ui/RadioList.cpp

@ -7,21 +7,22 @@ RadioList::RadioList() {
storedSelectedItem = 0; storedSelectedItem = 0;
} }
RadioList::RadioList(vector<string>& labels) { RadioList::RadioList(vector<string>& labels, vector<string>& values) {
RadioList(); RadioList();
setup(labels); setup(labels, values);
} }
RadioList::RadioList(string title, vector<string>& labels) { RadioList::RadioList(string title, vector<string>& labels, vector<string>& values) {
RadioList(); RadioList();
setup(title, labels); setup(title, labels, values);
} }
RadioList::~RadioList() { clear(); } RadioList::~RadioList() { clear(); }
void RadioList::setup(vector<string>& labels) { void RadioList::setup(vector<string>& labels, vector<string>& values) {
// Copy incomming labels for later use // Copy incomming labels for later use
storedLabels = labels; storedLabels = labels;
storedValues = values;
// Create toggles with labels from the labels arg // Create toggles with labels from the labels arg
int i; int i;
@ -36,11 +37,11 @@ void RadioList::setup(vector<string>& labels) {
cout << "num items: " << guiGroup.getNumControls() << endl; cout << "num items: " << guiGroup.getNumControls() << endl;
} }
void RadioList::setup(string title, vector<string>& labels) { void RadioList::setup(string title, vector<string>& labels, vector<string>& values) {
// Store title for later use // Store title for later use
storedTitle = title; storedTitle = title;
guiGroup.setName(title); guiGroup.setName(title);
setup(labels); setup(labels, values);
} }
void RadioList::draw() { guiGroup.draw(); } void RadioList::draw() { guiGroup.draw(); }
@ -65,9 +66,10 @@ void RadioList::selectItem(int index) {
toggle->removeListener(this, &RadioList::onToggleClicked); toggle->removeListener(this, &RadioList::onToggleClicked);
*toggle = true; // Select the specific radio button *toggle = true; // Select the specific radio button
toggle->addListener(this, &RadioList::onToggleClicked); toggle->addListener(this, &RadioList::onToggleClicked);
string name = toggle->getName(); //string name = toggle->getName();
ofNotifyEvent(radioSelectedEvent, name, this); // Throw event with value that is image path instead of name
string value = storedValues[index];
ofNotifyEvent(onRadioSelected, value, this);
storedSelectedItem = index; storedSelectedItem = index;
} }
@ -77,7 +79,7 @@ void RadioList::enable() {
} }
// Rebuild everyting // Rebuild everyting
setup(storedTitle, storedLabels); setup(storedTitle, storedLabels, storedValues);
// Select the stored selected item without throwing an event // Select the stored selected item without throwing an event
ofxToggle* toggle = ofxToggle* toggle =

11
src/ui/RadioList.h

@ -10,12 +10,12 @@ namespace piMapper {
class RadioList { class RadioList {
public: public:
RadioList(); RadioList();
RadioList(vector<string> &labels); RadioList(vector<string>& labels, vector<string>& values);
RadioList(string title, vector<string> &labels); RadioList(string title, vector<string>& labels, vector<string>& values);
~RadioList(); ~RadioList();
void setup(vector<string> &labels); void setup(vector<string> &labels, vector<string>& values);
void setup(string title, vector<string> &labels); void setup(string title, vector<string>& labels, vector<string>& values);
void draw(); void draw();
void setTitle(string title); void setTitle(string title);
void setPosition(ofPoint p); void setPosition(ofPoint p);
@ -37,10 +37,11 @@ class RadioList {
// Use ofAddListener(RadioListInstance.radioSelectedEvent, listenerClassPtr, // Use ofAddListener(RadioListInstance.radioSelectedEvent, listenerClassPtr,
// &listenerClass::listenerMethod) // &listenerClass::listenerMethod)
// to listen to this. Listner method void listenerMethod(string & radioName) // to listen to this. Listner method void listenerMethod(string & radioName)
ofEvent<string> radioSelectedEvent; ofEvent<string> onRadioSelected;
private: private:
vector<string> storedLabels; vector<string> storedLabels;
vector<string> storedValues;
string storedTitle; string storedTitle;
ofxGuiGroup guiGroup; ofxGuiGroup guiGroup;
int storedSelectedItem; int storedSelectedItem;

Loading…
Cancel
Save