1 #include "all_colors_display.hpp"
2 
3 #include <cppurses/painter/color.hpp>
4 #include <cppurses/painter/glyph.hpp>
5 #include <cppurses/painter/painter.hpp>
6 
7 namespace palette {
8 
Shade_display(cppurses::Color base)9 Shade_display::Shade_display(cppurses::Color base) : base_{base} {}
10 
invert()11 void Shade_display::invert() {
12     inverted_ = true;
13 }
14 
paint_event()15 bool Shade_display::paint_event() {
16     using namespace cppurses;
17     Glyph light_shade{L'░', background(base_)};
18     Glyph mid_shade{L'▒', background(base_)};
19     const auto color_n = 16;
20 
21     const int height = static_cast<int>(this->height());
22     const int width = static_cast<int>(this->width());
23 
24     int y_begin = inverted_ ? 0 : height - 1;
25     auto y_end = [this, height](int y) {
26         return inverted_ ? y < height : y >= 0;
27     };
28     auto increment = [this](int& y) { inverted_ ? ++y : --y; };
29 
30     Painter p{*this};
31     auto& shade = light_shade;
32     for (auto y = y_begin, i = 0; y_end(y); increment(y)) {
33         for (auto x = 0; x < width && i < (2 * color_n); ++x, ++i) {
34             if (i == color_n) {
35                 shade = mid_shade;
36             }
37             auto foreground =
38                 static_cast<Color>(detail::first_color_value + (i % 16));
39             if (foreground == base_) {
40                 --x;
41             } else {
42                 shade.brush.set_foreground(foreground);
43                 p.put(shade, x, y);
44             }
45         }
46     }
47     return Widget::paint_event();
48 }
49 
Bottom_shades()50 Bottom_shades::Bottom_shades() {
51     blue_shade.invert();
52     orange_shade.invert();
53     light_gray_shade.invert();
54     light_green_shade.invert();
55     violet_shade.invert();
56     light_blue_shade.invert();
57     yellow_shade.invert();
58     white_shade.invert();
59 }
60 
All_colors_display()61 All_colors_display::All_colors_display() {
62     const auto width = 48;
63     color_select.width_policy.maximum(width);
64     color_select.height_policy.maximum(6);
65     top_shades.width_policy.maximum(width);
66     bottom_shades.width_policy.maximum(width);
67 }
68 }  // namespace palette
69