Browse Source

Slide show XML loading

master
c-mendoza 8 years ago
parent
commit
8c283d96f4
  1. 10
      example/bin/data/ofxpimapper.xml
  2. 1
      example/src/magSlide.h
  3. 76
      example/src/magSlideShowSource.cpp
  4. 29
      example/src/magSlideShowSource.h
  5. 21
      example/src/ofApp.cpp

10
example/bin/data/ofxpimapper.xml

@ -78,4 +78,14 @@
<perspectiveWarping>1</perspectiveWarping> <perspectiveWarping>1</perspectiveWarping>
</properties> </properties>
</surface> </surface>
<magSlideShow>
<Width>1920</Width>
<Height>1080</Height>
<SlideDuration>0.5</SlideDuration> <!-- Optional default duration for each slide-->
<Loop>
<Type>PING-PONG</Type> <!-- NONE | NORMAL | PING-PONG -->
</Loop>
<!-- NoResize | Native | Fit | FitProportionally | FillProportionally -->
<ResizeOption>FitProportionally</ResizeOption>
</magSlideShow>
</surfaces> </surfaces>

1
example/src/magSlide.h

@ -50,7 +50,6 @@ public:
/** /**
* Resizes the largest dimension to the source's max, * Resizes the largest dimension to the source's max,
* the other dimension is resized proportionally. * the other dimension is resized proportionally.
* This is the default behavior.
*/ */
FitProportionally, FitProportionally,

76
example/src/magSlideShowSource.cpp

@ -6,8 +6,8 @@
#include "magSlideShowSource.h" #include "magSlideShowSource.h"
#include "magSlide.h"
#include "magSlideTransition.h" #include "magSlideTransition.h"
#include "SettingsLoader.h"
magSlideShowSource::magSlideShowSource() magSlideShowSource::magSlideShowSource()
{ {
@ -189,11 +189,79 @@ bool magSlideShowSource::createFromFolderContents(std::string path)
} }
} }
bool magSlideShowSource::loadFromXml()
bool magSlideShowSource::loadSlideShow(std::string slideShowXmlPath)
{ {
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<magSlide> slide) void magSlideShowSource::addSlide(std::shared_ptr<magSlide> slide)

29
example/src/magSlideShowSource.h

@ -35,7 +35,8 @@ public:
* otherwise. Check the console for the specific error. * otherwise. Check the console for the specific error.
*/ */
bool createFromFolderContents(std::string path); bool createFromFolderContents(std::string path);
bool loadSlideShow(std::string slideShowXmlPath);
bool loadFromXml();
void addSlide(std::shared_ptr<magSlide> slide); void addSlide(std::shared_ptr<magSlide> slide);
void play(); void play();
void pause(); void pause();
@ -43,7 +44,7 @@ public:
void playPrevSlide(); void playPrevSlide();
void playSlide(int slideIndex); void playSlide(int slideIndex);
enum LoopType enum LoopType : int
{ {
NONE = 0, NONE = 0,
NORMAL, NORMAL,
@ -53,14 +54,14 @@ public:
struct Settings 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. * An optional default slide duration, in seconds.
* If a slide specifies a duration this value is ignored. * If a slide specifies a duration this value is ignored.
@ -76,7 +77,7 @@ public:
* An optional default transition duration. If no transition * An optional default transition duration. If no transition
* is specified, this value is ignored; * is specified, this value is ignored;
*/ */
float transitionDuration = 1; float transitionDuration = 0;
/** /**
* If specified, all applicable files in the folder will * 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. * If path is relative, the root will likely be the Data folder.
*/ */
std::string slidesFolderPath; std::string slidesFolderPath = "sources/images";
/** /**
* If specified, * If specified,
@ -105,12 +106,12 @@ public:
*/ */
int numLoops = 0; int numLoops = 0;
/** /**
* The resizing option for the slide show. The default is None. If a slide * The resizing option for the slide show. The default is FitProportionally.
* already has a resizing option applied, that option will be respected and * If a slide already has a resizing option applied, that option will be
* this resizeOption will not be used. * respected and this resizeOption will not be used.
*/ */
magSlide::ResizeOptions resizeOption = magSlide::ResizeOptions::NoResize; magSlide::ResizeOptions resizeOption = magSlide::ResizeOptions::FitProportionally;
}; };
//////////////////////////////////////////// ////////////////////////////////////////////

21
example/src/ofApp.cpp

@ -19,17 +19,10 @@ void ofApp::setup(){
slideShowSource = new magSlideShowSource(); slideShowSource = new magSlideShowSource();
// Create the settings struct for the slide show. // 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. // Initialize the slide show with our settings.
slideShowSource->initialize(settings); // If it fails, initialize from default settings
// Register our sources: // Register our sources:
piMapper.registerFboSource(crossSource); piMapper.registerFboSource(crossSource);
@ -37,9 +30,17 @@ void ofApp::setup(){
piMapper.registerFboSource(slideShowSource); piMapper.registerFboSource(slideShowSource);
piMapper.setup(); 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 <i> to toggle // The info layer is hidden by default, press <i> to toggle
// piMapper.showInfo(); // piMapper.showInfo();
ofSetFullscreen(Settings::instance()->getFullscreen()); ofSetFullscreen(Settings::instance()->getFullscreen());
ofSetEscapeQuitsApp(false); ofSetEscapeQuitsApp(false);
ofSetLogLevel(OF_LOG_VERBOSE); ofSetLogLevel(OF_LOG_VERBOSE);

Loading…
Cancel
Save