Browse Source

Build gui from image names got from media server

master
Krisjanis Rijnieks 11 years ago
parent
commit
3093a23471
  1. 29
      src/MediaServer/MediaServer.cpp
  2. 2
      src/MediaServer/MediaServer.h
  3. 6
      src/SourcesEditor.cpp

29
src/MediaServer/MediaServer.cpp

@ -31,6 +31,18 @@ namespace piMapper {
return videoWatcher.getFilePaths();
}
std::vector<std::string> MediaServer::getImageNames() {
std::vector<std::string> imageNames;
for (int i = 0; i < getNumImages(); i++) {
// Split image path
std::vector<std::string> pathParts = ofSplitString(getImagePaths()[i], "/");
// And get only the last piece
std::string name = pathParts[pathParts.size()-1];
imageNames.push_back(name);
}
return imageNames;
}
void MediaServer::loadImage(string& path) {
// Load image and add to vector if loading success
ofImage image;
@ -56,6 +68,23 @@ namespace piMapper {
}
}
ofTexture* MediaServer::getImageTexture(string &path) {
// Find image index by path
for (int i = 0; i < loadedImagePaths.size(); i++) {
if (path == loadedImagePaths[i]) {
if (loadedImages[i].isAllocated()) {
return &loadedImages[i].getTextureReference();
}
}
}
// If we havent returned yet, that means that there is no image
// and we need to sort this out somehow
ofLogError("MediaServer::getImageTexture", "Image not found");
return NULL;
}
void MediaServer::handleImageAdded(string& path) {
/*
cout << "onImageAdded: " << path << endl;

2
src/MediaServer/MediaServer.h

@ -26,10 +26,12 @@ class MediaServer {
int getNumImages();
std::vector<string>& getVideoPaths();
std::vector<string>& getImagePaths();
std::vector<string> getImageNames();
// Image loading and handling
void loadImage(string& path);
void unloadImage(string& path);
ofTexture* getImageTexture(string& path);
// Custom events
ofEvent<string> onImageAdded;

6
src/SourcesEditor.cpp

@ -71,6 +71,7 @@ namespace piMapper {
gui = new RadioList();
// read directory contents
/*
ofDirectory imgDir;
imgDir.listDir(defImgDir);
imgDir.sort();
@ -81,7 +82,10 @@ namespace piMapper {
// 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();
gui->setup("Images", vnames);
gui->setPosition(20, 20);
ofAddListener(gui->radioSelectedEvent, this, &SourcesEditor::guiEvent);

Loading…
Cancel
Save