Making a snapshot of the current parameter state
We will implement a simple but useful mechanism for saving and loading the parameters' states. The code used in the examples will be based on the previous recipes.
Getting ready
Let's say we have a variable that we are changing frequently. In this case, it will be the color of some element we are drawing and the main class will have the following member variable:
ColorA mColor;
How to do it...
We will use a built-in XML parser and the fileDrop
event handler.
We have to include the following additional headers:
#include "cinder/params/Params.h" #include "cinder/ImageIo.h" #include "cinder/Utilities.h" #include "cinder/Xml.h"
First, we implement two methods for loading and saving parameters:
void MainApp::loadParameters(std::string filename) { try { XmlTree doc( loadFile( fs::path(filename) ) ); XmlTree &generalNode = doc.getChild( "general" ); mColor.r = generalNode.getChild("ColorR").getValue<float>(); mColor.g...