Browse Source

Show and hide source selection radio buttons depending on whether they contain sources or not

master
Krisjanis Rijnieks 11 years ago
parent
commit
3159a4779d
  1. 4
      src/Sources/ImageSource.cpp
  2. 81
      src/SourcesEditor.cpp
  3. 2
      src/ui/RadioList.cpp

4
src/Sources/ImageSource.cpp

@ -18,8 +18,8 @@ namespace ofx {
//cout << "path: " << path << endl; //cout << "path: " << path << endl;
image = new ofImage(); image = new ofImage();
if (!image->loadImage(filePath)) { if (!image->loadImage(filePath)) {
ofLogFatalError("ImageSource") << "Could not load image"; ofLogWarning("ImageSource") << "Could not load image";
std::exit(EXIT_FAILURE); //std::exit(EXIT_FAILURE);
} }
texture = &image->getTextureReference(); texture = &image->getTextureReference();
loaded = true; loaded = true;

81
src/SourcesEditor.cpp

@ -38,15 +38,35 @@ namespace piMapper {
void SourcesEditor::setup(ofEventArgs& args) { void SourcesEditor::setup(ofEventArgs& args) {
imageSelector = new RadioList(); imageSelector = new RadioList();
videoSelector = new RadioList(); videoSelector = new RadioList();
// Get image names from media server
vector<string> imageNames = mediaServer->getImageNames(); // Get media count
imageSelector->setup("Images", imageNames, mediaServer->getImagePaths()); int numImages = mediaServer->getNumImages();
imageSelector->setPosition(20, 20); int numVideos = mediaServer->getNumVideos();
ofAddListener(imageSelector->onRadioSelected, this, &SourcesEditor::handleImageSelected);
vector<string> videoNames = mediaServer->getVideoNames(); // Depending on media count, decide what to load and initialize
videoSelector->setup("Videos", videoNames, mediaServer->getVideoPaths()); if (numImages) {
videoSelector->setPosition(250, 20); // Get image names from media server
ofAddListener(videoSelector->onRadioSelected, this, &SourcesEditor::handleVideoSelected); vector<string> imageNames = mediaServer->getImageNames();
imageSelector->setup("Images", imageNames, mediaServer->getImagePaths());
ofAddListener(imageSelector->onRadioSelected, this, &SourcesEditor::handleImageSelected);
}
if (numVideos) {
vector<string> videoNames = mediaServer->getVideoNames();
videoSelector->setup("Videos", videoNames, mediaServer->getVideoPaths());
ofAddListener(videoSelector->onRadioSelected, this, &SourcesEditor::handleVideoSelected);
}
if (numImages) {
imageSelector->setPosition(20, 20);
if (numVideos) {
videoSelector->setPosition(250, 20);
}
} else {
if (numVideos) {
videoSelector->setPosition(20, 20);
}
}
} }
void SourcesEditor::draw() { void SourcesEditor::draw() {
@ -55,13 +75,22 @@ namespace piMapper {
ofLogNotice("SourcesEditor") << "No surface selected"; ofLogNotice("SourcesEditor") << "No surface selected";
return; return;
} }
imageSelector->draw(); if (imageSelector->size()) {
videoSelector->draw(); imageSelector->draw();
}
if (videoSelector->size()) {
videoSelector->draw();
}
} }
void SourcesEditor::disable() { void SourcesEditor::disable() {
imageSelector->disable(); if (imageSelector->size()) {
videoSelector->disable(); imageSelector->disable();
}
if (videoSelector->size()) {
videoSelector->disable();
}
} }
void SourcesEditor::enable() { void SourcesEditor::enable() {
@ -70,8 +99,12 @@ namespace piMapper {
ofLogNotice("SourcesEditor") << "No surface selected. Not enabling and not showing source list."; ofLogNotice("SourcesEditor") << "No surface selected. Not enabling and not showing source list.";
return; return;
} }
imageSelector->enable(); if (imageSelector->size()) {
videoSelector->enable(); imageSelector->enable();
}
if (videoSelector->size()) {
videoSelector->enable();
}
BaseSource* source = surfaceManager->getSelectedSurface()->getSource(); BaseSource* source = surfaceManager->getSelectedSurface()->getSource();
selectSourceRadioButton(source->getPath()); selectSourceRadioButton(source->getPath());
} }
@ -98,13 +131,23 @@ namespace piMapper {
void SourcesEditor::selectSourceRadioButton(std::string& sourcePath) { void SourcesEditor::selectSourceRadioButton(std::string& sourcePath) {
if (sourcePath == "") { if (sourcePath == "") {
ofLogNotice("SourcesEditor") << "Path is empty"; ofLogNotice("SourcesEditor") << "Path is empty";
imageSelector->unselectAll(); if (imageSelector->size()) {
videoSelector->unselectAll(); imageSelector->unselectAll();
}
if (videoSelector->size()) {
videoSelector->unselectAll();
}
return; return;
} else { } else {
// Check image selector first // Check image selector first
bool imageRadioSelected = imageSelector->selectItemByValue(sourcePath); bool imageRadioSelected = false;
bool videoRadioSelected = videoSelector->selectItemByValue(sourcePath); bool videoRadioSelected = false;
if (imageSelector->size()) {
imageRadioSelected = imageSelector->selectItemByValue(sourcePath);
}
if (videoSelector->size()) {
videoRadioSelected = videoSelector->selectItemByValue(sourcePath);
}
if (imageRadioSelected || videoRadioSelected) { if (imageRadioSelected || videoRadioSelected) {
return; return;
} }

2
src/ui/RadioList.cpp

@ -159,7 +159,7 @@ string RadioList::getItemName(int index) {
return toggle->getName(); return toggle->getName();
} }
int RadioList::size() { return guiGroup.getNumControls(); } int RadioList::size() { return storedValues.size(); }
void RadioList::onToggleClicked(bool& toggleValue) { void RadioList::onToggleClicked(bool& toggleValue) {
unselectAll(); unselectAll();

Loading…
Cancel
Save