Skip to content

animation & frameset

qPCR4vir edited this page Apr 5, 2019 · 6 revisions

The class animation provides an easy way to display an animation or create an animated GUI.
Set the number of frames per second in the constructor animation (std::size_t fps=23) or with fps (std::size_t n), if have to play repeatedly looped (bool enable) and self the frames to play with push_back (frameset frms).
Set where to output (window wd, const nana::point &pos) and play(). Optionaly pause().

The class frameset holds the frames and frame builders. This class have reference semantics for efficiency.
Images (the frames) can be set directly with push_back (paint::image img) and using a builder function with: push_back (framebuilder fb, std::size_t length), where lenght is the number of frames to generate.
That builder function have the type:
using framebuilder = std::function< bool(std::size_t pos, paint::graphics &gr, nana::size &sz)>

Example: animate-bmp :octocat:

#include <nana/gui/wvl.hpp>
#include <nana/gui/animation.hpp>

int main()
{
    using namespace nana;
   
    //Build frames
    frameset fset;
    fset.push_back(nana::paint::image("../Examples/a_pic0.bmp"));
    fset.push_back(nana::paint::image("../Examples/a_pic1.bmp"));
    fset.push_back(nana::paint::image("../Examples/a_pic2.bmp"));

    //A widget to display animation.
    form fm;
    fm.show();

    animation ani;
    ani.push_back(fset);
    ani.output(fm, nana::point(5,5));
    ani.looped(true);
    ani.play();

    exec();
}
Clone this wiki locally