mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
try to improve readability of the "grayname colorize" function
This commit is contained in:
parent
3bb40a0458
commit
391d75f208
1 changed files with 29 additions and 24 deletions
|
@ -20,43 +20,48 @@
|
||||||
#include "widgets/Window.hpp"
|
#include "widgets/Window.hpp"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QColor>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMediaPlayer>
|
#include <QMediaPlayer>
|
||||||
#include <QStringRef>
|
#include <QStringRef>
|
||||||
#include <QColor>
|
|
||||||
#include <boost/variant.hpp>
|
#include <boost/variant.hpp>
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
QColor getRandomColor(QVariant value)
|
QColor getRandomColor(const QVariant &userId)
|
||||||
{
|
{
|
||||||
static const std::vector<QColor> twitchUsernameColors = {
|
static const std::vector<QColor> twitchUsernameColors = {
|
||||||
QColor(255, 0, 0), // Red
|
{255, 0, 0}, // Red
|
||||||
QColor(0, 0, 255), // Blue
|
{0, 0, 255}, // Blue
|
||||||
QColor(0, 255, 0), // Green
|
{0, 255, 0}, // Green
|
||||||
QColor(178, 34, 34), // FireBrick
|
{178, 34, 34}, // FireBrick
|
||||||
QColor(255, 127, 80), // Coral
|
{255, 127, 80}, // Coral
|
||||||
QColor(154, 205, 50), // YellowGreen
|
{154, 205, 50}, // YellowGreen
|
||||||
QColor(255, 69, 0), // OrangeRed
|
{255, 69, 0}, // OrangeRed
|
||||||
QColor(46, 139, 87), // SeaGreen
|
{46, 139, 87}, // SeaGreen
|
||||||
QColor(218, 165, 32), // GoldenRod
|
{218, 165, 32}, // GoldenRod
|
||||||
QColor(210, 105, 30), // Chocolate
|
{210, 105, 30}, // Chocolate
|
||||||
QColor(95, 158, 160), // CadetBlue
|
{95, 158, 160}, // CadetBlue
|
||||||
QColor(30, 144, 255), // DodgerBlue
|
{30, 144, 255}, // DodgerBlue
|
||||||
QColor(255, 105, 180), // HotPink
|
{255, 105, 180}, // HotPink
|
||||||
QColor(138, 43, 226), // BlueViolet
|
{138, 43, 226}, // BlueViolet
|
||||||
QColor(0, 255, 127) // SpringGreen
|
{0, 255, 127}, // SpringGreen
|
||||||
};
|
};
|
||||||
|
|
||||||
// If someday Twitch will replace all the user-ids with strings
|
bool ok = true;
|
||||||
// then we just choose a random color.
|
int colorSeed = userId.toInt(&ok);
|
||||||
const auto userId = value.toInt();
|
if (!ok)
|
||||||
const auto index = (userId ? userId : std::rand())
|
{
|
||||||
% twitchUsernameColors.size();
|
// We were unable to convert the user ID to an integer, this means Twitch has decided to start using non-integer user IDs
|
||||||
return twitchUsernameColors[index];
|
// Just randomize the users color
|
||||||
|
colorSeed = std::rand();
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto colorIndex = colorSeed % twitchUsernameColors.size();
|
||||||
|
return twitchUsernameColors[colorIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} // namespace
|
||||||
|
|
||||||
namespace chatterino {
|
namespace chatterino {
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue