Custom colors in all media/history_view_ modules.

This commit is contained in:
John Preston 2021-09-03 17:18:03 +03:00
parent cbfe57c51d
commit b2364140e9
24 changed files with 207 additions and 142 deletions

View file

@ -594,14 +594,18 @@ QRect BackgroundPreviewBox::radialRect() const {
void BackgroundPreviewBox::paintTexts(Painter &p, crl::time ms) {
const auto height1 = _text1->height();
const auto height2 = _text2->height();
const auto context = _controller->defaultChatTheme()->preparePaintContext(
auto context = _controller->defaultChatTheme()->preparePaintContext(
_chatStyle.get(),
rect(),
rect());
p.translate(0, textsTop());
paintDate(p);
context.outbg = _text1->hasOutLayout();
_text1->draw(p, context);
p.translate(0, height1);
context.outbg = _text2->hasOutLayout();
_text2->draw(p, context);
p.translate(0, height2);
}

View file

@ -366,7 +366,14 @@ void HistoryMessageReply::paint(
auto to = style::rtlrect(x + st::msgReplyBarSkip, y + st::msgReplyPadding.top() + st::msgReplyBarPos.y(), st::msgReplyBarSize.height(), st::msgReplyBarSize.height(), w + 2 * x);
auto previewWidth = image->width() / cIntRetinaFactor();
auto previewHeight = image->height() / cIntRetinaFactor();
auto preview = image->pixSingle(previewWidth, previewHeight, to.width(), to.height(), ImageRoundRadius::Small, RectPart::AllCorners, context.selected() ? &st->msgStickerOverlay() : nullptr);
auto preview = image->pixSingle(
previewWidth,
previewHeight,
to.width(),
to.height(),
ImageRoundRadius::Small,
RectPart::AllCorners,
context.selected() ? &st->msgStickerOverlay() : nullptr);
p.drawPixmap(to.x(), to.y(), preview);
}
}

View file

@ -55,7 +55,7 @@ ClickHandlerPtr Dice::link() {
return _link;
}
void Dice::draw(Painter &p, const QRect &r, bool selected) {
void Dice::draw(Painter &p, const PaintContext &context, const QRect &r) {
if (!_start) {
if (const auto document = Lookup(_parent, _dice->emoji(), 0)) {
_start.emplace(_parent, document);
@ -74,9 +74,9 @@ void Dice::draw(Painter &p, const QRect &r, bool selected) {
_drawingEnd = false;
}
if (_drawingEnd) {
_end->draw(p, r, selected);
_end->draw(p, context, r);
} else if (_start) {
_start->draw(p, r, selected);
_start->draw(p, context, r);
if (_end && _end->readyToDrawLottie() && _start->atTheEnd()) {
_drawingEnd = true;
}

View file

@ -22,7 +22,10 @@ public:
~Dice();
QSize size() override;
void draw(Painter &p, const QRect &r, bool selected) override;
void draw(
Painter &p,
const PaintContext &context,
const QRect &r) override;
ClickHandlerPtr link() override;

View file

@ -266,7 +266,7 @@ void Game::draw(Painter &p, const PaintContext &context) const {
Ui::FillRoundRect(p, style::rtlrect(gameX, gameY, gameW, gameH, pixwidth), sti->msgDateImgBg, sti->msgDateImgBgCorners);
p.setFont(st::msgDateFont);
p.setPen(st::msgDateImgFg);
p.setPen(st->msgDateImgFg());
p.drawTextLeft(gameX + st::msgDateImgPadding.x(), gameY + st::msgDateImgPadding.y(), pixwidth, tr::lng_game_tag(tr::now).toUpper());
p.translate(-attachLeft, -attachTop);

View file

@ -286,7 +286,6 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
const auto st = context.st;
const auto sti = context.imageStyle();
const auto stm = context.messageStyle();
const auto selected = (context.selection == FullSelection);
const auto autoPaused = _parent->delegate()->elementIsGifPaused();
const auto cornerDownload = downloadInCorner();
const auto canBePlayed = _dataMedia->canBePlayed();
@ -407,7 +406,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
if (const auto playback = videoPlayback()) {
const auto value = playback->value();
if (value > 0.) {
auto pen = st::historyVideoMessageProgressFg->p;
auto pen = st->historyVideoMessageProgressFg()->p;
auto was = p.pen();
pen.setWidth(st::radialLine);
pen.setCapStyle(Qt::RoundCap);
@ -456,13 +455,13 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
| RectPart::NoTopBottom
| (roundTop ? RectPart::Top : RectPart::None)
| (roundBottom ? RectPart::Bottom : RectPart::None);
Ui::FillRoundRect(p, rthumb.marginsAdded({ 0, roundTop ? 0 : margin, 0, roundBottom ? 0 : margin }), st::imageBg, roundRadius, parts);
Ui::FillRoundRect(p, rthumb.marginsAdded({ 0, roundTop ? 0 : margin, 0, roundBottom ? 0 : margin }), st->imageBg(), roundRadius, parts);
}
}
}
}
if (selected) {
if (context.selected()) {
Ui::FillComplexOverlayRect(p, rthumb, roundRadius, roundCorners);
}
@ -479,7 +478,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
const auto innerSize = st::msgFileLayout.thumbSize;
auto inner = QRect(rthumb.x() + (rthumb.width() - innerSize) / 2, rthumb.y() + (rthumb.height() - innerSize) / 2, innerSize, innerSize);
p.setPen(Qt::NoPen);
if (selected) {
if (context.selected()) {
p.setBrush(st->msgDateImgBgSelected());
} else if (isThumbAnimation()) {
auto over = _animation->a_thumbOver.value(1.);
@ -501,14 +500,14 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
if (streamingMode && !_data->uploading()) {
return nullptr;
} else if ((loaded || canBePlayed) && (!radial || cornerDownload)) {
return &(selected ? st::historyFileThumbPlaySelected : st::historyFileThumbPlay);
return &sti->historyFileThumbPlay;
} else if (radial || _data->loading()) {
if (!item->isSending() || _data->uploading()) {
return &(selected ? st::historyFileThumbCancelSelected : st::historyFileThumbCancel);
return &sti->historyFileThumbCancel;
}
return nullptr;
}
return &(selected ? st::historyFileThumbDownloadSelected : st::historyFileThumbDownload);
return &sti->historyFileThumbDownload;
}();
if (icon) {
icon->paintInCenter(p, inner);
@ -516,9 +515,6 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
p.setOpacity(1);
if (radial) {
QRect rinner(inner.marginsRemoved(QMargins(st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine, st::msgFileRadialLine)));
const auto fg = selected
? st::historyFileThumbRadialFgSelected
: st::historyFileThumbRadialFg;
if (streamedForWaiting && !_data->uploading()) {
Ui::InfiniteRadialAnimation::Draw(
p,
@ -526,14 +522,14 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
rinner.topLeft(),
rinner.size(),
width(),
fg,
sti->historyFileThumbRadialFg,
st::msgFileRadialLine);
} else if (!cornerDownload) {
_animation->radial.draw(
p,
rinner,
st::msgFileRadialLine,
fg);
sti->historyFileThumbRadialFg);
}
}
}
@ -543,7 +539,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
p.setBrush(sti->msgDateImgBg);
PainterHighQualityEnabler hq(p);
p.drawEllipse(muteRect);
(selected ? st::historyVideoMessageMuteSelected : st::historyVideoMessageMute).paintInCenter(p, muteRect);
sti->historyVideoMessageMute.paintInCenter(p, muteRect);
}
if (!isRound) {
@ -561,11 +557,11 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
}
Ui::FillRoundRect(p, style::rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), sti->msgServiceBg, sti->msgServiceBgCorners);
p.setFont(st::normalFont);
p.setPen(st::msgServiceFg);
p.setPen(st->msgServiceFg());
p.drawTextLeft(statusX, statusY, width(), _statusText, statusW - 2 * st::msgDateImgPadding.x());
if (mediaUnread) {
p.setPen(Qt::NoPen);
p.setBrush(st::msgServiceFg);
p.setBrush(st->msgServiceFg());
{
PainterHighQualityEnabler hq(p);
@ -591,7 +587,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
if (rtl()) rectx = width() - rectx - rectw;
Ui::FillRoundRect(p, rectx, recty, rectw, recth, sti->msgServiceBg, sti->msgServiceBgCorners);
p.setPen(st::msgServiceFg);
p.setPen(st->msgServiceFg());
rectx += st::msgReplyPadding.left();
rectw = innerw;
if (forwarded) {
@ -611,7 +607,7 @@ void Gif::draw(Painter &p, const PaintContext &context) const {
}
}
if (!isRound && !_caption.isEmpty()) {
p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg));
p.setPen(stm->historyTextFg);
_caption.draw(p, st::msgPadding.left(), painty + painth + st::mediaCaptionSkip, captionw, style::al_left, 0, -1, context.selection);
} else if (!inWebPage) {
auto fullRight = paintx + usex + usew;
@ -695,7 +691,7 @@ void Gif::drawCornerStatus(
const auto statusTextTop = statusY + (cornerDownload ? (((statusH - 2 * st::normalFont->height) / 3) - padding.y()) : 0);
Ui::FillRoundRect(p, around, sti->msgDateImgBg, sti->msgDateImgBgCorners);
p.setFont(st::normalFont);
p.setPen(st::msgDateImgFg);
p.setPen(st->msgDateImgFg());
p.drawTextLeft(statusX + addLeft, statusTextTop, width(), text, statusW - 2 * padding.x());
if (cornerDownload) {
const auto downloadTextTop = statusY + st::normalFont->height + (2 * (statusH - 2 * st::normalFont->height) / 3) - padding.y();

View file

@ -263,7 +263,7 @@ void Invoice::draw(Painter &p, const PaintContext &context) const {
Ui::FillRoundRect(p, style::rtlrect(statusX, statusY, statusW, statusH, pixwidth), sti->msgDateImgBg, sti->msgDateImgBgCorners);
p.setFont(st::msgDateFont);
p.setPen(st::msgDateImgFg);
p.setPen(st->msgDateImgFg());
_status.drawLeftElided(p, statusX + st::msgDateImgPadding.x(), statusY + st::msgDateImgPadding.y(), available, pixwidth);
p.translate(-attachLeft, -attachTop);

View file

@ -13,6 +13,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/history_item.h"
#include "history/history.h"
#include "ui/image/image.h"
#include "ui/chat/chat_style.h"
#include "data/data_file_origin.h"
#include "styles/style_chat.h"
@ -65,7 +66,10 @@ QSize LargeEmoji::size() {
return _size;
}
void LargeEmoji::draw(Painter &p, const QRect &r, bool selected) {
void LargeEmoji::draw(
Painter &p,
const PaintContext &context,
const QRect &r) {
auto &&images = NonEmpty(_images);
const auto &padding = st::largeEmojiPadding;
auto x = r.x() + (r.width() - _size.width()) / 2 + padding.left();
@ -76,9 +80,8 @@ void LargeEmoji::draw(Painter &p, const QRect &r, bool selected) {
const auto w = size.width();
if (const auto &prepared = image->image) {
const auto h = size.height();
const auto &c = st::msgStickerOverlay;
const auto pixmap = selected
? prepared->pixColored(c, w, h)
const auto pixmap = context.selected()
? prepared->pixColored(context.st->msgStickerOverlay(), w, h)
: prepared->pix(w, h);
p.drawPixmap(x, y, pixmap);
} else if (image->load) {

View file

@ -27,7 +27,10 @@ public:
const Ui::Text::IsolatedEmoji &emoji);
QSize size() override;
void draw(Painter &p, const QRect &r, bool selected) override;
void draw(
Painter &p,
const PaintContext &context,
const QRect &r) override;
bool alwaysShowOutTimestamp() override {
return true;

View file

@ -152,6 +152,7 @@ void Location::draw(Painter &p, const PaintContext &context) const {
if (width() < st::msgPadding.left() + st::msgPadding.right() + 1) return;
auto paintx = 0, painty = 0, paintw = width(), painth = height();
bool bubble = _parent->hasBubble();
const auto st = context.st;
const auto sti = context.imageStyle();
const auto stm = context.messageStyle();
@ -200,8 +201,8 @@ void Location::draw(Painter &p, const PaintContext &context) const {
rthumb.y() + (rthumb.height() / 2) - icon.height(),
width());
};
paintMarker(st::historyMapPoint);
paintMarker(st::historyMapPointInner);
paintMarker(st->historyMapPoint());
paintMarker(st->historyMapPointInner());
if (context.selected()) {
Ui::FillComplexOverlayRect(p, rthumb, roundRadius, roundCorners);
}

View file

@ -335,15 +335,14 @@ void GroupedMedia::draw(Painter &p, const PaintContext &context) const {
}
// date
const auto selected = (selection == FullSelection);
if (!_caption.isEmpty()) {
const auto captionw = width() - st::msgPadding.left() - st::msgPadding.right();
const auto outbg = _parent->hasOutLayout();
const auto captiony = height()
- groupPadding.bottom()
- (isBubbleBottom() ? st::msgPadding.bottom() : 0)
- _caption.countHeight(captionw);
p.setPen(outbg ? (selected ? st::historyTextOutFgSelected : st::historyTextOutFg) : (selected ? st::historyTextInFgSelected : st::historyTextInFg));
const auto stm = context.messageStyle();
p.setPen(stm->historyTextFg);
_caption.draw(p, st::msgPadding.left(), captiony, captionw, style::al_left, 0, -1, selection);
} else if (_parent->media() == this) {
auto fullRight = width();

View file

@ -137,7 +137,7 @@ void UnwrappedMedia::draw(Painter &p, const PaintContext &context) const {
height() - st::msgDateImgPadding.y() * 2 - st::msgDateFont->height)
: _contentSize.height();
const auto inner = QRect(usex, usey, usew, useh);
_content->draw(p, inner, selected);
_content->draw(p, context, inner);
if (!inWebPage) {
drawSurrounding(p, inner, context, via, reply, forwarded);
@ -205,7 +205,7 @@ void UnwrappedMedia::drawSurrounding(
if (rtl()) rectx = width() - rectx - rectw;
Ui::FillRoundRect(p, rectx, recty, rectw, recth, sti->msgServiceBg, sti->msgServiceBgCorners);
p.setPen(st::msgServiceFg);
p.setPen(st->msgServiceFg());
rectx += st::msgReplyPadding.left();
rectw -= st::msgReplyPadding.left() + st::msgReplyPadding.right();
if (forwarded) {

View file

@ -23,7 +23,10 @@ public:
public:
[[nodiscard]] virtual QSize size() = 0;
virtual void draw(Painter &p, const QRect &r, bool selected) = 0;
virtual void draw(
Painter &p,
const PaintContext &context,
const QRect &r) = 0;
[[nodiscard]] virtual ClickHandlerPtr link() {
return nullptr;

View file

@ -723,10 +723,7 @@ void Poll::draw(Painter &p, const PaintContext &context) const {
checkSendingAnimation();
_poll->checkResultsReload(_parent->data(), context.now);
const auto outbg = _parent->hasOutLayout();
const auto selected = (context.selection == FullSelection);
const auto &regular = selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg);
const auto stm = context.messageStyle();
const auto padding = st::msgPadding;
auto tshift = st::historyPollQuestionTop;
if (!isBubbleTop()) {
@ -734,11 +731,11 @@ void Poll::draw(Painter &p, const PaintContext &context) const {
}
paintw -= padding.left() + padding.right();
p.setPen(outbg ? st::webPageTitleOutFg : st::webPageTitleInFg);
p.setPen(stm->webPageTitleFg);
_question.drawLeft(p, padding.left(), tshift, paintw, width(), style::al_left, 0, -1, context.selection);
tshift += _question.countHeight(paintw) + st::historyPollSubtitleSkip;
p.setPen(regular);
p.setPen(stm->msgDateFg);
_subtitle.drawLeftElided(p, padding.left(), tshift, paintw, width());
paintRecentVoters(p, padding.left() + _subtitle.maxWidth(), tshift, context);
paintCloseByTimer(p, padding.left() + paintw, tshift, context);
@ -791,10 +788,8 @@ void Poll::paintInlineFooter(
int top,
int paintw,
const PaintContext &context) const {
const auto selected = context.selected();
const auto outbg = _parent->hasOutLayout();
const auto &regular = selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg);
p.setPen(regular);
const auto stm = context.messageStyle();
p.setPen(stm->msgDateFg);
_totalVotesLabel.drawLeftElided(
p,
left,
@ -812,11 +807,9 @@ void Poll::paintBottom(
int paintw,
const PaintContext &context) const {
const auto stringtop = top + st::msgPadding.bottom() + st::historyPollBottomButtonTop;
const auto selected = context.selected();
const auto outbg = _parent->hasOutLayout();
const auto &regular = selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg);
const auto stm = context.messageStyle();
if (showVotersCount()) {
p.setPen(regular);
p.setPen(stm->msgDateFg);
_totalVotesLabel.draw(p, left, stringtop, paintw, style::al_top);
} else {
const auto link = showVotes()
@ -834,11 +827,7 @@ void Poll::paintBottom(
p.setOpacity(1.);
}
p.setFont(st::semiboldFont);
if (!link) {
p.setPen(regular);
} else {
p.setPen(outbg ? (selected ? st::msgFileThumbLinkOutFgSelected : st::msgFileThumbLinkOutFg) : (selected ? st::msgFileThumbLinkInFgSelected : st::msgFileThumbLinkInFg));
}
p.setPen(link ? stm->msgFileThumbLinkFg : stm->msgDateFg);
const auto string = showVotes()
? tr::lng_polls_view_results(tr::now, Ui::Text::Upper)
: tr::lng_polls_submit_votes(tr::now, Ui::Text::Upper);
@ -875,11 +864,8 @@ void Poll::paintRecentVoters(
+ (count - 1) * st::historyPollRecentVoterSkip;
auto y = top;
const auto size = st::historyPollRecentVoterSize;
const auto outbg = _parent->hasOutLayout();
const auto selected = (context.selection == FullSelection);
auto pen = (selected
? (outbg ? st::msgOutBgSelected : st::msgInBgSelected)
: (outbg ? st::msgOutBg : st::msgInBg))->p;
const auto stm = context.messageStyle();
auto pen = stm->msgBg->p;
pen.setWidth(st::lineWidth);
auto created = false;
@ -947,22 +933,16 @@ void Poll::paintCloseByTimer(
_close->radial.stop();
}
const auto time = Ui::FormatDurationText(int(std::ceil(left / 1000.)));
const auto outbg = _parent->hasOutLayout();
const auto selected = context.selected();
const auto &icon = selected
? (outbg
? st::historyQuizTimerOutSelected
: st::historyQuizTimerInSelected)
: (outbg ? st::historyQuizTimerOut : st::historyQuizTimerIn);
const auto st = context.st;
const auto stm = context.messageStyle();
const auto &icon = stm->historyQuizTimer;
const auto x = right - icon.width();
const auto y = top
+ (st::normalFont->height - icon.height()) / 2
- st::lineWidth;
const auto &regular = (left < kCriticalCloseDuration)
? st::boxTextFgError
: selected
? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected)
: (outbg ? st::msgOutDateFg : st::msgInDateFg);
? st->boxTextFgError()
: stm->msgDateFg;
p.setPen(regular);
const auto timeWidth = st::normalFont->width(time);
p.drawTextLeft(x - timeWidth, top, width(), time, timeWidth);
@ -1004,12 +984,8 @@ void Poll::paintShowSolution(
_showSolutionLink = std::make_shared<LambdaClickHandler>(
crl::guard(this, [=] { showSolution(); }));
}
const auto outbg = _parent->hasOutLayout();
const auto &icon = context.selected()
? (outbg
? st::historyQuizExplainOutSelected
: st::historyQuizExplainInSelected)
: (outbg ? st::historyQuizExplainOut : st::historyQuizExplainIn);
const auto stm = context.messageStyle();
const auto &icon = stm->historyQuizExplain;
const auto x = right - icon.width();
const auto y = top + (st::normalFont->height - icon.height()) / 2;
if (shown == 1.) {
@ -1034,7 +1010,7 @@ int Poll::paintAnswer(
int outerWidth,
const PaintContext &context) const {
const auto height = countAnswerHeight(answer, width);
const auto outbg = _parent->hasOutLayout();
const auto stm = context.messageStyle();
const auto aleft = left + st::historyPollAnswerPadding.left();
const auto awidth = width
- st::historyPollAnswerPadding.left()
@ -1106,7 +1082,7 @@ int Poll::paintAnswer(
}
top += st::historyPollAnswerPadding.top();
p.setPen(outbg ? st::webPageDescriptionOutFg : st::webPageDescriptionInFg);
p.setPen(stm->webPageDescriptionFg);
answer.text.drawLeft(p, aleft, top, awidth, outerWidth);
return height;
@ -1120,14 +1096,13 @@ void Poll::paintRadio(
const PaintContext &context) const {
top += st::historyPollAnswerPadding.top();
const auto outbg = _parent->hasOutLayout();
const auto selected = context.selected();
const auto st = context.st;
const auto stm = context.messageStyle();
PainterHighQualityEnabler hq(p);
const auto &radio = st::historyPollRadio;
const auto over = ClickHandler::showAsActive(answer.handler);
const auto &regular = selected ? (outbg ? st::msgOutDateFgSelected : st::msgInDateFgSelected) : (outbg ? st::msgOutDateFg : st::msgInDateFg);
const auto &regular = stm->msgDateFg;
const auto checkmark = answer.selectedAnimation.value(answer.selected ? 1. : 0.);
@ -1139,11 +1114,7 @@ void Poll::paintRadio(
const auto rect = QRectF(left, top, radio.diameter, radio.diameter).marginsRemoved(QMarginsF(radio.thickness / 2., radio.thickness / 2., radio.thickness / 2., radio.thickness / 2.));
if (_sendingAnimation && _sendingAnimation->option == answer.option) {
const auto &active = selected
? (outbg
? st::msgOutServiceFgSelected
: st::msgInServiceFgSelected)
: (outbg ? st->msgOutServiceFg() : st->msgInServiceFg());
const auto &active = stm->msgServiceFg;
if (anim::Disabled()) {
anim::DrawStaticLoading(p, rect, radio.thickness, active);
} else {
@ -1167,13 +1138,13 @@ void Poll::paintRadio(
if (checkmark > 0.) {
const auto removeFull = (radio.diameter / 2 - radio.thickness);
const auto removeNow = removeFull * (1. - checkmark);
const auto color = outbg ? (selected ? st::msgFileThumbLinkOutFgSelected : st::msgFileThumbLinkOutFg) : (selected ? st::msgFileThumbLinkInFgSelected : st::msgFileThumbLinkInFg);
const auto color = stm->msgFileThumbLinkFg;
auto pen = color->p;
pen.setWidth(radio.thickness);
p.setPen(pen);
p.setBrush(color);
p.drawEllipse(rect.marginsRemoved({ removeNow, removeNow, removeNow, removeNow }));
const auto &icon = outbg ? (selected ? st::historyPollOutChosenSelected : st::historyPollOutChosen) : (selected ? st::historyPollInChosenSelected : st::historyPollInChosen);
const auto &icon = stm->historyPollChosen;
icon.paint(p, left + (radio.diameter - icon.width()) / 2, top + (radio.diameter - icon.height()) / 2, width());
}
}
@ -1189,13 +1160,13 @@ void Poll::paintPercent(
int top,
int outerWidth,
const PaintContext &context) const {
const auto outbg = _parent->hasOutLayout();
const auto stm = context.messageStyle();
const auto aleft = left + st::historyPollAnswerPadding.left();
top += st::historyPollAnswerPadding.top();
p.setFont(st::historyPollPercentFont);
p.setPen(outbg ? st::webPageDescriptionOutFg : st::webPageDescriptionInFg);
p.setPen(stm->webPageDescriptionFg);
const auto pleft = aleft - percentWidth - st::historyPollPercentSkip;
p.drawTextLeft(pleft, top + st::historyPollPercentTop, outerWidth, percent, percentWidth);
}
@ -1211,8 +1182,8 @@ void Poll::paintFilling(
int height,
const PaintContext &context) const {
const auto bottom = top + height;
const auto outbg = _parent->hasOutLayout();
const auto selected = context.selected();
const auto st = context.st;
const auto stm = context.messageStyle();
const auto aleft = left + st::historyPollAnswerPadding.left();
const auto awidth = width
- st::historyPollAnswerPadding.left()
@ -1229,19 +1200,18 @@ void Poll::paintFilling(
const auto ftop = bottom - st::historyPollFillingBottom - thickness;
if (chosen && !correct) {
p.setBrush(st::boxTextFgError);
} else if (chosen && correct && _poll->quiz() && !outbg) {
p.setBrush(st::boxTextFgGood);
p.setBrush(st->boxTextFgError());
} else if (chosen && correct && _poll->quiz() && !context.outbg) {
p.setBrush(st->boxTextFgGood());
} else {
const auto bar = outbg ? (selected ? st::msgWaveformOutActiveSelected : st::msgWaveformOutActive) : (selected ? st::msgWaveformInActiveSelected : st::msgWaveformInActive);
p.setBrush(bar);
p.setBrush(stm->msgWaveformActive);
}
auto barleft = aleft;
auto barwidth = size;
if (chosen || correct) {
const auto &icon = (chosen && !correct)
? st::historyPollChoiceWrong
: st::historyPollChoiceRight;
? st->historyPollChoiceWrong()
: st->historyPollChoiceRight();
const auto cleft = aleft - st::historyPollPercentSkip - icon.width();
const auto ctop = ftop - (icon.height() - thickness) / 2;
p.drawEllipse(cleft, ctop, icon.width(), icon.height());

View file

@ -148,7 +148,10 @@ ClickHandlerPtr SlotMachine::link() {
return _link;
}
void SlotMachine::draw(Painter &p, const QRect &r, bool selected) {
void SlotMachine::draw(
Painter &p,
const PaintContext &context,
const QRect &r) {
resolveStarts(true);
resolveEnds(_dice->value());
@ -194,9 +197,9 @@ void SlotMachine::draw(Painter &p, const QRect &r, bool selected) {
for (auto i = 0; i != 4; ++i) {
if (switchedToEnd[i]) {
_end[i]->draw(p, r, selected);
_end[i]->draw(p, context, r);
} else {
_start[i]->draw(p, r, selected);
_start[i]->draw(p, context, r);
if (_end[i]
&& _end[i]->readyToDrawLottie()
&& _start[i]->atTheEnd()) {
@ -204,7 +207,7 @@ void SlotMachine::draw(Painter &p, const QRect &r, bool selected) {
}
}
}
_pull->draw(p, r, selected);
_pull->draw(p, context, r);
}
} // namespace HistoryView

View file

@ -22,7 +22,10 @@ public:
~SlotMachine();
QSize size() override;
void draw(Painter &p, const QRect &r, bool selected) override;
void draw(
Painter &p,
const PaintContext &context,
const QRect &r) override;
ClickHandlerPtr link() override;

View file

@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "history/view/history_view_cursor_state.h"
#include "history/view/media/history_view_media_common.h"
#include "ui/image/image.h"
#include "ui/chat/chat_style.h"
#include "ui/effects/path_shift_gradient.h"
#include "ui/emoji_config.h"
#include "core/application.h"
@ -148,22 +149,28 @@ QSize Sticker::GetAnimatedEmojiSize(
return { convert(documentSize.width()), convert(documentSize.height()) };
}
void Sticker::draw(Painter &p, const QRect &r, bool selected) {
void Sticker::draw(
Painter &p,
const PaintContext &context,
const QRect &r) {
ensureDataMediaCreated();
if (readyToDrawLottie()) {
paintLottie(p, r, selected);
paintLottie(p, context, r);
} else if (!_data->sticker()
|| (_data->sticker()->animated && _replacements)
|| !paintPixmap(p, r, selected)) {
paintPath(p, r, selected);
|| !paintPixmap(p, context, r)) {
paintPath(p, context, r);
}
}
void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) {
void Sticker::paintLottie(
Painter &p,
const PaintContext &context,
const QRect &r) {
auto request = Lottie::FrameRequest();
request.box = _size * cIntRetinaFactor();
if (selected && !_nextLastDiceFrame) {
request.colored = st::msgStickerOverlay->c;
if (context.selected() && !_nextLastDiceFrame) {
request.colored = context.st->msgStickerOverlay()->c;
}
const auto frame = _lottie
? _lottie->frameInfo(request)
@ -175,8 +182,8 @@ void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) {
const auto &image = _lastDiceFrame.isNull()
? frame.image
: _lastDiceFrame;
const auto prepared = (!_lastDiceFrame.isNull() && selected)
? Images::prepareColored(st::msgStickerOverlay->c, image)
const auto prepared = (!_lastDiceFrame.isNull() && context.selected())
? Images::prepareColored(context.st->msgStickerOverlay()->c, image)
: image;
const auto size = prepared.size() / cIntRetinaFactor();
p.drawImage(
@ -216,8 +223,11 @@ void Sticker::paintLottie(Painter &p, const QRect &r, bool selected) {
}
}
bool Sticker::paintPixmap(Painter &p, const QRect &r, bool selected) {
const auto pixmap = paintedPixmap(selected);
bool Sticker::paintPixmap(
Painter &p,
const PaintContext &context,
const QRect &r) {
const auto pixmap = paintedPixmap(context);
if (pixmap.isNull()) {
return false;
}
@ -229,16 +239,19 @@ bool Sticker::paintPixmap(Painter &p, const QRect &r, bool selected) {
return true;
}
void Sticker::paintPath(Painter &p, const QRect &r, bool selected) {
void Sticker::paintPath(
Painter &p,
const PaintContext &context,
const QRect &r) {
const auto pathGradient = _parent->delegate()->elementPathShiftGradient();
if (selected) {
if (context.selected()) {
pathGradient->overrideColors(
st::msgServiceBgSelected,
st::msgServiceBg);
context.st->msgServiceBgSelected(),
context.st->msgServiceBg());
} else {
pathGradient->clearOverridenColors();
}
p.setBrush(selected ? st::msgServiceBgSelected : st::msgServiceBg);
p.setBrush(context.imageStyle()->msgServiceBg);
ChatHelpers::PaintStickerThumbnailPath(
p,
_dataMedia.get(),
@ -246,28 +259,28 @@ void Sticker::paintPath(Painter &p, const QRect &r, bool selected) {
pathGradient);
}
QPixmap Sticker::paintedPixmap(bool selected) const {
QPixmap Sticker::paintedPixmap(const PaintContext &context) const {
const auto w = _size.width();
const auto h = _size.height();
const auto &c = st::msgStickerOverlay;
const auto &c = context.st->msgStickerOverlay();
const auto good = _dataMedia->goodThumbnail();
if (const auto image = _dataMedia->getStickerLarge()) {
return selected
return context.selected()
? image->pixColored(c, w, h)
: image->pix(w, h);
//
// Inline thumbnails can't have alpha channel.
//
//} else if (const auto blurred = _data->thumbnailInline()) {
// return selected
// return context.selected()
// ? blurred->pixBlurredColored(c, w, h)
// : blurred->pixBlurred(w, h);
} else if (good) {
return selected
return context.selected()
? good->pixColored(c, w, h)
: good->pix(w, h);
} else if (const auto thumbnail = _dataMedia->thumbnail()) {
return selected
return context.selected()
? thumbnail->pixBlurredColored(c, w, h)
: thumbnail->pixBlurred(w, h);
}

View file

@ -39,7 +39,10 @@ public:
void initSize();
QSize size() override;
void draw(Painter &p, const QRect &r, bool selected) override;
void draw(
Painter &p,
const PaintContext &context,
const QRect &r) override;
ClickHandlerPtr link() override {
return _link;
}
@ -83,10 +86,10 @@ public:
private:
[[nodiscard]] bool isEmojiSticker() const;
void paintLottie(Painter &p, const QRect &r, bool selected);
bool paintPixmap(Painter &p, const QRect &r, bool selected);
void paintPath(Painter &p, const QRect &r, bool selected);
[[nodiscard]] QPixmap paintedPixmap(bool selected) const;
void paintLottie(Painter &p, const PaintContext &context, const QRect &r);
bool paintPixmap(Painter &p, const PaintContext &context, const QRect &r);
void paintPath(Painter &p, const PaintContext &context, const QRect &r);
[[nodiscard]] QPixmap paintedPixmap(const PaintContext &context) const;
void ensureDataMediaCreated() const;
void dataMediaCreated() const;

View file

@ -190,7 +190,7 @@ void ThemeDocument::draw(Painter &p, const PaintContext &context) const {
auto statusH = st::normalFont->height + 2 * st::msgDateImgPadding.y();
Ui::FillRoundRect(p, style::rtlrect(statusX - st::msgDateImgPadding.x(), statusY - st::msgDateImgPadding.y(), statusW, statusH, width()), sti->msgDateImgBg, sti->msgDateImgBgCorners);
p.setFont(st::normalFont);
p.setPen(st::msgDateImgFg);
p.setPen(st->msgDateImgFg());
p.drawTextLeft(statusX, statusY, width(), _statusText, statusW - 2 * st::msgDateImgPadding.x());
if (radial || (!loaded && !_data->loading())) {
const auto radialOpacity = (radial && loaded && !_data->uploading())

View file

@ -563,9 +563,9 @@ void WebPage::draw(Painter &p, const PaintContext &context) const {
&& !_data->document) {
if (_attach->isReadyForOpen()) {
if (_data->siteName == qstr("YouTube")) {
st::youtubeIcon.paint(p, (pixwidth - st::youtubeIcon.width()) / 2, (pixheight - st::youtubeIcon.height()) / 2, width());
st->youtubeIcon().paint(p, (pixwidth - st::youtubeIcon.width()) / 2, (pixheight - st::youtubeIcon.height()) / 2, width());
} else {
st::videoIcon.paint(p, (pixwidth - st::videoIcon.width()) / 2, (pixheight - st::videoIcon.height()) / 2, width());
st->videoIcon().paint(p, (pixwidth - st::videoIcon.width()) / 2, (pixheight - st::videoIcon.height()) / 2, width());
}
}
if (_durationWidth) {
@ -577,7 +577,7 @@ void WebPage::draw(Painter &p, const PaintContext &context) const {
Ui::FillRoundRect(p, dateX, dateY, dateW, dateH, sti->msgDateImgBg, sti->msgDateImgBgCorners);
p.setFont(st::msgDateFont);
p.setPen(st::msgDateImgFg);
p.setPen(st->msgDateImgFg());
p.drawTextLeft(dateX + st::msgDateImgPadding.x(), dateY + st::msgDateImgPadding.y(), pixwidth, _duration);
}
}

View file

@ -719,11 +719,12 @@ object_ptr<Ui::RpWidget> ForwardsPrivacyController::setupAboveWidget(
Painter p(widget);
const auto theme = _controller->defaultChatTheme().get();
const auto context = theme->preparePaintContext(
auto context = theme->preparePaintContext(
_chatStyle.get(),
widget->rect(),
widget->rect());
p.translate(0, padding + view->marginBottom());
context.outbg = view->hasOutLayout();
view->draw(p, context);
PaintForwardedTooltip(p, view, *option);

View file

@ -570,15 +570,17 @@ void ConfirmContactBox::paintEvent(QPaintEvent *e) {
p.fillRect(e->rect(), st::boxBg);
const auto theme = controller()->defaultChatTheme().get();
const auto context = theme->preparePaintContext(
auto context = theme->preparePaintContext(
_chatStyle.get(),
rect(),
rect());
p.translate(st::boxPadding.left(), 0);
if (_comment) {
context.outbg = _comment->hasOutLayout();
_comment->draw(p, context);
p.translate(0, _comment->height());
}
context.outbg = _contact->hasOutLayout();
_contact->draw(p, context);
}

View file

@ -82,6 +82,12 @@ ChatStyle::ChatStyle() {
make(_historyFastCommentsIcon, st::historyFastCommentsIcon);
make(_historyFastShareIcon, st::historyFastShareIcon);
make(_historyGoToOriginalIcon, st::historyGoToOriginalIcon);
make(_historyMapPoint, st::historyMapPoint);
make(_historyMapPointInner, st::historyMapPointInner);
make(_youtubeIcon, st::youtubeIcon);
make(_videoIcon, st::videoIcon);
make(_historyPollChoiceRight, st::historyPollChoiceRight);
make(_historyPollChoiceWrong, st::historyPollChoiceWrong);
make(
&MessageStyle::msgBg,
st::msgInBg,
@ -334,6 +340,24 @@ ChatStyle::ChatStyle() {
st::historyAudioInCancelSelected,
st::historyAudioOutCancel,
st::historyAudioOutCancelSelected);
make(
&MessageStyle::historyQuizTimer,
st::historyQuizTimerIn,
st::historyQuizTimerInSelected,
st::historyQuizTimerOut,
st::historyQuizTimerOutSelected);
make(
&MessageStyle::historyQuizExplain,
st::historyQuizExplainIn,
st::historyQuizExplainInSelected,
st::historyQuizExplainOut,
st::historyQuizExplainOutSelected);
make(
&MessageStyle::historyPollChosen,
st::historyPollInChosen,
st::historyPollInChosenSelected,
st::historyPollOutChosen,
st::historyPollOutChosenSelected);
make(
&MessageImageStyle::msgDateImgBg,
st::msgDateImgBg,

View file

@ -61,6 +61,9 @@ struct MessageStyle {
style::icon historyFileDocument = { Qt::Uninitialized };
style::icon historyAudioDownload = { Qt::Uninitialized };
style::icon historyAudioCancel = { Qt::Uninitialized };
style::icon historyQuizTimer = { Qt::Uninitialized };
style::icon historyQuizExplain = { Qt::Uninitialized };
style::icon historyPollChosen = { Qt::Uninitialized };
};
struct MessageImageStyle {
@ -195,6 +198,24 @@ public:
[[nodiscard]] const style::icon &historyGoToOriginalIcon() const {
return _historyGoToOriginalIcon;
}
[[nodiscard]] const style::icon &historyMapPoint() const {
return _historyMapPoint;
}
[[nodiscard]] const style::icon &historyMapPointInner() const {
return _historyMapPointInner;
}
[[nodiscard]] const style::icon &youtubeIcon() const {
return _youtubeIcon;
}
[[nodiscard]] const style::icon &videoIcon() const {
return _videoIcon;
}
[[nodiscard]] const style::icon &historyPollChoiceRight() const {
return _historyPollChoiceRight;
}
[[nodiscard]] const style::icon &historyPollChoiceWrong() const {
return _historyPollChoiceWrong;
}
private:
void assignPalette(not_null<const style::palette*> palette);
@ -255,6 +276,12 @@ private:
style::icon _historyFastCommentsIcon = { Qt::Uninitialized };
style::icon _historyFastShareIcon = { Qt::Uninitialized };
style::icon _historyGoToOriginalIcon = { Qt::Uninitialized };
style::icon _historyMapPoint = { Qt::Uninitialized };
style::icon _historyMapPointInner = { Qt::Uninitialized };
style::icon _youtubeIcon = { Qt::Uninitialized };
style::icon _videoIcon = { Qt::Uninitialized };
style::icon _historyPollChoiceRight = { Qt::Uninitialized };
style::icon _historyPollChoiceWrong = { Qt::Uninitialized };
rpl::lifetime _defaultPaletteChangeLifetime;