send_action_animations.cpp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. This file is part of Telegram Desktop,
  3. the official desktop application for the Telegram messaging service.
  4. For license and copyright information please follow this link:
  5. https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
  6. */
  7. #include "ui/effects/send_action_animations.h"
  8. #include "api/api_send_progress.h"
  9. #include "base/never_freed_pointer.h"
  10. #include "ui/effects/animation_value.h"
  11. #include "ui/painter.h"
  12. #include "styles/style_widgets.h"
  13. #include "styles/style_dialogs.h"
  14. namespace Ui {
  15. namespace {
  16. constexpr int kTypingDotsCount = 3;
  17. constexpr int kRecordArcsCount = 4;
  18. constexpr int kUploadArrowsCount = 3;
  19. constexpr auto kSpeakingDuration = 3200;
  20. constexpr auto kSpeakingFadeDuration = 400;
  21. } // namespace
  22. class SendActionAnimation::Impl {
  23. public:
  24. using Type = Api::SendProgressType;
  25. Impl(int period) : _period(period), _started(crl::now()) {
  26. }
  27. struct MetaData {
  28. int index;
  29. std::unique_ptr<Impl>(*creator)();
  30. };
  31. virtual const MetaData *metaData() const = 0;
  32. bool supports(Type type) const;
  33. virtual int width() const = 0;
  34. virtual int widthNoMargins() const {
  35. return width();
  36. }
  37. virtual void paint(
  38. QPainter &p,
  39. style::color color,
  40. int x,
  41. int y,
  42. int outerWidth,
  43. crl::time now) = 0;
  44. virtual void restartedAt(crl::time now) {
  45. }
  46. virtual bool finishNow() {
  47. return true;
  48. }
  49. virtual ~Impl() = default;
  50. protected:
  51. [[nodiscard]] int period() const {
  52. return _period;
  53. }
  54. [[nodiscard]] crl::time started() const {
  55. return _started;
  56. }
  57. [[nodiscard]] int frameTime(crl::time now) const {
  58. return anim::Disabled()
  59. ? 0
  60. : (std::max(now - _started, crl::time(0)) % _period);
  61. }
  62. private:
  63. int _period = 1;
  64. crl::time _started = 0;
  65. };
  66. namespace {
  67. using ImplementationsMap = QMap<
  68. Api::SendProgressType,
  69. const SendActionAnimation::Impl::MetaData*>;
  70. base::NeverFreedPointer<ImplementationsMap> Implementations;
  71. class TypingAnimation : public SendActionAnimation::Impl {
  72. public:
  73. TypingAnimation() : Impl(st::historySendActionTypingDuration) {
  74. }
  75. static const MetaData kMeta;
  76. static std::unique_ptr<Impl> create() {
  77. return std::make_unique<TypingAnimation>();
  78. }
  79. const MetaData *metaData() const override {
  80. return &kMeta;
  81. }
  82. int width() const override {
  83. return st::historySendActionTypingPosition.x()
  84. + kTypingDotsCount * st::historySendActionTypingDelta;
  85. }
  86. void paint(
  87. QPainter &p,
  88. style::color color,
  89. int x,
  90. int y,
  91. int outerWidth,
  92. crl::time now) override;
  93. };
  94. const TypingAnimation::MetaData TypingAnimation::kMeta = {
  95. 0,
  96. &TypingAnimation::create,
  97. };
  98. void TypingAnimation::paint(
  99. QPainter &p,
  100. style::color color,
  101. int x,
  102. int y,
  103. int outerWidth,
  104. crl::time now) {
  105. PainterHighQualityEnabler hq(p);
  106. p.setPen(Qt::NoPen);
  107. p.setBrush(color);
  108. auto frameMs = frameTime(now);
  109. auto position = QPointF(x + 0.5, y - 0.5)
  110. + st::historySendActionTypingPosition;
  111. for (auto i = 0; i != kTypingDotsCount; ++i) {
  112. auto r = st::historySendActionTypingSmallNumerator
  113. / st::historySendActionTypingDenominator;
  114. if (frameMs < 2 * st::historySendActionTypingHalfPeriod) {
  115. const auto delta = (st::historySendActionTypingLargeNumerator
  116. - st::historySendActionTypingSmallNumerator)
  117. / st::historySendActionTypingDenominator;
  118. if (frameMs < st::historySendActionTypingHalfPeriod) {
  119. r += delta
  120. * anim::easeOutCirc(
  121. 1.,
  122. float64(frameMs)
  123. / st::historySendActionTypingHalfPeriod);
  124. } else {
  125. r += delta
  126. * (1. - anim::easeOutCirc(
  127. 1.,
  128. float64(frameMs
  129. - st::historySendActionTypingHalfPeriod)
  130. / st::historySendActionTypingHalfPeriod));
  131. }
  132. }
  133. p.drawEllipse(position, r, r);
  134. position.setX(position.x() + st::historySendActionTypingDelta);
  135. frameMs = (frameMs + period() - st::historySendActionTypingDeltaTime)
  136. % period();
  137. }
  138. }
  139. class RecordAnimation : public SendActionAnimation::Impl {
  140. public:
  141. RecordAnimation() : Impl(st::historySendActionRecordDuration) {
  142. }
  143. static const MetaData kMeta;
  144. static std::unique_ptr<Impl> create() {
  145. return std::make_unique<RecordAnimation>();
  146. }
  147. const MetaData *metaData() const override {
  148. return &kMeta;
  149. }
  150. int width() const override {
  151. return st::historySendActionRecordPosition.x()
  152. + (kRecordArcsCount + 1) * st::historySendActionRecordDelta;
  153. }
  154. void paint(
  155. QPainter &p,
  156. style::color color,
  157. int x,
  158. int y,
  159. int outerWidth,
  160. crl::time now) override;
  161. };
  162. const RecordAnimation::MetaData RecordAnimation::kMeta = {
  163. 0,
  164. &RecordAnimation::create,
  165. };
  166. void RecordAnimation::paint(
  167. QPainter &p,
  168. style::color color,
  169. int x,
  170. int y,
  171. int outerWidth,
  172. crl::time now) {
  173. PainterHighQualityEnabler hq(p);
  174. const auto frameMs = frameTime(now);
  175. auto pen = color->p;
  176. pen.setWidth(st::historySendActionRecordStrokeNumerator
  177. / st::historySendActionRecordDenominator);
  178. pen.setJoinStyle(Qt::RoundJoin);
  179. pen.setCapStyle(Qt::RoundCap);
  180. p.setPen(pen);
  181. p.setBrush(Qt::NoBrush);
  182. auto progress = frameMs / float64(period());
  183. auto size = st::historySendActionRecordPosition.x()
  184. + st::historySendActionRecordDelta * progress;
  185. y += st::historySendActionRecordPosition.y();
  186. constexpr auto kAngleStart = -arc::kFullLength / 24;
  187. constexpr auto kAngleSpan = arc::kFullLength / 12;
  188. for (auto i = 0; i != kRecordArcsCount; ++i) {
  189. p.setOpacity((i == 0)
  190. ? progress
  191. : (i == kRecordArcsCount - 1)
  192. ? (1. - progress)
  193. : 1.);
  194. auto rect = QRectF(x - size, y - size, 2 * size, 2 * size);
  195. p.drawArc(rect, kAngleStart, kAngleSpan);
  196. size += st::historySendActionRecordDelta;
  197. }
  198. p.setOpacity(1.);
  199. }
  200. class UploadAnimation : public SendActionAnimation::Impl {
  201. public:
  202. UploadAnimation() : Impl(st::historySendActionUploadDuration) {
  203. }
  204. static const MetaData kMeta;
  205. static std::unique_ptr<Impl> create() {
  206. return std::make_unique<UploadAnimation>();
  207. }
  208. const MetaData *metaData() const override {
  209. return &kMeta;
  210. }
  211. int width() const override {
  212. return st::historySendActionUploadPosition.x()
  213. + (kUploadArrowsCount + 1) * st::historySendActionUploadDelta;
  214. }
  215. void paint(
  216. QPainter &p,
  217. style::color color,
  218. int x,
  219. int y,
  220. int outerWidth,
  221. crl::time now) override;
  222. };
  223. const UploadAnimation::MetaData UploadAnimation::kMeta = {
  224. 0,
  225. &UploadAnimation::create,
  226. };
  227. void UploadAnimation::paint(
  228. QPainter &p,
  229. style::color color,
  230. int x,
  231. int y,
  232. int outerWidth,
  233. crl::time now) {
  234. PainterHighQualityEnabler hq(p);
  235. const auto frameMs = frameTime(now);
  236. auto pen = color->p;
  237. pen.setWidth(st::historySendActionUploadStrokeNumerator
  238. / st::historySendActionUploadDenominator);
  239. pen.setJoinStyle(Qt::RoundJoin);
  240. pen.setCapStyle(Qt::RoundCap);
  241. p.setPen(pen);
  242. p.setBrush(Qt::NoBrush);
  243. auto progress = frameMs / float64(period());
  244. auto position = st::historySendActionUploadPosition
  245. + QPointF(x + st::historySendActionUploadDelta * progress, y);
  246. auto path = QPainterPath();
  247. path.moveTo(
  248. 0.,
  249. -st::historySendActionUploadSizeNumerator
  250. / st::historySendActionUploadDenominator);
  251. path.lineTo(
  252. st::historySendActionUploadSizeNumerator
  253. / st::historySendActionUploadDenominator,
  254. 0.);
  255. path.lineTo(
  256. 0.,
  257. st::historySendActionUploadSizeNumerator
  258. / st::historySendActionUploadDenominator);
  259. p.translate(position);
  260. for (auto i = 0; i != kUploadArrowsCount; ++i) {
  261. p.setOpacity((i == 0)
  262. ? progress
  263. : (i == kUploadArrowsCount - 1)
  264. ? (1. - progress)
  265. : 1.);
  266. p.drawPath(path);
  267. position.setX(position.x() + st::historySendActionUploadDelta);
  268. p.translate(st::historySendActionUploadDelta, 0);
  269. }
  270. p.setOpacity(1.);
  271. p.translate(-position);
  272. }
  273. class SpeakingAnimation : public SendActionAnimation::Impl {
  274. public:
  275. SpeakingAnimation();
  276. static const MetaData kMeta;
  277. static std::unique_ptr<Impl> create() {
  278. return std::make_unique<SpeakingAnimation>();
  279. }
  280. const MetaData *metaData() const override {
  281. return &kMeta;
  282. }
  283. int width() const override {
  284. const auto &numerator = st::dialogsSpeakingStrokeNumerator;
  285. const auto &denominator = st::dialogsSpeakingDenominator;
  286. return 4 * (numerator / denominator);
  287. }
  288. void restartedAt(crl::time now) override;
  289. bool finishNow() override;
  290. static void PaintIdle(
  291. QPainter &p,
  292. style::color color,
  293. int x,
  294. int y,
  295. int outerWidth);
  296. void paint(
  297. QPainter &p,
  298. style::color color,
  299. int x,
  300. int y,
  301. int outerWidth,
  302. crl::time now) override;
  303. private:
  304. static void PaintFrame(
  305. QPainter &p,
  306. style::color color,
  307. int x,
  308. int y,
  309. int outerWidth,
  310. int frameMs,
  311. float64 started);
  312. crl::time _startStarted = 0;
  313. crl::time _finishStarted = 0;
  314. };
  315. const SpeakingAnimation::MetaData SpeakingAnimation::kMeta = {
  316. 0,
  317. &SpeakingAnimation::create };
  318. SpeakingAnimation::SpeakingAnimation()
  319. : Impl(kSpeakingDuration)
  320. , _startStarted(crl::now()) {
  321. }
  322. void SpeakingAnimation::restartedAt(crl::time now) {
  323. if (!_finishStarted) {
  324. return;
  325. }
  326. const auto finishFinishes = _finishStarted + kSpeakingFadeDuration;
  327. const auto leftToFinish = (finishFinishes - now);
  328. if (leftToFinish > 0) {
  329. _startStarted = now - leftToFinish;
  330. } else {
  331. _startStarted = now;
  332. }
  333. _finishStarted = 0;
  334. }
  335. bool SpeakingAnimation::finishNow() {
  336. const auto now = crl::now();
  337. if (_finishStarted) {
  338. return (_finishStarted + kSpeakingFadeDuration <= now);
  339. } else if (_startStarted >= now) {
  340. return true;
  341. }
  342. const auto startFinishes = _startStarted + kSpeakingFadeDuration;
  343. const auto leftToStart = (startFinishes - now);
  344. if (leftToStart > 0) {
  345. _finishStarted = now - leftToStart;
  346. } else {
  347. _finishStarted = now;
  348. }
  349. return false;
  350. }
  351. void SpeakingAnimation::PaintIdle(
  352. QPainter &p,
  353. style::color color,
  354. int x,
  355. int y,
  356. int outerWidth) {
  357. PaintFrame(p, color, x, y, outerWidth, 0, 0.);
  358. }
  359. void SpeakingAnimation::paint(
  360. QPainter &p,
  361. style::color color,
  362. int x,
  363. int y,
  364. int outerWidth,
  365. crl::time now) {
  366. const auto started = _finishStarted
  367. ? (1. - ((now - _finishStarted) / float64(kSpeakingFadeDuration)))
  368. : (now - _startStarted) / float64(kSpeakingFadeDuration);
  369. const auto progress = std::clamp(started, 0., 1.);
  370. PaintFrame(p, color, x, y, outerWidth, frameTime(now), progress);
  371. }
  372. void SpeakingAnimation::PaintFrame(
  373. QPainter &p,
  374. style::color color,
  375. int x,
  376. int y,
  377. int outerWidth,
  378. int frameMs,
  379. float64 started) {
  380. PainterHighQualityEnabler hq(p);
  381. const auto line = st::dialogsSpeakingStrokeNumerator
  382. / (2 * st::dialogsSpeakingDenominator);
  383. p.setPen(Qt::NoPen);
  384. p.setBrush(color);
  385. const auto duration = kSpeakingDuration;
  386. const auto stageDuration = duration / 8;
  387. const auto fullprogress = frameMs;
  388. const auto stage = fullprogress / stageDuration;
  389. const auto progress = (fullprogress - stage * stageDuration)
  390. / float64(stageDuration);
  391. const auto half = st::dialogsCallBadgeSize / 2.;
  392. const auto center = QPointF(x + half, y + half);
  393. const auto middleSize = [&] {
  394. if (!started) {
  395. return 2 * line;
  396. }
  397. auto result = line;
  398. switch (stage) {
  399. case 0: result += 4 * line * progress; break;
  400. case 1: result += 4 * line * (1. - progress); break;
  401. case 2: result += 2 * line * progress; break;
  402. case 3: result += 2 * line * (1. - progress); break;
  403. case 4: result += 4 * line * progress; break;
  404. case 5: result += 4 * line * (1. - progress); break;
  405. case 6: result += 4 * line * progress; break;
  406. case 7: result += 4 * line * (1. - progress); break;
  407. }
  408. return (started == 1.)
  409. ? result
  410. : (started * result) + ((1. - started) * 2 * line);
  411. }();
  412. const auto sideSize = [&] {
  413. if (!started) {
  414. return 2 * line;
  415. }
  416. auto result = line;
  417. switch (stage) {
  418. case 0: result += 2 * line * (1. - progress); break;
  419. case 1: result += 4 * line * progress; break;
  420. case 2: result += 4 * line * (1. - progress); break;
  421. case 3: result += 2 * line * progress; break;
  422. case 4: result += 2 * line * (1. - progress); break;
  423. case 5: result += 4 * line * progress; break;
  424. case 6: result += 4 * line * (1. - progress); break;
  425. case 7: result += 2 * line * progress; break;
  426. }
  427. return (started == 1.)
  428. ? result
  429. : (started * result) + ((1. - started) * 2 * line);
  430. }();
  431. const auto drawRoundedRect = [&](float left, float size) {
  432. const auto top = center.y() - size;
  433. p.drawRoundedRect(QRectF(left, top, 2 * line, 2 * size), line, line);
  434. };
  435. auto left = center.x() - 4 * line;
  436. drawRoundedRect(left, sideSize);
  437. left += 3 * line;
  438. drawRoundedRect(left, middleSize);
  439. left += 3 * line;
  440. drawRoundedRect(left, sideSize);
  441. }
  442. class ChooseStickerAnimation : public SendActionAnimation::Impl {
  443. public:
  444. ChooseStickerAnimation()
  445. : Impl(st::historySendActionChooseStickerDuration)
  446. , _eye({
  447. .outWidth = float64(st::historySendActionChooseStickerEyeWidth),
  448. .outHeight = float64(st::historySendActionChooseStickerEyeHeight),
  449. .step = float64(st::historySendActionChooseStickerEyeStep),
  450. .inLeftOffset = style::ConvertScale(1.5),
  451. .inRightOffset = -style::ConvertScale(2.5)
  452. + st::historySendActionChooseStickerEyeWidth,
  453. .outXOffset = style::ConvertScale(1.5),
  454. .outStrokeWidth = style::ConvertScale(0.8 * 1.3),
  455. .inStrokeWidth = style::ConvertScale(1.2 * 1.3),
  456. .inSize = style::ConvertScale(2.),
  457. .minProgress = 0.3,
  458. .outHeightOffset = 1.5,
  459. }) {
  460. }
  461. static const MetaData kMeta;
  462. static std::unique_ptr<Impl> create() {
  463. return std::make_unique<ChooseStickerAnimation>();
  464. }
  465. const MetaData *metaData() const override {
  466. return &kMeta;
  467. }
  468. int width() const override {
  469. return widthNoMargins() + _eye.step * 2;
  470. }
  471. int widthNoMargins() const override {
  472. return st::historySendActionChooseStickerPosition.x()
  473. + 2 * (_eye.outWidth + _eye.step)
  474. + _eye.step;
  475. }
  476. void paint(
  477. QPainter &p,
  478. style::color color,
  479. int x,
  480. int y,
  481. int outerWidth,
  482. crl::time now) override;
  483. private:
  484. const struct {
  485. const float64 outWidth;
  486. const float64 outHeight;
  487. const float64 step;
  488. const float64 inLeftOffset;
  489. const float64 inRightOffset;
  490. const float64 outXOffset;
  491. const float64 outStrokeWidth;
  492. const float64 inStrokeWidth;
  493. const float64 inSize;
  494. const float64 minProgress;
  495. const float64 outHeightOffset;
  496. } _eye;
  497. };
  498. const ChooseStickerAnimation::MetaData ChooseStickerAnimation::kMeta = {
  499. 0,
  500. &ChooseStickerAnimation::create,
  501. };
  502. void ChooseStickerAnimation::paint(
  503. QPainter &p,
  504. style::color color,
  505. int x,
  506. int y,
  507. int outerWidth,
  508. crl::time now) {
  509. PainterHighQualityEnabler hq(p);
  510. const auto frameMs = frameTime(now);
  511. auto pen = color->p;
  512. pen.setJoinStyle(Qt::RoundJoin);
  513. pen.setCapStyle(Qt::RoundCap);
  514. const auto half = float64(period() / 2);
  515. const auto increment = (frameMs < half) ? true : false;
  516. // A double-progress within a period half.
  517. const auto progress = (frameMs / (half / 2)) - (increment ? 0 : 2);
  518. const auto animationProgress = std::min(progress, 1.);
  519. const auto k = _eye.minProgress;
  520. const auto pIn = anim::easeInCirc(1, std::min(animationProgress / k, 1.));
  521. const auto pInRev = 1. - pIn;
  522. const auto pOut = anim::easeOutCirc(1., (animationProgress < k)
  523. ? 0.
  524. : (animationProgress - k) / (1. - k));
  525. const auto inX = _eye.inLeftOffset * (increment ? pIn : pInRev)
  526. + _eye.inRightOffset * (increment ? pInRev : pIn);
  527. const auto inY = (_eye.outHeight - _eye.inSize) / 2.;
  528. const auto outLeft = _eye.outXOffset
  529. * (increment
  530. ? (1. - anim::easeOutCirc(1., progress / 2.))
  531. : anim::easeOutQuint(1., progress / 2.));
  532. const auto outScaleOffset = (pIn - pOut) * _eye.outHeightOffset;
  533. const auto top = st::historySendActionChooseStickerPosition.y() + y;
  534. const auto left = st::historySendActionChooseStickerPosition.x()
  535. + x
  536. + outLeft;
  537. for (auto i = 0; i < 2; i++) {
  538. const auto currentLeft = left + (_eye.outWidth + _eye.step) * i;
  539. pen.setWidthF(_eye.outStrokeWidth);
  540. p.setPen(pen);
  541. p.setBrush(Qt::NoBrush);
  542. p.drawEllipse(QRectF(
  543. currentLeft,
  544. top + outScaleOffset,
  545. _eye.outWidth,
  546. _eye.outHeight - outScaleOffset));
  547. pen.setWidthF(_eye.inStrokeWidth);
  548. p.setPen(pen);
  549. p.setBrush(color->b);
  550. p.drawEllipse(QRectF(
  551. currentLeft + inX,
  552. top + inY,
  553. _eye.inSize,
  554. _eye.inSize));
  555. }
  556. }
  557. void CreateImplementationsMap() {
  558. if (Implementations) {
  559. return;
  560. }
  561. using Type = Api::SendProgressType;
  562. Implementations.createIfNull();
  563. static constexpr auto kRecordTypes = {
  564. Type::RecordVideo,
  565. Type::RecordVoice,
  566. Type::RecordRound,
  567. };
  568. for (const auto type : kRecordTypes) {
  569. Implementations->insert(type, &RecordAnimation::kMeta);
  570. }
  571. static constexpr auto kUploadTypes = {
  572. Type::UploadFile,
  573. Type::UploadPhoto,
  574. Type::UploadVideo,
  575. Type::UploadVoice,
  576. Type::UploadRound,
  577. };
  578. for (const auto type : kUploadTypes) {
  579. Implementations->insert(type, &UploadAnimation::kMeta);
  580. }
  581. Implementations->insert(Type::Speaking, &SpeakingAnimation::kMeta);
  582. Implementations->insert(
  583. Type::ChooseSticker,
  584. &ChooseStickerAnimation::kMeta);
  585. }
  586. } // namespace
  587. SendActionAnimation::SendActionAnimation() = default;
  588. SendActionAnimation::~SendActionAnimation() = default;
  589. bool SendActionAnimation::Impl::supports(Type type) const {
  590. CreateImplementationsMap();
  591. return Implementations->value(type, &TypingAnimation::kMeta)
  592. == metaData();
  593. }
  594. void SendActionAnimation::start(Type type) {
  595. if (!_impl || !_impl->supports(type)) {
  596. _impl = CreateByType(type);
  597. } else {
  598. _impl->restartedAt(crl::now());
  599. }
  600. }
  601. void SendActionAnimation::tryToFinish() {
  602. if (!_impl) {
  603. return;
  604. } else if (_impl->finishNow()) {
  605. _impl.reset();
  606. }
  607. }
  608. int SendActionAnimation::width() const {
  609. return _impl ? _impl->width() : 0;
  610. }
  611. int SendActionAnimation::widthNoMargins() const {
  612. return _impl ? _impl->widthNoMargins() : 0;
  613. }
  614. void SendActionAnimation::paint(
  615. QPainter &p,
  616. style::color color,
  617. int x,
  618. int y,
  619. int outerWidth,
  620. crl::time ms) const {
  621. if (_impl) {
  622. _impl->paint(p, color, x, y, outerWidth, ms);
  623. }
  624. }
  625. void SendActionAnimation::PaintSpeakingIdle(
  626. QPainter &p,
  627. style::color color,
  628. int x,
  629. int y,
  630. int outerWidth) {
  631. SpeakingAnimation::PaintIdle(p, color, x, y, outerWidth);
  632. }
  633. auto SendActionAnimation::CreateByType(Type type) -> std::unique_ptr<Impl> {
  634. CreateImplementationsMap();
  635. return Implementations->value(type, &TypingAnimation::kMeta)->creator();
  636. }
  637. } // namespace Ui