1 #ifndef TERMOX_PAINTER_BRUSH_HPP
2 #define TERMOX_PAINTER_BRUSH_HPP
6 #include <termox/painter/color.hpp>
7 #include <termox/painter/trait.hpp>
15 Color background = Color::Background;
16 Color foreground = Color::Foreground;
17 Traits traits = Trait::None;
21 template <
typename... Items>
22 explicit constexpr
Brush(Items... items)
24 this->add_items(items...);
29 template <
typename Head,
typename... Tail>
30 void constexpr add_items(Head t, Tail... ts)
33 this->add_items(ts...);
35 void constexpr add_items() {}
38 void constexpr set_item(Background_color bg)
40 background = Color{bg.value};
44 void constexpr set_item(Foreground_color fg)
46 foreground = Color{fg.value};
50 void constexpr set_item(Trait t) { traits |= t; }
53 void constexpr set_item(Traits t) { traits |= t; }
58 auto constexpr operator|(Brush& b, Traits ts) -> Brush&
64 [[nodiscard]]
auto constexpr operator|(Brush
const& b, Traits ts) -> Brush
71 [[nodiscard]]
auto constexpr operator|(Brush&& b, Traits ts) -> Brush
77 auto constexpr operator|(Brush& b, Background_color c) -> Brush&
79 b.background = Color{c.value};
83 [[nodiscard]]
auto constexpr operator|(Brush
const& b, Background_color c)
87 copy.background = Color{c.value};
91 [[nodiscard]]
auto constexpr operator|(Brush&& b, Background_color c) -> Brush
93 b.background = Color{c.value};
97 auto constexpr operator|(Brush& b, Foreground_color c) -> Brush&
99 b.foreground = Color{c.value};
103 [[nodiscard]]
auto constexpr operator|(Brush
const& b, Foreground_color c)
107 copy.foreground = Color{c.value};
111 [[nodiscard]]
auto constexpr operator|(Brush&& b, Foreground_color c) -> Brush
113 b.foreground = Color{c.value};
120 [[nodiscard]]
auto constexpr operator==(Brush a, Brush b) ->
bool
122 return std::tie(a.traits, a.background, a.foreground) ==
123 std::tie(b.traits, b.background, b.foreground);
127 [[nodiscard]]
auto constexpr merge(Brush primary, Brush secondary) -> Brush
129 if (primary.background == Color::Background)
130 primary.background = secondary.background;
131 if (primary.foreground == Color::Foreground)
132 primary.foreground = secondary.foreground;
133 primary.traits |= secondary.traits;
Holds the look of any paintable object with Traits and Colors.
Definition: brush.hpp:13
constexpr Brush(Items... items)
Construct a Brush with given Traits and Colors.
Definition: brush.hpp:22
Color numbers [0 - 180] are valid.
Definition: color.hpp:16