From 9931bfa14fbaef1e6fe8858fcb56c4beb9a17c67 Mon Sep 17 00:00:00 2001 From: Mikko Rasa Date: Wed, 15 Aug 2018 02:22:59 +0300 Subject: [PATCH] Add alpha channel support for colors --- source/appearance.cpp | 24 +++++++++++++++++++++--- source/appearance.h | 3 +++ source/color.cpp | 8 +++++--- source/color.h | 3 ++- source/theme.cpp | 6 ++++++ source/theme.h | 1 + 6 files changed, 38 insertions(+), 7 deletions(-) diff --git a/source/appearance.cpp b/source/appearance.cpp index f1bb993..ccd8476 100644 --- a/source/appearance.cpp +++ b/source/appearance.cpp @@ -35,13 +35,13 @@ void Appearance::add_lines(FilterStatement &st) const st.add_line(format("SetFontSize %d", font_size)); if(background_color.defined) - st.add_line(format("SetBackgroundColor %d %d %d", background_color.r, background_color.g, background_color.b)); + st.add_line(format("SetBackgroundColor %d %d %d %d", background_color.r, background_color.g, background_color.b, background_color.a)); if(border_color.defined) - st.add_line(format("SetBorderColor %d %d %d", border_color.r, border_color.g, border_color.b)); + st.add_line(format("SetBorderColor %d %d %d %d", border_color.r, border_color.g, border_color.b, border_color.a)); if(text_color.defined) - st.add_line(format("SetTextColor %d %d %d", text_color.r, text_color.g, text_color.b)); + st.add_line(format("SetTextColor %d %d %d %d", text_color.r, text_color.g, text_color.b, text_color.a)); if(sound_type) st.add_line(format("PlayAlertSound %d %d", sound_type, sound_volume)); @@ -54,11 +54,14 @@ Appearance::Loader::Loader(Appearance &a, const Theme *t): { add("alert_sound", &Appearance::sound_type, &Appearance::sound_volume); add("background_color", &Loader::background_color); + add("background_color", &Loader::background_color_alpha); add("background_color", &Loader::background_color_named); add("border_color", &Loader::border_color); + add("border_color", &Loader::border_color_alpha); add("border_color", &Loader::border_color_named); add("font_size", &Loader::font_size); add("text_color", &Loader::text_color); + add("text_color", &Loader::text_color_alpha); add("text_color", &Loader::text_color_named); } @@ -67,6 +70,11 @@ void Appearance::Loader::background_color(unsigned r, unsigned g, unsigned b) obj.background_color = Color(r, g, b); } +void Appearance::Loader::background_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a) +{ + obj.background_color = Color(r, g, b, a); +} + void Appearance::Loader::background_color_named(const string &name) { if(!theme) @@ -79,6 +87,11 @@ void Appearance::Loader::border_color(unsigned r, unsigned g, unsigned b) obj.border_color = Color(r, g, b); } +void Appearance::Loader::border_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a) +{ + obj.border_color = Color(r, g, b, a); +} + void Appearance::Loader::border_color_named(const string &name) { if(!theme) @@ -97,6 +110,11 @@ void Appearance::Loader::text_color(unsigned r, unsigned g, unsigned b) obj.text_color = Color(r, g, b); } +void Appearance::Loader::text_color_alpha(unsigned r, unsigned g, unsigned b, unsigned a) +{ + obj.text_color = Color(r, g, b, a); +} + void Appearance::Loader::text_color_named(const string &name) { if(!theme) diff --git a/source/appearance.h b/source/appearance.h index 4135074..6806ed2 100644 --- a/source/appearance.h +++ b/source/appearance.h @@ -20,11 +20,14 @@ public: Loader(Appearance &, const Theme * = 0); void background_color(unsigned, unsigned, unsigned); + void background_color_alpha(unsigned, unsigned, unsigned, unsigned); void background_color_named(const std::string &); void border_color(unsigned, unsigned, unsigned); + void border_color_alpha(unsigned, unsigned, unsigned, unsigned); void border_color_named(const std::string &); void font_size(float); void text_color(unsigned, unsigned, unsigned); + void text_color_alpha(unsigned, unsigned, unsigned, unsigned); void text_color_named(const std::string &); }; diff --git a/source/color.cpp b/source/color.cpp index a7d8330..ebfe154 100644 --- a/source/color.cpp +++ b/source/color.cpp @@ -4,12 +4,14 @@ Color::Color(): defined(false), r(0), g(0), - b(0) + b(0), + a(0) { } -Color::Color(unsigned r_, unsigned g_, unsigned b_): +Color::Color(unsigned r_, unsigned g_, unsigned b_, unsigned a_): defined(true), r(r_), g(g_), - b(b_) + b(b_), + a(a_) { } diff --git a/source/color.h b/source/color.h index 5ade180..8d73e7e 100644 --- a/source/color.h +++ b/source/color.h @@ -7,9 +7,10 @@ struct Color unsigned r; unsigned g; unsigned b; + unsigned a; Color(); - Color(unsigned, unsigned, unsigned); + Color(unsigned, unsigned, unsigned, unsigned = 255); }; #endif diff --git a/source/theme.cpp b/source/theme.cpp index 7557caa..6f9f5d9 100644 --- a/source/theme.cpp +++ b/source/theme.cpp @@ -46,6 +46,7 @@ Theme::Loader::Loader(Theme &t): add("appearance", &Loader::appearance); add("base_font_size", &Theme::base_font_size); add("color", &Loader::color); + add("color", &Loader::color_alpha); } void Theme::Loader::appearance(const string &name) @@ -60,3 +61,8 @@ void Theme::Loader::color(const string &name, unsigned r, unsigned g, unsigned b { obj.set_color(name, Color(r, g, b)); } + +void Theme::Loader::color_alpha(const string &name, unsigned r, unsigned g, unsigned b, unsigned a) +{ + obj.set_color(name, Color(r, g, b, a)); +} diff --git a/source/theme.h b/source/theme.h index 43584a2..f7c3f94 100644 --- a/source/theme.h +++ b/source/theme.h @@ -18,6 +18,7 @@ public: private: void appearance(const std::string &); void color(const std::string &, unsigned, unsigned, unsigned); + void color_alpha(const std::string &, unsigned, unsigned, unsigned, unsigned); }; private: -- 2.45.2