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);
}
// TODO Remove this
void SourcesEditor::setup(ofEventArgs& args) {
gui = new RadioList();
// 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
// Get image names from media server
vector<string> 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) {

2
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

24
src/ui/RadioList.cpp

@ -7,21 +7,22 @@ RadioList::RadioList() {
storedSelectedItem = 0;
}
RadioList::RadioList(vector<string>& labels) {
RadioList::RadioList(vector<string>& labels, vector<string>& values) {
RadioList();
setup(labels);
setup(labels, values);
}
RadioList::RadioList(string title, vector<string>& labels) {
RadioList::RadioList(string title, vector<string>& labels, vector<string>& values) {
RadioList();
setup(title, labels);
setup(title, labels, values);
}
RadioList::~RadioList() { clear(); }
void RadioList::setup(vector<string>& labels) {
void RadioList::setup(vector<string>& labels, vector<string>& 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<string>& labels) {
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
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 =

11
src/ui/RadioList.h

@ -10,12 +10,12 @@ namespace piMapper {
class RadioList {
public:
RadioList();
RadioList(vector<string> &labels);
RadioList(string title, vector<string> &labels);
RadioList(vector<string>& labels, vector<string>& values);
RadioList(string title, vector<string>& labels, vector<string>& values);
~RadioList();
void setup(vector<string> &labels);
void setup(string title, vector<string> &labels);
void setup(vector<string> &labels, vector<string>& values);
void setup(string title, vector<string>& labels, vector<string>& 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<string> radioSelectedEvent;
ofEvent<string> onRadioSelected;
private:
vector<string> storedLabels;
vector<string> storedValues;
string storedTitle;
ofxGuiGroup guiGroup;
int storedSelectedItem;

Loading…
Cancel
Save