From 125f4f246c969568b4487a3405a1fc22da6946f3 Mon Sep 17 00:00:00 2001 From: Krisjanis Rijnieks Date: Tue, 13 May 2014 21:59:38 +0200 Subject: [PATCH] Add image source selection per surface --- src/ofxSourcesEditor.cpp | 31 +++++++++++++++++++++++++++++++ src/ofxSourcesEditor.h | 1 + src/ofxSurfaceManager.cpp | 16 ++++++++++++++++ src/ofxSurfaceManager.h | 1 + src/ofxSurfaceManagerGui.cpp | 2 ++ 5 files changed, 51 insertions(+) diff --git a/src/ofxSourcesEditor.cpp b/src/ofxSourcesEditor.cpp index 9c81f11..372f13d 100644 --- a/src/ofxSourcesEditor.cpp +++ b/src/ofxSourcesEditor.cpp @@ -81,6 +81,37 @@ void ofxSourcesEditor::setSurfaceManager(ofxSurfaceManager *newSurfaceManager) surfaceManager = newSurfaceManager; } +void ofxSourcesEditor::selectImageSourceRadioButton(string name) +{ + vector widgets = gui->getWidgets(); + + // find radio list item + ofxUIRadio* radio; + for ( int i=0; igetKind(); + 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; igetName(); + if ( name == widgetName ) { + radio->activateToggle(name); + return; + } + } + } +} + int ofxSourcesEditor::getLoadedTexCount() { return images.size(); diff --git a/src/ofxSourcesEditor.h b/src/ofxSourcesEditor.h index efdabc3..7344e33 100644 --- a/src/ofxSourcesEditor.h +++ b/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); diff --git a/src/ofxSurfaceManager.cpp b/src/ofxSurfaceManager.cpp index 60326d1..7d7a167 100644 --- a/src/ofxSurfaceManager.cpp +++ b/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; igetTextureReference()) { + return loadedImageSourceNames[i]; + } + } + + return "none"; +} + ofxBaseSurface* ofxSurfaceManager::getSurface(int index) { if ( index >= surfaces.size() ) { diff --git a/src/ofxSurfaceManager.h b/src/ofxSurfaceManager.h index 5e136f6..709d29e 100644 --- a/src/ofxSurfaceManager.h +++ b/src/ofxSurfaceManager.h @@ -27,6 +27,7 @@ public: ofxBaseSurface* getSelectedSurface(); void deselectSurface(); ofTexture* loadImageSource(string name, string path); + string getSelectedSurfaceSourceName(); private: diff --git a/src/ofxSurfaceManagerGui.cpp b/src/ofxSurfaceManagerGui.cpp index 5e99b19..d8023e0 100644 --- a/src/ofxSurfaceManagerGui.cpp +++ b/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(); }