diff --git a/example/bin/data/ofxpimapper.xml b/example/bin/data/ofxpimapper.xml
index 0f1d1ff..84bd5b4 100644
--- a/example/bin/data/ofxpimapper.xml
+++ b/example/bin/data/ofxpimapper.xml
@@ -78,4 +78,14 @@
1
+
+ 1920
+ 1080
+ 0.5
+
+ PING-PONG
+
+
+ FitProportionally
+
diff --git a/example/src/magSlide.h b/example/src/magSlide.h
index c1889cb..f216203 100644
--- a/example/src/magSlide.h
+++ b/example/src/magSlide.h
@@ -50,7 +50,6 @@ public:
/**
* Resizes the largest dimension to the source's max,
* the other dimension is resized proportionally.
- * This is the default behavior.
*/
FitProportionally,
diff --git a/example/src/magSlideShowSource.cpp b/example/src/magSlideShowSource.cpp
index 7c1d625..02f335e 100644
--- a/example/src/magSlideShowSource.cpp
+++ b/example/src/magSlideShowSource.cpp
@@ -6,8 +6,8 @@
#include "magSlideShowSource.h"
-#include "magSlide.h"
#include "magSlideTransition.h"
+#include "SettingsLoader.h"
magSlideShowSource::magSlideShowSource()
{
@@ -189,11 +189,79 @@ bool magSlideShowSource::createFromFolderContents(std::string path)
}
}
-
-bool magSlideShowSource::loadSlideShow(std::string slideShowXmlPath)
+bool magSlideShowSource::loadFromXml()
{
+ auto *loader = ofx::piMapper::SettingsLoader::instance();
+ auto xml = ofxXmlSettings();
+ Settings settings;
+
+ if (!xml.load(loader->getLastLoadedFilename()))
+ {
+ ofLogError("magSlideShowSource") << "Could not load settings file " << loader->getLastLoadedFilename();
+ return false;
+ }
+
+ xml.pushTag("surfaces");
+ if (!xml.pushTag("magSlideShow"))
+ {
+ ofLogError("magSlideShowSource") << "Slide show settings not found in " << loader->getLastLoadedFilename();
+ return false;
+ }
+
+ settings.width = xml.getValue("Width", settings.width);
+ settings.height = xml.getValue("Height", settings.height);
+
+ // Default slide duration:
+ settings.slideDuration = xml.getValue("SlideDuration", settings.slideDuration);
+
+ // Default loop:
+ if (xml.pushTag("Loop"))
+ {
+ auto type = xml.getValue("Type", "");
+ if (type == "NONE")
+ {
+ settings.loopType = LoopType::NONE;
+ }
+ else if (type == "NORMAL")
+ {
+ settings.loopType = LoopType::NORMAL;
+ }
+ else if (type == "PING-PONG")
+ {
+ settings.loopType = LoopType::PING_PONG;
+ }
+
+ settings.numLoops = xml.getValue("Count", settings.numLoops);
+ xml.popTag();
+ }
+
+ // Default resize options:
+ auto ropts = xml.getValue("ResizeOption", "");
+ if (ropts == "NoResize")
+ {
+ settings.resizeOption = magSlide::NoResize;
+ }
+ else if (ropts == "Native")
+ {
+ settings.resizeOption = magSlide::Native;
+ }
+ else if (ropts == "Fit")
+ {
+ settings.resizeOption = magSlide::Fit;
+ }
+ else if (ropts == "FitProportionally")
+ {
+ settings.resizeOption = magSlide::FitProportionally;
+ }
+ else if (ropts == "FillProportionally")
+ {
+ settings.resizeOption = magSlide::FillProportionally;
+ }
+
+ initialize(settings);
+
+ return true;
- return false;
}
void magSlideShowSource::addSlide(std::shared_ptr slide)
diff --git a/example/src/magSlideShowSource.h b/example/src/magSlideShowSource.h
index bfa6377..5284b23 100644
--- a/example/src/magSlideShowSource.h
+++ b/example/src/magSlideShowSource.h
@@ -35,7 +35,8 @@ public:
* otherwise. Check the console for the specific error.
*/
bool createFromFolderContents(std::string path);
- bool loadSlideShow(std::string slideShowXmlPath);
+
+ bool loadFromXml();
void addSlide(std::shared_ptr slide);
void play();
void pause();
@@ -43,7 +44,7 @@ public:
void playPrevSlide();
void playSlide(int slideIndex);
- enum LoopType
+ enum LoopType : int
{
NONE = 0,
NORMAL,
@@ -53,14 +54,14 @@ public:
struct Settings
{
/**
- * The pixel width of the FBO. This value must be provided.
+ * The pixel width of the FBO.
*/
- float width = 0;
+ float width = 1280;
/**
- * The pixel height of the FBO. This value must be provided.
+ * The pixel height of the FBO.
*/
- float height = 0;
+ float height = 720;
/**
* An optional default slide duration, in seconds.
* If a slide specifies a duration this value is ignored.
@@ -76,7 +77,7 @@ public:
* An optional default transition duration. If no transition
* is specified, this value is ignored;
*/
- float transitionDuration = 1;
+ float transitionDuration = 0;
/**
* If specified, all applicable files in the folder will
@@ -85,7 +86,7 @@ public:
*
* If path is relative, the root will likely be the Data folder.
*/
- std::string slidesFolderPath;
+ std::string slidesFolderPath = "sources/images";
/**
* If specified,
@@ -105,12 +106,12 @@ public:
*/
int numLoops = 0;
- /**
- * The resizing option for the slide show. The default is None. If a slide
- * already has a resizing option applied, that option will be respected and
- * this resizeOption will not be used.
- */
- magSlide::ResizeOptions resizeOption = magSlide::ResizeOptions::NoResize;
+ /**
+ * The resizing option for the slide show. The default is FitProportionally.
+ * If a slide already has a resizing option applied, that option will be
+ * respected and this resizeOption will not be used.
+ */
+ magSlide::ResizeOptions resizeOption = magSlide::ResizeOptions::FitProportionally;
};
////////////////////////////////////////////
diff --git a/example/src/ofApp.cpp b/example/src/ofApp.cpp
index 9c75f7b..e691269 100644
--- a/example/src/ofApp.cpp
+++ b/example/src/ofApp.cpp
@@ -19,17 +19,10 @@ void ofApp::setup(){
slideShowSource = new magSlideShowSource();
// Create the settings struct for the slide show.
- magSlideShowSource::Settings settings;
- settings.width = 1280;
- settings.height = 720;
- settings.slidesFolderPath = "sources/images";
- settings.transitionDuration = 0;
- settings.slideDuration = 0.5;
- settings.loopType = magSlideShowSource::LoopType::NORMAL;
- settings.resizeOption = magSlide::ResizeOptions::FitProportionally;
// Initialize the slide show with our settings.
- slideShowSource->initialize(settings);
+ // If it fails, initialize from default settings
+
// Register our sources:
piMapper.registerFboSource(crossSource);
@@ -37,9 +30,17 @@ void ofApp::setup(){
piMapper.registerFboSource(slideShowSource);
piMapper.setup();
+ // Slide show needs to be loaded after piMapper is set up:
+ if (!slideShowSource->loadFromXml())
+ {
+ ofLogNotice("setup") << "loading magSlideShowSource XML settings failed. Initializing from default values";
+ magSlideShowSource::Settings sets;
+ slideShowSource->initialize(sets);
+ }
+
// The info layer is hidden by default, press to toggle
// piMapper.showInfo();
-
+
ofSetFullscreen(Settings::instance()->getFullscreen());
ofSetEscapeQuitsApp(false);
ofSetLogLevel(OF_LOG_VERBOSE);