polybar-dwm/include/drawtypes/animation.hpp

46 lines
1.1 KiB
C++
Raw Normal View History

#pragma once
2016-05-19 14:41:06 +00:00
2016-11-20 22:04:31 +00:00
#include <chrono>
2016-06-15 03:32:35 +00:00
#include "common.hpp"
#include "components/config.hpp"
#include "drawtypes/label.hpp"
#include "utils/mixins.hpp"
2016-05-19 14:41:06 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS
2016-05-19 14:41:06 +00:00
2016-11-20 22:04:31 +00:00
namespace chrono = std::chrono;
2016-06-15 03:32:35 +00:00
namespace drawtypes {
class animation : public non_copyable_mixin<animation> {
public:
explicit animation(int framerate_ms) : m_framerate_ms(framerate_ms) {}
explicit animation(vector<label_t>&& frames, int framerate_ms)
2016-06-15 03:32:35 +00:00
: m_frames(forward<decltype(frames)>(frames))
, m_framerate_ms(framerate_ms)
, m_framecount(m_frames.size())
, m_lastupdate(chrono::system_clock::now()) {}
2016-05-19 14:41:06 +00:00
void add(label_t&& frame);
label_t get();
2016-11-02 19:22:45 +00:00
int framerate();
operator bool();
2016-05-19 14:41:06 +00:00
2016-06-15 03:32:35 +00:00
protected:
2016-11-02 19:22:45 +00:00
void tick();
vector<label_t> m_frames;
2016-06-15 03:32:35 +00:00
int m_framerate_ms = 1000;
int m_frame = 0;
int m_framecount = 0;
chrono::system_clock::time_point m_lastupdate;
2016-05-19 14:41:06 +00:00
};
2016-10-25 05:10:03 +00:00
using animation_t = shared_ptr<animation>;
2016-11-25 12:55:15 +00:00
animation_t load_animation(
const config& conf, const string& section, string name = "animation", bool required = true);
2016-05-19 14:41:06 +00:00
}
2016-06-15 03:32:35 +00:00
2016-11-19 05:22:44 +00:00
POLYBAR_NS_END