Improve colorizing of custom themes.

This commit is contained in:
John Preston 2021-09-11 12:26:35 +03:00
parent 8d31769846
commit 9150cc77f9
3 changed files with 41 additions and 1 deletions

View File

@ -12,6 +12,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/chat/message_bubble.h"
#include "ui/chat/chat_style.h"
#include "ui/style/style_core_palette.h"
#include "ui/style/style_palette_colorizer.h"
#include <crl/crl_async.h>
#include <QtGui/QGuiApplication>
@ -247,6 +248,7 @@ void ChatTheme::adjustPalette(const ChatThemeDescriptor &descriptor) {
CountAverageColor(descriptor.bubblesData.colors))
: std::optional<QColor>();
if (bubblesAccent) {
// First set hue/saturation the same for all those colors from accent.
const auto by = *bubblesAccent;
if (!overrideOutBg) {
adjust(p.msgOutBg(), by);
@ -269,6 +271,18 @@ void ChatTheme::adjustPalette(const ChatThemeDescriptor &descriptor) {
adjust(p.historyOutIconFg(), by);
adjust(p.historyCallArrowOutFg(), by);
adjust(p.historyFileOutIconFg(), by);
// After make msgFileOutBg exact accent and adjust some others.
const auto colorizer = bubblesAccentColorizer(by);
adjust(p.msgOutServiceFg(), colorizer);
adjust(p.msgOutDateFg(), colorizer);
adjust(p.msgFileThumbLinkOutFg(), colorizer);
adjust(p.msgFileOutBg(), colorizer);
adjust(p.msgOutReplyBarColor(), colorizer);
adjust(p.msgWaveformOutActive(), colorizer);
adjust(p.msgWaveformOutInactive(), colorizer);
adjust(p.mediaOutFg(), colorizer);
adjust(p.historyLinkOutFg(), colorizer);
}
auto outBgColors = descriptor.bubblesData.colors;
if (outBgColors.empty()) {
@ -321,6 +335,22 @@ void ChatTheme::adjustPalette(const ChatThemeDescriptor &descriptor) {
}
}
style::colorizer ChatTheme::bubblesAccentColorizer(
const QColor &accent) const {
const auto color = [](const QColor &value) {
auto hue = 0;
auto saturation = 0;
auto lightness = 0;
value.getHsv(&hue, &saturation, &lightness);
return style::colorizer::Color{ hue, saturation, lightness };
};
return {
.hueThreshold = 255,
.was = color(_palette->msgFileOutBg()->c),
.now = color(accent),
};
}
void ChatTheme::set(const style::color &my, const QColor &color) {
auto r = 0, g = 0, b = 0, a = 0;
color.getRgb(&r, &g, &b, &a);
@ -331,6 +361,12 @@ void ChatTheme::adjust(const style::color &my, const QColor &by) {
set(my, ThemeAdjustedColor(my->c, by));
}
void ChatTheme::adjust(const style::color &my, const style::colorizer &by) {
if (const auto adjusted = style::colorize(my->c, by)) {
set(my, *adjusted);
}
}
void ChatTheme::setBackground(ChatThemeBackground &&background) {
_mutableBackground = std::move(background);
_backgroundState = {};

View File

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace style {
class palette;
struct colorizer;
} // namespace style
namespace Ui {
@ -150,9 +151,12 @@ private:
[[nodiscard]] bool readyForBackgroundRotation() const;
void generateNextBackgroundRotation();
[[nodiscard]] style::colorizer bubblesAccentColorizer(
const QColor &accent) const;
void adjustPalette(const ChatThemeDescriptor &descriptor);
void set(const style::color &my, const QColor &color);
void adjust(const style::color &my, const QColor &by);
void adjust(const style::color &my, const style::colorizer &by);
uint64 _id = 0;
std::unique_ptr<style::palette> _palette;

@ -1 +1 @@
Subproject commit 5b521d63a424b9b2521c13785e5f264279c7ba2e
Subproject commit 246b947fa747a1fd54e0b4a58516e1b3a9465c1a