2016-04-21 20:57:29 +03:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop version of Telegram messaging app, see https://telegram.org
|
|
|
|
|
|
|
|
Telegram Desktop is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
It is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
In addition, as a special exception, the copyright holders give permission
|
|
|
|
to link the code of portions of this program with the OpenSSL library.
|
|
|
|
|
|
|
|
Full license: https://github.com/telegramdesktop/tdesktop/blob/master/LICENSE
|
2017-01-11 22:31:31 +04:00
|
|
|
Copyright (c) 2014-2017 John Preston, https://desktop.telegram.org
|
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() {
|
|
|
|
if (cRetina()) {
|
|
|
|
cSetRealScale(dbisOne);
|
|
|
|
}
|
|
|
|
|
|
|
|
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) {
|
|
|
|
if (srcRect.isNull()) {
|
|
|
|
srcRect = src.rect();
|
|
|
|
} else {
|
|
|
|
t_assert(src.rect().contains(srcRect));
|
|
|
|
}
|
|
|
|
auto width = srcRect.width();
|
|
|
|
auto height = srcRect.height();
|
|
|
|
t_assert(outResult && outResult->rect().contains(QRect(dstPoint, srcRect.size())));
|
|
|
|
|
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;
|
2016-11-01 15:46:34 +03:00
|
|
|
t_assert(resultIntsAdded >= 0);
|
2016-11-03 13:58:10 +03:00
|
|
|
t_assert(outResult->depth() == static_cast<int>((resultIntsPerPixel * sizeof(uint32)) << 3));
|
2016-11-02 17:44:33 +03:00
|
|
|
t_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;
|
2016-11-01 15:46:34 +03:00
|
|
|
t_assert(maskBytesAdded >= 0);
|
|
|
|
t_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
|