2016-11-02 19:22:45 +00:00
|
|
|
#include "drawtypes/animation.hpp"
|
|
|
|
#include "drawtypes/label.hpp"
|
2016-12-09 08:02:47 +00:00
|
|
|
#include "utils/factory.hpp"
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS
|
2016-11-02 19:22:45 +00:00
|
|
|
|
|
|
|
namespace drawtypes {
|
2018-12-23 21:59:10 +00:00
|
|
|
void animation::add(label_t&& frame) {
|
2016-11-02 19:22:45 +00:00
|
|
|
m_frames.emplace_back(forward<decltype(frame)>(frame));
|
|
|
|
m_framecount = m_frames.size();
|
2019-03-09 05:14:39 +00:00
|
|
|
m_frame = m_framecount - 1;
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
2019-03-09 05:14:39 +00:00
|
|
|
label_t animation::get() const {
|
2016-11-02 19:22:45 +00:00
|
|
|
return m_frames[m_frame];
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:14:39 +00:00
|
|
|
unsigned int animation::framerate() const {
|
2016-11-02 19:22:45 +00:00
|
|
|
return m_framerate_ms;
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:14:39 +00:00
|
|
|
animation::operator bool() const {
|
2016-11-02 19:22:45 +00:00
|
|
|
return !m_frames.empty();
|
|
|
|
}
|
|
|
|
|
2019-03-09 05:14:39 +00:00
|
|
|
void animation::increment() {
|
|
|
|
auto tmp = m_frame.load();
|
|
|
|
++tmp;
|
|
|
|
tmp %= m_framecount;
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2019-03-09 05:14:39 +00:00
|
|
|
m_frame = tmp;
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Create an animation by loading values
|
|
|
|
* from the configuration
|
|
|
|
*/
|
2016-11-25 12:55:15 +00:00
|
|
|
animation_t load_animation(const config& conf, const string& section, string name, bool required) {
|
2018-12-23 21:59:10 +00:00
|
|
|
vector<label_t> vec;
|
2016-11-02 19:22:45 +00:00
|
|
|
vector<string> frames;
|
|
|
|
|
2016-12-14 05:51:07 +00:00
|
|
|
name = string_util::ltrim(string_util::rtrim(move(name), '>'), '<');
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2018-12-23 21:59:10 +00:00
|
|
|
auto anim_defaults = load_optional_label(conf, section, name);
|
2016-11-19 11:23:31 +00:00
|
|
|
|
2016-11-25 12:55:15 +00:00
|
|
|
if (required) {
|
2016-12-30 22:32:05 +00:00
|
|
|
frames = conf.get_list(section, name);
|
2016-11-25 12:55:15 +00:00
|
|
|
} else {
|
2016-12-30 22:32:05 +00:00
|
|
|
frames = conf.get_list(section, name, {});
|
2016-11-25 12:55:15 +00:00
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-19 11:23:31 +00:00
|
|
|
for (size_t i = 0; i < frames.size(); i++) {
|
2018-12-23 21:59:10 +00:00
|
|
|
vec.emplace_back(forward<label_t>(load_optional_label(conf, section, name + "-" + to_string(i), frames[i])));
|
2016-11-19 11:23:31 +00:00
|
|
|
vec.back()->copy_undefined(anim_defaults);
|
|
|
|
}
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-12-30 22:32:05 +00:00
|
|
|
auto framerate = conf.get(section, name + "-framerate", 1000);
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
return factory_util::shared<animation>(move(vec), framerate);
|
2016-11-02 19:22:45 +00:00
|
|
|
}
|
2019-03-09 05:14:39 +00:00
|
|
|
} // namespace drawtypes
|
2016-11-02 19:22:45 +00:00
|
|
|
|
2016-11-19 05:22:44 +00:00
|
|
|
POLYBAR_NS_END
|