TermOx
dynamic_color_engine.hpp
1 #ifndef TERMOX_TERMINAL_DYNAMIC_COLOR_ENGINE_HPP
2 #define TERMOX_TERMINAL_DYNAMIC_COLOR_ENGINE_HPP
3 #include <mutex>
4 #include <vector>
5 
6 #include <termox/common/lockable.hpp>
7 #include <termox/common/timer.hpp>
8 #include <termox/painter/color.hpp>
9 #include <termox/system/event_loop.hpp>
10 #include <termox/system/event_queue.hpp>
11 
12 namespace ox {
13 
15 class Dynamic_color_engine : private Lockable<std::mutex> {
16  public:
17  using Clock_t = Timer::Clock_t;
18  using Duration_t = Timer::Duration_t;
19  using Time_point = Timer::Time_point;
20 
21  struct Registered_data {
22  Color color;
23  Dynamic_color dynamic;
24  Time_point last_event_time;
25  };
26 
27  static auto constexpr default_interval = Duration_t{100};
28 
29  public:
31 
32  void register_color(Color color, Dynamic_color const& dynamic);
33 
35 
36  void unregister_color(Color color);
37 
39  void clear();
40 
42  [[nodiscard]] auto is_empty() const -> bool;
43 
45  void start();
46 
48  void stop();
49 
50  private:
51  std::vector<Registered_data> data_;
52  Event_loop loop_;
53  Timer timer_ = Timer{default_interval};
54 
55  private:
57  auto get_dynamic_color_event() -> Dynamic_color_event;
58 
60  void loop_function(Event_queue& queue);
61 };
62 
63 } // namespace ox
64 #endif // TERMOX_TERMINAL_DYNAMIC_COLOR_ENGINE_HPP
Color numbers [0 - 180] are valid.
Definition: color.hpp:16
Event loop that manages posting of Dynamic_color_events.
Definition: dynamic_color_engine.hpp:15
auto is_empty() const -> bool
Return true if there are no registered widgets.
Definition: dynamic_color_engine.cpp:38
void start()
Start another thread that waits on intervals and sents Events.
Definition: dynamic_color_engine.cpp:44
void stop()
Sends exit signal and waits for animation thread to exit.
Definition: dynamic_color_engine.cpp:49
void clear()
Remove all registered colors.
Definition: dynamic_color_engine.cpp:32
void register_color(Color color, Dynamic_color const &dynamic)
Add a dynamic color linked to color.
Definition: dynamic_color_engine.cpp:15
void unregister_color(Color color)
Removes the Dynamic_color linked to color.
Definition: dynamic_color_engine.cpp:22
Calls on loop_function(), and then processes the Event_queue.
Definition: event_loop.hpp:17
Definition: lockable.hpp:8
Timer class where begin() and wait() are used to block for a given interval.
Definition: timer.hpp:10
Definition: dynamic_color_engine.hpp:21
Defines an animated color.
Definition: color.hpp:105