Browse Source

Add image source selection per surface

master
Krisjanis Rijnieks 11 years ago
parent
commit
125f4f246c
  1. 31
      src/ofxSourcesEditor.cpp
  2. 1
      src/ofxSourcesEditor.h
  3. 16
      src/ofxSurfaceManager.cpp
  4. 1
      src/ofxSurfaceManager.h
  5. 2
      src/ofxSurfaceManagerGui.cpp

31
src/ofxSourcesEditor.cpp

@ -81,6 +81,37 @@ void ofxSourcesEditor::setSurfaceManager(ofxSurfaceManager *newSurfaceManager)
surfaceManager = newSurfaceManager;
}
void ofxSourcesEditor::selectImageSourceRadioButton(string name)
{
vector<ofxUIWidget*> widgets = gui->getWidgets();
// find radio list item
ofxUIRadio* radio;
for ( int i=0; i<widgets.size(); i++ ) {
int widgetKind = widgets[i]->getKind();
if ( widgetKind == OFX_UI_WIDGET_RADIO ){
radio = (ofxUIRadio*)widgets[i];
break;
}
}
if (name == "none") {
ofxUIToggle* toggle = (ofxUIToggle*)radio->getActive();
if ( toggle != NULL ) {
toggle->setValue(false);
}
return;
} else {
for ( int i=0; i<widgets.size(); i++ ) {
string widgetName = widgets[i]->getName();
if ( name == widgetName ) {
radio->activateToggle(name);
return;
}
}
}
}
int ofxSourcesEditor::getLoadedTexCount()
{
return images.size();

1
src/ofxSourcesEditor.h

@ -23,6 +23,7 @@ public:
void disable();
void enable();
void setSurfaceManager(ofxSurfaceManager* newSurfaceManager);
void selectImageSourceRadioButton(string name);
int getLoadedTexCount();
ofTexture* getTexture(int index);

16
src/ofxSurfaceManager.cpp

@ -161,6 +161,22 @@ ofTexture* ofxSurfaceManager::loadImageSource(string name, string path)
return &image->getTextureReference();
}
string ofxSurfaceManager::getSelectedSurfaceSourceName()
{
if ( selectedSurface == NULL ) {
return "none";
}
ofTexture* tex = selectedSurface->getTexture();
for ( int i=0; i<loadedImageSources.size(); i++ ) {
if (tex == &loadedImageSources[i]->getTextureReference()) {
return loadedImageSourceNames[i];
}
}
return "none";
}
ofxBaseSurface* ofxSurfaceManager::getSurface(int index)
{
if ( index >= surfaces.size() ) {

1
src/ofxSurfaceManager.h

@ -27,6 +27,7 @@ public:
ofxBaseSurface* getSelectedSurface();
void deselectSurface();
ofTexture* loadImageSource(string name, string path);
string getSelectedSurfaceSourceName();
private:

2
src/ofxSurfaceManagerGui.cpp

@ -182,6 +182,8 @@ void ofxSurfaceManagerGui::setMode(int newGuiMode)
if ( guiMode == ofxGuiMode::SOURCE_SELECTION ) {
sourcesEditor.enable();
string sourceName = surfaceManager->getSelectedSurfaceSourceName();
sourcesEditor.selectImageSourceRadioButton(sourceName);
} else {
sourcesEditor.disable();
}

Loading…
Cancel
Save