2020-03-04 09:21:19 +00:00
|
|
|
/*
|
|
|
|
This file is part of Telegram Desktop,
|
|
|
|
the official desktop application for the Telegram messaging service.
|
|
|
|
|
|
|
|
For license and copyright information please follow this link:
|
|
|
|
https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
|
|
|
|
*/
|
|
|
|
#include "history/view/media/history_view_dice.h"
|
|
|
|
|
|
|
|
#include "data/data_session.h"
|
|
|
|
#include "chat_helpers/stickers_dice_pack.h"
|
|
|
|
#include "history/history.h"
|
|
|
|
#include "history/history_item.h"
|
2020-03-06 09:48:29 +00:00
|
|
|
#include "history/history_item_components.h"
|
2020-03-04 09:21:19 +00:00
|
|
|
#include "history/view/history_view_element.h"
|
|
|
|
#include "main/main_session.h"
|
|
|
|
|
|
|
|
namespace HistoryView {
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
DocumentData *Lookup(not_null<Element*> view, int value) {
|
|
|
|
const auto &session = view->data()->history()->session();
|
|
|
|
return session.diceStickersPack().lookup(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2020-03-06 12:12:03 +00:00
|
|
|
Dice::Dice(not_null<Element*> parent, not_null<Data::MediaDice*> dice)
|
2020-03-04 09:21:19 +00:00
|
|
|
: _parent(parent)
|
2020-03-06 12:12:03 +00:00
|
|
|
, _dice(dice)
|
|
|
|
, _start(parent, Lookup(parent, 0)) {
|
2020-03-06 09:48:29 +00:00
|
|
|
_showLastFrame = _parent->data()->Has<HistoryMessageForwarded>();
|
|
|
|
if (_showLastFrame) {
|
|
|
|
_drawingEnd = true;
|
|
|
|
} else {
|
|
|
|
_start.setDiceIndex(0);
|
|
|
|
}
|
2020-03-04 09:21:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Dice::~Dice() = default;
|
|
|
|
|
|
|
|
QSize Dice::size() {
|
|
|
|
return _start.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Dice::draw(Painter &p, const QRect &r, bool selected) {
|
2020-03-06 12:12:03 +00:00
|
|
|
if (const auto value = _end ? 0 : _dice->diceValue()) {
|
|
|
|
if (const auto document = Lookup(_parent, value)) {
|
2020-03-06 09:48:29 +00:00
|
|
|
_end.emplace(_parent, document);
|
2020-03-06 12:12:03 +00:00
|
|
|
_end->setDiceIndex(value);
|
2020-03-06 09:48:29 +00:00
|
|
|
_end->initSize();
|
|
|
|
}
|
|
|
|
}
|
2020-03-04 09:21:19 +00:00
|
|
|
if (_drawingEnd) {
|
|
|
|
_end->draw(p, r, selected);
|
|
|
|
} else {
|
|
|
|
_start.draw(p, r, selected);
|
|
|
|
if (_end && _end->readyToDrawLottie() && _start.atTheEnd()) {
|
|
|
|
_drawingEnd = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace HistoryView
|