mirror of
https://github.com/Chatterino/chatterino2.git
synced 2024-11-21 22:24:07 +01:00
added color normalizer for dark theme
This commit is contained in:
parent
670d25342d
commit
fa049cf420
5 changed files with 153 additions and 6 deletions
|
@ -8,8 +8,12 @@ QT += core gui network
|
||||||
CONFIG += communi
|
CONFIG += communi
|
||||||
COMMUNI += core model util
|
COMMUNI += core model util
|
||||||
|
|
||||||
win32:LIBS += -LC:/OpenSSL-Win32/lib/openssl.lib
|
#win32 {
|
||||||
INCLUDEPATH += C:/OpenSSL-Win32/include
|
# LIBS += -L"C:/OpenSSL-Win32/lib" -llibssl.lib
|
||||||
|
# INCLUDEPATH += C:/OpenSSL-Win32/include
|
||||||
|
#} else {
|
||||||
|
# LIBS += -lcrypto -lssl
|
||||||
|
#}
|
||||||
|
|
||||||
CONFIG += c++11
|
CONFIG += c++11
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,14 @@
|
||||||
#include "chatwidgetview.h"
|
#include "chatwidgetview.h"
|
||||||
#include "channels.h"
|
#include "channels.h"
|
||||||
#include "chatwidget.h"
|
#include "chatwidget.h"
|
||||||
|
#include "colorscheme.h"
|
||||||
#include "message.h"
|
#include "message.h"
|
||||||
#include "word.h"
|
#include "word.h"
|
||||||
#include "wordpart.h"
|
#include "wordpart.h"
|
||||||
|
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QScroller>
|
#include <QScroller>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
ChatWidgetView::ChatWidgetView(ChatWidget *parent)
|
ChatWidgetView::ChatWidgetView(ChatWidget *parent)
|
||||||
: QWidget()
|
: QWidget()
|
||||||
|
@ -55,12 +57,48 @@ ChatWidgetView::paintEvent(QPaintEvent *)
|
||||||
|
|
||||||
auto c = m_chatWidget->channel();
|
auto c = m_chatWidget->channel();
|
||||||
|
|
||||||
|
QColor color;
|
||||||
|
|
||||||
|
ColorScheme &scheme = ColorScheme::instance();
|
||||||
|
|
||||||
|
// code for tesing colors
|
||||||
|
/*
|
||||||
|
static ConcurrentMap<qreal, QImage *> imgCache;
|
||||||
|
|
||||||
|
std::function<QImage *(qreal)> getImg = [&scheme](qreal light) {
|
||||||
|
return imgCache.getOrAdd(light, [&scheme, &light] {
|
||||||
|
QImage *img = new QImage(150, 50, QImage::Format_RGB32);
|
||||||
|
|
||||||
|
QColor color;
|
||||||
|
|
||||||
|
for (int j = 0; j < 50; j++) {
|
||||||
|
for (qreal i = 0; i < 150; i++) {
|
||||||
|
color = QColor::fromHslF(i / 150.0, light, j / 50.0);
|
||||||
|
|
||||||
|
scheme.normalizeColor(color);
|
||||||
|
|
||||||
|
img->setPixelColor(i, j, color);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return img;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
for (qreal k = 0; k < 4.8; k++) {
|
||||||
|
auto img = getImg(k / 5);
|
||||||
|
|
||||||
|
painter.drawImage(QRect(k * 150, 0, 150, 150), *img);
|
||||||
|
}
|
||||||
|
|
||||||
|
painter.fillRect(QRect(0, 9, 500, 2), QColor(0, 0, 0));*/
|
||||||
|
|
||||||
if (c == NULL)
|
if (c == NULL)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto messages = c->getMessagesClone();
|
auto messages = c->getMessagesClone();
|
||||||
|
|
||||||
int y = 0;
|
int y = m_scrollbar.star;
|
||||||
|
|
||||||
for (std::shared_ptr<Message> const &message : messages) {
|
for (std::shared_ptr<Message> const &message : messages) {
|
||||||
for (WordPart const &wordPart : message.get()->wordParts()) {
|
for (WordPart const &wordPart : message.get()->wordParts()) {
|
||||||
|
@ -83,7 +121,9 @@ ChatWidgetView::paintEvent(QPaintEvent *)
|
||||||
}
|
}
|
||||||
// text
|
// text
|
||||||
else {
|
else {
|
||||||
painter.setPen(wordPart.word().color());
|
QColor color = wordPart.word().color();
|
||||||
|
|
||||||
|
painter.setPen(color);
|
||||||
painter.setFont(wordPart.word().getFont());
|
painter.setFont(wordPart.word().getFont());
|
||||||
|
|
||||||
painter.drawText(
|
painter.drawText(
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
#define LOOKUP_COLOR_COUNT 360
|
||||||
|
|
||||||
#include "colorscheme.h"
|
#include "colorscheme.h"
|
||||||
#include "QColor"
|
#include "QColor"
|
||||||
|
|
||||||
|
@ -40,4 +42,89 @@ ColorScheme::setColors(float hue, float multiplyer)
|
||||||
ChatHeaderBorder = getColor(0, 0.1, 0.85);
|
ChatHeaderBorder = getColor(0, 0.1, 0.85);
|
||||||
ChatInputBackground = getColor(0, 0.1, 0.95);
|
ChatInputBackground = getColor(0, 0.1, 0.95);
|
||||||
ChatInputBorder = getColor(0, 0.1, 0.9);
|
ChatInputBorder = getColor(0, 0.1, 0.9);
|
||||||
|
|
||||||
|
// generate color lookuptable
|
||||||
|
// fillLookupTableValues(0, 0.1, 0.6, 1);
|
||||||
|
// fillLookupTableValues(0.1, 0.50, 1, 1);
|
||||||
|
// fillLookupTableValues(0.50, 0.65, 1, 0.5);
|
||||||
|
// fillLookupTableValues(0.65, 0.83, 0.5, 0.7);
|
||||||
|
// fillLookupTableValues(0.83, 1, 0.7, 0.6);
|
||||||
|
|
||||||
|
fillLookupTableValues(m_middleLookupTable, 0.000, 0.166, 0.66, 0.5);
|
||||||
|
fillLookupTableValues(m_middleLookupTable, 0.166, 0.333, 0.5, 0.55);
|
||||||
|
fillLookupTableValues(m_middleLookupTable, 0.333, 0.500, 0.55, 0.45);
|
||||||
|
fillLookupTableValues(m_middleLookupTable, 0.500, 0.666, 0.45, 0.80);
|
||||||
|
fillLookupTableValues(m_middleLookupTable, 0.666, 0.833, 0.80, 0.61);
|
||||||
|
fillLookupTableValues(m_middleLookupTable, 0.833, 1.000, 0.61, 0.66);
|
||||||
|
|
||||||
|
fillLookupTableValues(m_minLookupTable, 0.000, 0.166, 0.33, 0.23);
|
||||||
|
fillLookupTableValues(m_minLookupTable, 0.166, 0.333, 0.23, 0.27);
|
||||||
|
fillLookupTableValues(m_minLookupTable, 0.333, 0.500, 0.27, 0.23);
|
||||||
|
fillLookupTableValues(m_minLookupTable, 0.500, 0.666, 0.23, 0.50);
|
||||||
|
fillLookupTableValues(m_minLookupTable, 0.666, 0.833, 0.50, 0.30);
|
||||||
|
fillLookupTableValues(m_minLookupTable, 0.833, 1.000, 0.30, 0.33);
|
||||||
|
|
||||||
|
// for (int i = 0; i < LOOKUP_COLOR_COUNT; i++) {
|
||||||
|
// qInfo(QString::number(m_middleLookupTable[i]).toStdString().c_str());
|
||||||
|
// }
|
||||||
|
}
|
||||||
|
|
||||||
|
void ColorScheme::fillLookupTableValues(qreal (&array)[360], qreal from,
|
||||||
|
qreal to, qreal fromValue,
|
||||||
|
qreal toValue)
|
||||||
|
{
|
||||||
|
qreal diff = toValue - fromValue;
|
||||||
|
|
||||||
|
int start = from * LOOKUP_COLOR_COUNT;
|
||||||
|
int end = to * LOOKUP_COLOR_COUNT;
|
||||||
|
int length = end - start;
|
||||||
|
|
||||||
|
for (int i = 0; i < length; i++) {
|
||||||
|
array[start + i] = fromValue + (diff * ((qreal)i / length));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
ColorScheme::normalizeColor(QColor &color)
|
||||||
|
{
|
||||||
|
// qreal l = color.lightnessF();
|
||||||
|
// qreal s = color.saturationF();
|
||||||
|
// qreal x = m_colorLookupTable[std::max(0, color.hue())];
|
||||||
|
// qreal newL = (l - 1) * x + 1;
|
||||||
|
|
||||||
|
// newL = s * newL + (1 - s) * l;
|
||||||
|
|
||||||
|
// newL = newL > 0.5 ? newL : newL / 2 + 0.25;
|
||||||
|
|
||||||
|
// color.setHslF(color.hueF(), s, newL);
|
||||||
|
|
||||||
|
qreal l = color.lightnessF();
|
||||||
|
qreal s = color.saturationF();
|
||||||
|
int h = std::max(0, color.hue());
|
||||||
|
qreal x = m_middleLookupTable[h];
|
||||||
|
x = s * 0.5 + (1 - s) * x;
|
||||||
|
|
||||||
|
qreal min = m_minLookupTable[h];
|
||||||
|
min = (1 - s) * 0.5 + s * min;
|
||||||
|
|
||||||
|
qreal newL;
|
||||||
|
|
||||||
|
if (l < x) {
|
||||||
|
newL = l * ((x - min) / x) + min;
|
||||||
|
|
||||||
|
// newL = (l * ((x - min) / x) + min);
|
||||||
|
// newL = (1 - s) * newL + s * l;
|
||||||
|
} else {
|
||||||
|
newL = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
color.setHslF(color.hueF(), s, newL);
|
||||||
|
|
||||||
|
// qreal newL = (l - 1) * x + 1;
|
||||||
|
|
||||||
|
// newL = s * newL + (1 - s) * l;
|
||||||
|
|
||||||
|
// newL = newL > 0.5 ? newL : newL / 2 + 0.25;
|
||||||
|
|
||||||
|
// color.setHslF(color.hueF(), s, newL);
|
||||||
}
|
}
|
||||||
|
|
|
@ -64,12 +64,20 @@ public:
|
||||||
return instance;
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void normalizeColor(QColor &color);
|
||||||
|
|
||||||
void setColors(float hue, float multiplyer);
|
void setColors(float hue, float multiplyer);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ColorScheme()
|
ColorScheme()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
qreal m_middleLookupTable[360] = {};
|
||||||
|
qreal m_minLookupTable[360] = {};
|
||||||
|
|
||||||
|
void fillLookupTableValues(qreal (&array)[360], qreal from, qreal to,
|
||||||
|
qreal fromValue, qreal toValue);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // COLORSCHEME_H
|
#endif // COLORSCHEME_H
|
||||||
|
|
|
@ -176,9 +176,17 @@ IrcManager::partChannel(const QString &channel)
|
||||||
void
|
void
|
||||||
IrcManager::messageReceived(IrcMessage *message)
|
IrcManager::messageReceived(IrcMessage *message)
|
||||||
{
|
{
|
||||||
// qInfo(message->command().toStdString().c_str());
|
// qInfo(message->command().toStdString().c_str());
|
||||||
|
|
||||||
// if (message->command() == "")
|
const QString &command = message->command();
|
||||||
|
|
||||||
|
// if (command == "CLEARCHAT") {
|
||||||
|
// message->
|
||||||
|
// } else if (command == "ROOMSTATE") {
|
||||||
|
// } else if (command == "USERSTATE") {
|
||||||
|
// } else if (command == "WHISPER") {
|
||||||
|
// } else if (command == "USERNOTICE") {
|
||||||
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
Loading…
Reference in a new issue