From de482d6cb7a57c804e771d14dcb1c592b5f07402 Mon Sep 17 00:00:00 2001 From: ouwou <26526779+ouwou@users.noreply.github.com> Date: Sat, 5 Sep 2020 21:05:52 -0400 Subject: add int -> color to util --- components/chatmessage.cpp | 14 +++----------- util.hpp | 14 ++++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/components/chatmessage.cpp b/components/chatmessage.cpp index 9d4aa46..bb61e81 100644 --- a/components/chatmessage.cpp +++ b/components/chatmessage.cpp @@ -2,6 +2,7 @@ #include #include "chatmessage.hpp" #include "../abaddon.hpp" +#include "../util.hpp" ChatMessageContainer::ChatMessageContainer(const MessageData *data) { UserID = data->Author.ID; @@ -271,17 +272,8 @@ void ChatMessageEmbedItem::DoLayout() { if (m_embed.Color != -1) { auto provider = Gtk::CssProvider::create(); // this seems wrong - int r = (m_embed.Color & 0xFF0000) >> 16; - int g = (m_embed.Color & 0x00FF00) >> 8; - int b = (m_embed.Color & 0x0000FF) >> 0; - std::stringstream css; // lol - css << ".embed { border-left: 2px solid #" - << std::hex << std::setw(2) << std::setfill('0') << r - << std::hex << std::setw(2) << std::setfill('0') << g - << std::hex << std::setw(2) << std::setfill('0') << b - << "; }"; - - provider->load_from_data(css.str()); + std::string css = ".embed { border-left: 2px solid #" + IntToCSSColor(m_embed.Color) + "; }"; + provider->load_from_data(css); style->add_provider(provider, GTK_STYLE_PROVIDER_PRIORITY_APPLICATION); } diff --git a/util.hpp b/util.hpp index 48cd73c..f192835 100644 --- a/util.hpp +++ b/util.hpp @@ -4,6 +4,9 @@ #include #include #include +#include +#include +#include template inline void AlphabeticalSort(typename T start, typename T end, std::function::value_type &)> get_string) { @@ -29,3 +32,14 @@ inline void AlphabeticalSort(typename T start, typename T end, std::function> 16; + int g = (color & 0x00FF00) >> 8; + int b = (color & 0x0000FF) >> 0; + std::stringstream ss; + ss << std::hex << std::setw(2) << std::setfill('0') << r + << std::hex << std::setw(2) << std::setfill('0') << g + << std::hex << std::setw(2) << std::setfill('0') << b; + return ss.str(); +} -- cgit v1.2.3