summaryrefslogtreecommitdiff
path: root/bouncer
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bouncer/richtext.cpp51
-rw-r--r--bouncer/window.cpp6
2 files changed, 48 insertions, 9 deletions
diff --git a/bouncer/richtext.cpp b/bouncer/richtext.cpp
index 2deebda..396f666 100644
--- a/bouncer/richtext.cpp
+++ b/bouncer/richtext.cpp
@@ -177,15 +177,60 @@ const char *RichTextBuilder::c_str() {
+inline static float hslValue(float n1, float n2, float hue) {
+ if (hue > 6.0f)
+ hue -= 6.0f;
+ else if (hue < 0.0f)
+ hue += 6.0f;
+
+ if (hue < 1.0f)
+ return n1 + (n2 - n1) * hue;
+ else if (hue < 3.0f)
+ return n2;
+ else if (hue < 4.0f)
+ return n1 + (n2 - n1) * (4.0f - hue);
+ else
+ return n1;
+}
+
+void calculateHSL(float h, float s, float l, uint8_t *r, uint8_t *g, uint8_t *b) {
+ // make it RGB
+
+ if (s == 0) {
+ *r = *g = *b = l*255.0f;
+ } else {
+ float m1, m2;
+ if (l <= 0.5f)
+ m2 = l * (1.0f + s);
+ else
+ m2 = l + s - l * s;
+
+ m1 = 2.0f * s - m2;
+
+ *r = hslValue(m1, m2, h * 6.0f + 2.0) * 255.0f;
+ *g = hslValue(m1, m2, h * 6.0f) * 255.0f;
+ *b = hslValue(m1, m2, h * 6.0f - 2.0) * 255.0f;
+ }
+}
+
+
+
void RichTextBuilder::appendNick(const char *nick) {
uint32_t hash = 0;
const char *c = nick;
while (*c)
hash = (hash * 17) + *(c++);
- int r = ((hash & 0xFF0000) >> 16);
- int g = ((hash & 0xFF00) >> 8);
- int b = (hash & 0xFF);
+ int hueBase = ((hash & 0xFF0000) >> 16);
+ int satBase = ((hash & 0xFF00) >> 8);
+ int lumBase = (hash & 0xFF);
+ uint8_t r, g, b;
+
+ calculateHSL(
+ hueBase / 255.0f,
+ (0.50f + (satBase / 765.0f)),
+ (0.40f + (lumBase / 1020.0f)),
+ &r, &g, &b);
foreground(COL_LEVEL_NICK, r, g, b);
append(nick);
diff --git a/bouncer/window.cpp b/bouncer/window.cpp
index a8a7bb2..75ba862 100644
--- a/bouncer/window.cpp
+++ b/bouncer/window.cpp
@@ -172,12 +172,6 @@ void StatusWindow::handleUserInput(const char *str) {
else
pushMessage("Server password cleared.");
- } else if (strcmp(str, "/c") == 0) {
- RichTextBuilder rt;
- rt.foreground(2, 100, 0, 255);
- rt.append("boooooop");
- rt.endForeground(2);
- pushMessage(rt.c_str());
}
} else {
server->sendLine(str);