1
0
mirror of https://github.com/uowuo/abaddon.git synced 2025-03-04 03:03:16 -05:00

add int -> color to util

This commit is contained in:
ouwou 2020-09-05 21:05:52 -04:00
parent 7d41206a19
commit de482d6cb7
2 changed files with 17 additions and 11 deletions

View File

@ -2,6 +2,7 @@
#include <iomanip>
#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);
}

View File

@ -4,6 +4,9 @@
#include <vector>
#include <functional>
#include <iterator>
#include <sstream>
#include <string>
#include <iomanip>
template<typename T>
inline void AlphabeticalSort(typename T start, typename T end, std::function<std::string(const typename std::iterator_traits<T>::value_type &)> get_string) {
@ -29,3 +32,14 @@ inline void AlphabeticalSort(typename T start, typename T end, std::function<std
return ac[0] || ac[5];
});
}
inline std::string IntToCSSColor(int color) {
int r = (color & 0xFF0000) >> 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();
}