From 503c196d4f86cb6156ee9a2e6546af5fc04edf7e Mon Sep 17 00:00:00 2001 From: Jaidyn Ann Date: Mon, 7 Jun 2021 00:56:26 -0500 Subject: [PATCH] Generate unique foreground for each user --- application/CayaUtils.cpp | 26 ++++++++++++++++++++++++++ application/CayaUtils.h | 1 + application/User.cpp | 1 + application/User.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/application/CayaUtils.cpp b/application/CayaUtils.cpp index c077ad3..f83a2fa 100644 --- a/application/CayaUtils.cpp +++ b/application/CayaUtils.cpp @@ -177,6 +177,32 @@ CayaTintColor(rgb_color color, int severity) } +rgb_color +CayaForegroundColor(rgb_color background) +{ + rgb_color foreground; + int32 brighter; + int32 darker; + float ratio; + + do { + foreground.set_to(rand() % 255, rand() % 255, rand() %255); + if (foreground.Brightness() > background.Brightness()) { + brighter = foreground.Brightness(); + darker = background.Brightness(); + } + else { + brighter = background.Brightness(); + darker = foreground.Brightness(); + } + ratio = (brighter + .05) / (darker + .05); + } + while (ratio > 5 || ratio < 4); + + return foreground; +} + + status_t ReadAttributeData(BNode* node, const char* name, char** buffer, int32 *size) { attr_info info; diff --git a/application/CayaUtils.h b/application/CayaUtils.h index 4935363..a14ef69 100644 --- a/application/CayaUtils.h +++ b/application/CayaUtils.h @@ -25,6 +25,7 @@ const char* CayaCachePath(); const char* CayaLogPath(const char* signature, const char* subsignature); rgb_color CayaTintColor(rgb_color color, int severity); +rgb_color CayaForegroundColor(rgb_color background); // Borrowed from BePodder's own libfunky status_t ReadAttributeData(BNode* node, const char* name, char** buffer, int32 *size); diff --git a/application/User.cpp b/application/User.cpp index 3d7482b..4305c6c 100644 --- a/application/User.cpp +++ b/application/User.cpp @@ -29,6 +29,7 @@ User::User(BString id, BMessenger msgn) fMessenger(msgn), fLooper(NULL), fListItem(NULL), + fItemColor(CayaForegroundColor(ui_color(B_LIST_BACKGROUND_COLOR))), fStatus(CAYA_OFFLINE), fPopUp(NULL) { diff --git a/application/User.h b/application/User.h index 81f7b06..fe88d69 100644 --- a/application/User.h +++ b/application/User.h @@ -63,6 +63,8 @@ public: ChatMap Conversations(); + rgb_color fItemColor; + protected: BMessenger fMessenger; ProtocolLooper* fLooper;