refactor(color): Better channel function names

(alpha|red|green|blue)_(d|i) are used for the four channels using
doubles or integers, respectively.
This commit is contained in:
patrick96 2020-11-27 21:05:50 +01:00 committed by Patrick Ziegler
parent 477189e443
commit 53c6f3b042
5 changed files with 34 additions and 34 deletions

View File

@ -70,7 +70,7 @@ namespace cairo {
}
context& operator<<(const rgba& f) {
cairo_set_source_rgba(m_c, f.r(), f.g(), f.b(), f.a());
cairo_set_source_rgba(m_c, f.red_d(), f.green_d(), f.blue_d(), f.alpha_d());
return *this;
}
@ -105,7 +105,7 @@ namespace cairo {
auto offset = 0.0;
for (auto&& color : l.steps) {
// clang-format off
cairo_pattern_add_color_stop_rgba(pattern, offset, color.r(), color.g(), color.b(), color.a());
cairo_pattern_add_color_stop_rgba(pattern, offset, color.red_d(), color.green_d(), color.blue_d(), color.alpha_d());
// clang-format on
offset += step;
}

View File

@ -24,15 +24,15 @@ class rgba {
uint32_t value() const;
color_type type() const;
double a() const;
double r() const;
double g() const;
double b() const;
double alpha_d() const;
double red_d() const;
double green_d() const;
double blue_d() const;
uint8_t a_int() const;
uint8_t r_int() const;
uint8_t g_int() const;
uint8_t b_int() const;
uint8_t alpha_i() const;
uint8_t red_i() const;
uint8_t green_i() const;
uint8_t blue_i() const;
bool has_color() const;
rgba apply_alpha(rgba other) const;

View File

@ -85,7 +85,7 @@ bool rgba::operator==(const rgba& other) const {
case ARGB:
return m_value == other.m_value;
case ALPHA_ONLY:
return a_int() == other.a_int();
return alpha_i() == other.alpha_i();
default:
return false;
}
@ -103,35 +103,35 @@ rgba::color_type rgba::type() const {
return m_type;
}
double rgba::a() const {
return a_int() / 255.0;
double rgba::alpha_d() const {
return alpha_i() / 255.0;
}
double rgba::r() const {
return r_int() / 255.0;
double rgba::red_d() const {
return red_i() / 255.0;
}
double rgba::g() const {
return g_int() / 255.0;
double rgba::green_d() const {
return green_i() / 255.0;
}
double rgba::b() const {
return b_int() / 255.0;
double rgba::blue_d() const {
return blue_i() / 255.0;
}
uint8_t rgba::a_int() const {
uint8_t rgba::alpha_i() const {
return (m_value >> 24) & 0xFF;
}
uint8_t rgba::r_int() const {
uint8_t rgba::red_i() const {
return (m_value >> 16) & 0xFF;
}
uint8_t rgba::g_int() const {
uint8_t rgba::green_i() const {
return (m_value >> 8) & 0xFF;
}
uint8_t rgba::b_int() const {
uint8_t rgba::blue_i() const {
return m_value & 0xFF;
}
@ -145,7 +145,7 @@ bool rgba::has_color() const {
* Useful for ALPHA_ONLY colors
*/
rgba rgba::apply_alpha(rgba other) const {
uint32_t val = (m_value & 0x00FFFFFF) | (((uint32_t)other.a_int()) << 24);
uint32_t val = (m_value & 0x00FFFFFF) | (((uint32_t)other.alpha_i()) << 24);
return rgba(val, m_type);
}

View File

@ -130,7 +130,7 @@ void tray_manager::setup(const bar_settings& bar_opts) {
// Set user-defined background color
m_opts.background = conf.get(bs, "tray-background", bar_opts.background);
if (m_opts.background.a_int() != 255) {
if (m_opts.background.alpha_i() != 255) {
m_log.trace("tray: enable transparency");
m_opts.transparent = true;
}
@ -638,9 +638,9 @@ void tray_manager::set_wm_hints() {
void tray_manager::set_tray_colors() {
m_log.trace("tray: Set _NET_SYSTEM_TRAY_COLORS to %x", m_opts.background);
auto r = m_opts.background.r_int();
auto g = m_opts.background.g_int();
auto b = m_opts.background.b_int();
auto r = m_opts.background.red_i();
auto g = m_opts.background.green_i();
auto b = m_opts.background.blue_i();
const unsigned int colors[12] = {
r, g, b, // normal

View File

@ -87,13 +87,13 @@ TEST(Rgba, hasColor) {
TEST(Rgba, channel) {
rgba v{0xCC123456};
EXPECT_EQ(0xCC, v.a_int());
EXPECT_EQ(0x12, v.r_int());
EXPECT_EQ(0x34, v.g_int());
EXPECT_EQ(0x56, v.b_int());
EXPECT_EQ(0xCC, v.alpha_i());
EXPECT_EQ(0x12, v.red_i());
EXPECT_EQ(0x34, v.green_i());
EXPECT_EQ(0x56, v.blue_i());
EXPECT_EQ(0xCC / 255.0, rgba{0xCC112233}.a());
EXPECT_EQ(0x99 / 255.0, rgba{0x88449933}.g());
EXPECT_EQ(0xCC / 255.0, rgba{0xCC112233}.alpha_d());
EXPECT_EQ(0x99 / 255.0, rgba{0x88449933}.green_d());
}
TEST(Rgba, applyAlpha) {