diff options
| author | Tim Redfern <tim@eclectronics.org> | 2012-01-09 16:36:57 +0000 |
|---|---|---|
| committer | Tim Redfern <tim@eclectronics.org> | 2012-01-09 16:36:57 +0000 |
| commit | 7ff3ebe50cd272176daff0de4aee32c1dc0f3320 (patch) | |
| tree | 0dbebbef6fe8688bf9ac98f415b542b1e100bda6 /src/testApp.cpp | |
| parent | c63227ab08ef1caa5efe957d6f9472387c9481ae (diff) | |
xmlising settings
Diffstat (limited to 'src/testApp.cpp')
| -rw-r--r-- | src/testApp.cpp | 69 |
1 files changed, 58 insertions, 11 deletions
diff --git a/src/testApp.cpp b/src/testApp.cpp index 2094c34..b93f4be 100644 --- a/src/testApp.cpp +++ b/src/testApp.cpp @@ -1,10 +1,13 @@ #include "testApp.h" - +//-------------------------------------------------------------- +testApp::~testApp(){ + saveSettings(); +} //-------------------------------------------------------------- void testApp::setup(){ + ofBackground(0,0,0); - ///ofSetVerticalSync(true); //some model / light stuff @@ -12,7 +15,7 @@ void testApp::setup(){ glShadeModel (GL_SMOOTH); glColorMaterial (GL_FRONT_AND_BACK, GL_DIFFUSE); glEnable (GL_COLOR_MATERIAL); - + //load the bottle model - the 3ds and the texture file need to be in the same folder bottle.loadModel("bottle.3DS", 1); bottle.setRotation(0, 180, 1, 0, 0); @@ -25,13 +28,7 @@ void testApp::setup(){ mode=CALIBRATE; - views=new viewpoint[2]; - - //todo: read this from xml - numViews=2; - views[0].setup(ofGetWidth()/2,ofGetHeight(),0,0); - views[1].setup(ofGetWidth()/2,ofGetHeight(),ofGetWidth()/2,0); - activeView=0; + loadSettings(); } //-------------------------------------------------------------- @@ -95,11 +92,61 @@ void testApp::keyPressed(int key){ case '3': activeView=1; break; - + } } +void testApp::loadSettings(){ + //viewport settings are float/ normalised to 0..1 + if( !XML.loadFile("settings.xml") ){ + printf("unable to load settings.xml check data/ folder\n"); + }else{ + if(XML.pushTag("map4")) { + numViews=XML.getNumTags("view"); + if(numViews) { + views=new viewpoint[numViews]; + for (int i=0;i<numViews;i++){ + XML.pushTag("view",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + map<string,string>settings; + for (int k=0;k<keys.size();k++) { + settings[keys[k]]=XML.getAttribute("settings",keys[k],"none",0); + } + views[i].setup(settings); + XML.popTag(); + } + } + XML.popTag(); + } + } + //numViews=2; + //views[0].setup(ofGetWidth()/2,ofGetHeight(),0,0); + //views[1].setup(ofGetWidth()/2,ofGetHeight(),ofGetWidth()/2,0); + //activeView=0; +} +//-------------------------------------------------------------- +void testApp::saveSettings(){ + //either re-navigate the whole thing OR + //save the number to the vp OR + //send a pointer to the vp + + //renavigate? easiest way to get the settings back out + if(XML.pushTag("map4")) { + for (int i=0;i<numViews;i++){ + XML.pushTag("view",i); + vector<string>keys; + XML.getAttributeNames("settings", keys, 0); + for (int k=0;k<keys.size();k++) { + XML.setAttribute("settings", keys[k], views[i].getSetting(keys[k]),0); + } + XML.popTag(); + } + XML.popTag(); + } + XML.saveFile("settings.xml"); +} //-------------------------------------------------------------- void testApp::keyReleased(int key){ if (activeView<0) for (int i=0;i<numViews;i++) views[i].keyReleased(key); |
