diff --git a/README.md b/README.md index 957fff9..909558b 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,8 @@ git clone https://github.com/kr15h/ofxPiMapper.git Dependencies ------------ -None so far. +ofxUI +ofxXmlSettings Compatibility ------------ diff --git a/src/ofxSourcesEditor.cpp b/src/ofxSourcesEditor.cpp index 9a33c87..7ba604b 100644 --- a/src/ofxSourcesEditor.cpp +++ b/src/ofxSourcesEditor.cpp @@ -2,15 +2,124 @@ ofxSourcesEditor::ofxSourcesEditor() { - + defImgDir = DEFAULT_IMAGES_DIR; + registerAppEvents(); } ofxSourcesEditor::~ofxSourcesEditor() { + unregisterAppEvents(); + delete gui; + while ( images.size() ) { + delete images.back(); + images.pop_back(); + } +} + +void ofxSourcesEditor::registerAppEvents() +{ + ofAddListener(ofEvents().setup, this, &ofxSourcesEditor::setup); +} + +void ofxSourcesEditor::unregisterAppEvents() +{ + ofRemoveListener(ofEvents().setup, this, &ofxSourcesEditor::setup); +} + +void ofxSourcesEditor::setup(ofEventArgs& args) +{ + gui = new ofxUICanvas(); + gui->disable(); + gui->disableAppDrawCallback(); + // read directory contents + ofDirectory imgDir; + imgDir.listDir(defImgDir); + imgDir.sort(); + + vector vnames; + + for(int i = 0; i < (int)imgDir.size(); i++){ + //images[i].loadImage(imgDir.getPath(i)); + vnames.push_back(imgDir.getName(i)); + } + + gui->addLabel(defImgDir, OFX_UI_FONT_SMALL); + ofxUIRadio *radio = gui->addRadio("VR", vnames, OFX_UI_ORIENTATION_VERTICAL); + radio->activateToggle("image0.png"); + + ofAddListener(gui->newGUIEvent,this,&ofxSourcesEditor::guiEvent); } void ofxSourcesEditor::draw() { - ofDrawBitmapString("Sources Editor", ofPoint(10, 20)); + gui->draw(); +} + +void ofxSourcesEditor::loadImage( string name, string path ) +{ + images.push_back(new ofImage()); + images.back()->loadImage(path); + + imageNames.push_back(name); + + ofSendMessage("imageLoaded"); +} + +void ofxSourcesEditor::disable() +{ + gui->disable(); +} + +void ofxSourcesEditor::enable() +{ + gui->enable(); +} + +int ofxSourcesEditor::getLoadedTexCount() +{ + return images.size(); +} + +ofTexture* ofxSourcesEditor::getTexture(int index) +{ + if (index >= images.size()){ + throw std::runtime_error("Texture index out of bounds."); + } + + return &images[index]->getTextureReference(); +} + +void ofxSourcesEditor::guiEvent(ofxUIEventArgs &e) +{ + string name = e.widget->getName(); + int kind = e.widget->getKind(); + + if(kind == OFX_UI_WIDGET_TOGGLE){ + ofxUIToggle *toggle = (ofxUIToggle *) e.widget; + cout << name << "\t value: " << toggle->getValue() << endl; + } + + // search for matching loaded image name + for ( int i=0; i images; + vector imageNames; + //ofxPanel imgSrcPanel; + //void onSourceSelect(bool& value); }; #endif \ No newline at end of file diff --git a/src/ofxSurfaceManager.h b/src/ofxSurfaceManager.h index 5f14354..e5ebca3 100644 --- a/src/ofxSurfaceManager.h +++ b/src/ofxSurfaceManager.h @@ -4,6 +4,7 @@ #include "ofxBaseSurface.h" #include "ofxTriangleSurface.h" #include "ofxSurfaceType.h" +#include "ofEvents.h" using namespace std; diff --git a/src/ofxSurfaceManagerGui.cpp b/src/ofxSurfaceManagerGui.cpp index 81a6c3c..766f55b 100644 --- a/src/ofxSurfaceManagerGui.cpp +++ b/src/ofxSurfaceManagerGui.cpp @@ -6,11 +6,13 @@ ofxSurfaceManagerGui::ofxSurfaceManagerGui() guiMode = ofxGuiMode::NONE; bDrag = false; registerMouseEvents(); + ofRegisterGetMessages(this); } ofxSurfaceManagerGui::~ofxSurfaceManagerGui() { unregisterMouseEvents(); + ofUnregisterGetMessages(this); surfaceManager = NULL; } @@ -68,6 +70,12 @@ void ofxSurfaceManagerGui::draw() projectionEditor.draw(); } else if ( guiMode == ofxGuiMode::SOURCE_SELECTION ) { + // draw projection surfaces first + surfaceManager->draw(); + + // highlight selected surface + drawSelectedSurfaceHighlight(); + sourcesEditor.draw(); } } @@ -173,8 +181,16 @@ void ofxSurfaceManagerGui::setMode(int newGuiMode) guiMode = newGuiMode; - // refresh texture editor surface reference - textureEditor.setSurface(surfaceManager->getSelectedSurface()); + if ( guiMode == ofxGuiMode::SOURCE_SELECTION ) { + sourcesEditor.enable(); + } else { + sourcesEditor.disable(); + } + + if ( guiMode == ofxGuiMode::TEXTURE_MAPPING ) { + // refresh texture editor surface reference + textureEditor.setSurface(surfaceManager->getSelectedSurface()); + } } void ofxSurfaceManagerGui::drawSelectedSurfaceHighlight() @@ -212,4 +228,17 @@ void ofxSurfaceManagerGui::startDrag() void ofxSurfaceManagerGui::stopDrag() { bDrag = false; +} + +void ofxSurfaceManagerGui::gotMessage(ofMessage& msg) +{ + cout << msg.message << endl; + + if ( msg.message == "imageLoaded" ) { + // assign texture to selected source + if (surfaceManager->getSelectedSurface() == NULL){ + return; + } + surfaceManager->getSelectedSurface()->setTexture( sourcesEditor.getTexture(sourcesEditor.getLoadedTexCount()-1) ); + } } \ No newline at end of file diff --git a/src/ofxSurfaceManagerGui.h b/src/ofxSurfaceManagerGui.h index 4b24f20..483255b 100644 --- a/src/ofxSurfaceManagerGui.h +++ b/src/ofxSurfaceManagerGui.h @@ -30,6 +30,7 @@ public: void drawSelectedSurfaceTextureHighlight(); void startDrag(); void stopDrag(); + void gotMessage(ofMessage& msg); private: ofxSurfaceManager* surfaceManager;