2016-04-21 20:57:29 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
2018-01-03 13:23:14 +03:00
|
|
|
the official desktop application for the Telegram messaging service.
|
2016-04-21 20:57:29 +03:00
|
|
|
|
2018-01-03 13:23:14 +03:00
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
2016-04-21 20:57:29 +03:00
|
|
|
*/
|
2017-03-04 12:27:52 +03:00
|
|
|
#include "ui/style/style_core.h"
|
2016-04-21 20:57:29 +03:00
|
|
|
|
|
|
|
namespace style {
|
|
|
|
namespace internal {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
using ModulesList = QList<internal::ModuleBase*>;
|
|
|
|
NeverFreedPointer<ModulesList> styleModules;
|
|
|
|
|
|
|
|
void startModules() {
|
|
|
|
if (!styleModules) return;
|
|
|
|
|
|
|
|
for_const (auto module, *styleModules) {
|
|
|
|
module->start();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void stopModules() {
|
|
|
|
if (!styleModules) return;
|
|
|
|
|
|
|
|
for_const (auto module, *styleModules) {
|
|
|
|
module->stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
void registerModule(ModuleBase *module) {
|
2016-10-12 22:34:25 +03:00
|
|
|
styleModules.createIfNull();
|
2016-04-21 20:57:29 +03:00
|
|
|
styleModules->push_back(module);
|
|
|
|
}
|
|
|
|
|
|
|
|
void unregisterModule(ModuleBase *module) {
|
|
|
|
styleModules->removeOne(module);
|
|
|
|
if (styleModules->isEmpty()) {
|
|
|
|
styleModules.clear();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
|
|
|
|
|
|
|
void startManager() {
|
2018-10-26 14:58:46 +04:00
|
|
|
if (cIntRetinaFactor() * cConfigScale() > kInterfaceScaleMax) {
|
2018-10-15 22:42:10 +03:00
|
|
|
cSetConfigScale(kInterfaceScaleDefault);
|
2016-04-21 20:57:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
internal::registerFontFamily(qsl("Open Sans"));
|
|
|
|
internal::startModules();
|
|
|
|
}
|
|
|
|
|
|
|
|
void stopManager() {
|
|
|
|
internal::stopModules();
|
|
|
|
internal::destroyFonts();
|
2016-07-13 20:34:57 +03:00
|
|
|
internal::destroyIcons();
|
2016-04-21 20:57:29 +03:00
|
|
|
}
|
|
|
|
|
2016-11-02 17:44:33 +03:00
|
|
|
void colorizeImage(const QImage &src, QColor c, QImage *outResult, QRect srcRect, QPoint dstPoint) {
|
2019-01-29 10:29:38 +03:00
|
|
|
// In background_box ColorizePattern we use the fact that
|
|
|
|
// colorizeImage takes only first byte of the mask, so it
|
|
|
|
// could be used for wallpaper patterns, which have values
|
|
|
|
// in ranges (0, 0, 0, 0) to (0, 0, 0, 255) (only 'alpha').
|
2016-11-02 17:44:33 +03:00
|
|
|
if (srcRect.isNull()) {
|
|
|
|
srcRect = src.rect();
|
|
|
|
} else {
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(src.rect().contains(srcRect));
|
2016-11-02 17:44:33 +03:00
|
|
|
}
|
|
|
|
auto width = srcRect.width();
|
|
|
|
auto height = srcRect.height();
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(outResult && outResult->rect().contains(QRect(dstPoint, srcRect.size())));
|
2016-11-02 17:44:33 +03:00
|
|
|
|
2016-11-12 18:02:19 +03:00
|
|
|
auto pattern = anim::shifted(c);
|
2016-11-02 17:44:33 +03:00
|
|
|
|
2016-11-01 15:46:34 +03:00
|
|
|
auto resultBytesPerPixel = (src.depth() >> 3);
|
2016-11-21 23:26:54 +03:00
|
|
|
constexpr auto resultIntsPerPixel = 1;
|
2016-11-02 17:44:33 +03:00
|
|
|
auto resultIntsPerLine = (outResult->bytesPerLine() >> 2);
|
|
|
|
auto resultIntsAdded = resultIntsPerLine - width * resultIntsPerPixel;
|
|
|
|
auto resultInts = reinterpret_cast<uint32*>(outResult->bits()) + dstPoint.y() * resultIntsPerLine + dstPoint.x() * resultIntsPerPixel;
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(resultIntsAdded >= 0);
|
|
|
|
Assert(outResult->depth() == static_cast<int>((resultIntsPerPixel * sizeof(uint32)) << 3));
|
|
|
|
Assert(outResult->bytesPerLine() == (resultIntsPerLine << 2));
|
2016-11-01 15:46:34 +03:00
|
|
|
|
|
|
|
auto maskBytesPerPixel = (src.depth() >> 3);
|
|
|
|
auto maskBytesPerLine = src.bytesPerLine();
|
2016-11-02 17:44:33 +03:00
|
|
|
auto maskBytesAdded = maskBytesPerLine - width * maskBytesPerPixel;
|
|
|
|
auto maskBytes = src.constBits() + srcRect.y() * maskBytesPerLine + srcRect.x() * maskBytesPerPixel;
|
2017-08-17 12:06:26 +03:00
|
|
|
Assert(maskBytesAdded >= 0);
|
|
|
|
Assert(src.depth() == (maskBytesPerPixel << 3));
|
2016-11-02 17:44:33 +03:00
|
|
|
for (int y = 0; y != height; ++y) {
|
|
|
|
for (int x = 0; x != width; ++x) {
|
2016-11-21 23:26:54 +03:00
|
|
|
auto maskOpacity = static_cast<anim::ShiftedMultiplier>(*maskBytes) + 1;
|
2016-11-09 16:40:51 +03:00
|
|
|
*resultInts = anim::unshifted(pattern * maskOpacity);
|
2016-11-01 15:46:34 +03:00
|
|
|
maskBytes += maskBytesPerPixel;
|
|
|
|
resultInts += resultIntsPerPixel;
|
2016-04-21 20:57:29 +03:00
|
|
|
}
|
2016-11-01 15:46:34 +03:00
|
|
|
maskBytes += maskBytesAdded;
|
|
|
|
resultInts += resultIntsAdded;
|
2016-04-21 20:57:29 +03:00
|
|
|
}
|
2016-11-01 15:46:34 +03:00
|
|
|
|
2016-11-02 17:44:33 +03:00
|
|
|
outResult->setDevicePixelRatio(src.devicePixelRatio());
|
2016-04-21 20:57:29 +03:00
|
|
|
}
|
|
|
|
|
2017-02-03 23:07:26 +03:00
|
|
|
QBrush transparentPlaceholderBrush() {
|
|
|
|
auto size = st::transparentPlaceholderSize * cIntRetinaFactor();
|
|
|
|
auto transparent = QImage(2 * size, 2 * size, QImage::Format_ARGB32_Premultiplied);
|
|
|
|
transparent.fill(st::mediaviewTransparentBg->c);
|
|
|
|
{
|
|
|
|
Painter p(&transparent);
|
|
|
|
p.fillRect(rtlrect(0, size, size, size, 2 * size), st::mediaviewTransparentFg);
|
|
|
|
p.fillRect(rtlrect(size, 0, size, size, 2 * size), st::mediaviewTransparentFg);
|
|
|
|
}
|
|
|
|
transparent.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return QBrush(transparent);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2016-06-09 14:51:24 +03:00
|
|
|
namespace internal {
|
|
|
|
|
2016-11-01 15:46:34 +03:00
|
|
|
QImage createCircleMask(int size, QColor bg, QColor fg) {
|
2016-06-09 14:51:24 +03:00
|
|
|
int realSize = size * cIntRetinaFactor();
|
2016-08-29 23:24:16 -06:00
|
|
|
#ifndef OS_MAC_OLD
|
2016-06-09 20:54:31 +03:00
|
|
|
auto result = QImage(realSize, realSize, QImage::Format::Format_Grayscale8);
|
2016-08-29 23:24:16 -06:00
|
|
|
#else // OS_MAC_OLD
|
|
|
|
auto result = QImage(realSize, realSize, QImage::Format::Format_RGB32);
|
|
|
|
#endif // OS_MAC_OLD
|
2016-06-09 14:51:24 +03:00
|
|
|
{
|
2016-12-03 15:10:35 +03:00
|
|
|
Painter p(&result);
|
|
|
|
PainterHighQualityEnabler hq(p);
|
|
|
|
|
|
|
|
p.fillRect(0, 0, realSize, realSize, bg);
|
|
|
|
p.setPen(Qt::NoPen);
|
|
|
|
p.setBrush(fg);
|
|
|
|
p.drawEllipse(0, 0, realSize, realSize);
|
2016-06-09 14:51:24 +03:00
|
|
|
}
|
|
|
|
result.setDevicePixelRatio(cRetinaFactor());
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace internal
|
2016-04-21 20:57:29 +03:00
|
|
|
} // namespace style
|