panel_animation.cpp 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539
  1. // This file is part of Desktop App Toolkit,
  2. // a set of libraries for developing nice desktop applications.
  3. //
  4. // For license and copyright information please follow this link:
  5. // https://github.com/desktop-app/legal/blob/master/LEGAL
  6. //
  7. #include "ui/effects/panel_animation.h"
  8. #include "ui/effects/animation_value.h"
  9. #include "ui/ui_utility.h"
  10. #include <QtGui/QPainter>
  11. namespace Ui {
  12. void RoundShadowAnimation::start(int frameWidth, int frameHeight, float64 devicePixelRatio) {
  13. Expects(!started());
  14. _frameWidth = frameWidth;
  15. _frameHeight = frameHeight;
  16. _frame = QImage(_frameWidth, _frameHeight, QImage::Format_ARGB32_Premultiplied);
  17. _frame.setDevicePixelRatio(devicePixelRatio);
  18. _frameIntsPerLine = (_frame.bytesPerLine() >> 2);
  19. _frameInts = reinterpret_cast<uint32*>(_frame.bits());
  20. _frameIntsPerLineAdded = _frameIntsPerLine - _frameWidth;
  21. Assert(_frame.depth() == static_cast<int>(sizeof(uint32) << 3));
  22. Assert(_frame.bytesPerLine() == (_frameIntsPerLine << 2));
  23. Assert(_frameIntsPerLineAdded >= 0);
  24. }
  25. void RoundShadowAnimation::setShadow(const style::Shadow &st) {
  26. _shadow.extend = st.extend * style::DevicePixelRatio();
  27. _shadow.left = cloneImage(st.left);
  28. if (_shadow.valid()) {
  29. _shadow.topLeft = cloneImage(st.topLeft);
  30. _shadow.top = cloneImage(st.top);
  31. _shadow.topRight = cloneImage(st.topRight);
  32. _shadow.right = cloneImage(st.right);
  33. _shadow.bottomRight = cloneImage(st.bottomRight);
  34. _shadow.bottom = cloneImage(st.bottom);
  35. _shadow.bottomLeft = cloneImage(st.bottomLeft);
  36. Assert(!_shadow.topLeft.isNull()
  37. && !_shadow.top.isNull()
  38. && !_shadow.topRight.isNull()
  39. && !_shadow.right.isNull()
  40. && !_shadow.bottomRight.isNull()
  41. && !_shadow.bottom.isNull()
  42. && !_shadow.bottomLeft.isNull());
  43. } else {
  44. _shadow.topLeft =
  45. _shadow.top =
  46. _shadow.topRight =
  47. _shadow.right =
  48. _shadow.bottomRight =
  49. _shadow.bottom =
  50. _shadow.bottomLeft = QImage();
  51. }
  52. }
  53. void RoundShadowAnimation::setCornerMasks(
  54. const std::array<QImage, 4> &corners) {
  55. setCornerMask(_topLeft, corners[0]);
  56. setCornerMask(_topRight, corners[1]);
  57. setCornerMask(_bottomLeft, corners[2]);
  58. setCornerMask(_bottomRight, corners[3]);
  59. }
  60. void RoundShadowAnimation::setCornerMask(Corner &corner, const QImage &image) {
  61. Expects(!started());
  62. corner.image = image;
  63. if (corner.valid()) {
  64. corner.width = corner.image.width();
  65. corner.height = corner.image.height();
  66. corner.bytes = corner.image.constBits();
  67. corner.bytesPerPixel = (corner.image.depth() >> 3);
  68. corner.bytesPerLineAdded = corner.image.bytesPerLine() - corner.width * corner.bytesPerPixel;
  69. Assert(corner.image.depth() == (corner.bytesPerPixel << 3));
  70. Assert(corner.bytesPerLineAdded >= 0);
  71. } else {
  72. corner.width = corner.height = 0;
  73. }
  74. }
  75. QImage RoundShadowAnimation::cloneImage(const style::icon &source) {
  76. if (source.empty()) return QImage();
  77. auto result = QImage(
  78. source.size() * style::DevicePixelRatio(),
  79. QImage::Format_ARGB32_Premultiplied);
  80. result.setDevicePixelRatio(style::DevicePixelRatio());
  81. result.fill(Qt::transparent);
  82. {
  83. QPainter p(&result);
  84. source.paint(p, 0, 0, source.width());
  85. }
  86. return result;
  87. }
  88. void RoundShadowAnimation::paintCorner(Corner &corner, int left, int top) {
  89. auto mask = corner.bytes;
  90. auto bytesPerPixel = corner.bytesPerPixel;
  91. auto bytesPerLineAdded = corner.bytesPerLineAdded;
  92. auto frameInts = _frameInts + top * _frameIntsPerLine + left;
  93. auto frameIntsPerLineAdd = _frameIntsPerLine - corner.width;
  94. for (auto y = 0; y != corner.height; ++y) {
  95. for (auto x = 0; x != corner.width; ++x) {
  96. auto alpha = static_cast<uint32>(*mask) + 1;
  97. *frameInts = anim::unshifted(anim::shifted(*frameInts) * alpha);
  98. ++frameInts;
  99. mask += bytesPerPixel;
  100. }
  101. frameInts += frameIntsPerLineAdd;
  102. mask += bytesPerLineAdded;
  103. }
  104. }
  105. void RoundShadowAnimation::paintShadow(int left, int top, int right, int bottom) {
  106. paintShadowCorner(left, top, _shadow.topLeft);
  107. paintShadowCorner(right - _shadow.topRight.width(), top, _shadow.topRight);
  108. paintShadowCorner(right - _shadow.bottomRight.width(), bottom - _shadow.bottomRight.height(), _shadow.bottomRight);
  109. paintShadowCorner(left, bottom - _shadow.bottomLeft.height(), _shadow.bottomLeft);
  110. paintShadowVertical(left, top + _shadow.topLeft.height(), bottom - _shadow.bottomLeft.height(), _shadow.left);
  111. paintShadowVertical(right - _shadow.right.width(), top + _shadow.topRight.height(), bottom - _shadow.bottomRight.height(), _shadow.right);
  112. paintShadowHorizontal(left + _shadow.topLeft.width(), right - _shadow.topRight.width(), top, _shadow.top);
  113. paintShadowHorizontal(left + _shadow.bottomLeft.width(), right - _shadow.bottomRight.width(), bottom - _shadow.bottom.height(), _shadow.bottom);
  114. }
  115. void RoundShadowAnimation::paintShadowCorner(int left, int top, const QImage &image) {
  116. auto imageWidth = image.width();
  117. auto imageHeight = image.height();
  118. auto imageInts = reinterpret_cast<const uint32*>(image.constBits());
  119. auto imageIntsPerLine = (image.bytesPerLine() >> 2);
  120. auto imageIntsPerLineAdded = imageIntsPerLine - imageWidth;
  121. if (left < 0) {
  122. auto shift = -base::take(left);
  123. imageWidth -= shift;
  124. imageInts += shift;
  125. }
  126. if (top < 0) {
  127. auto shift = -base::take(top);
  128. imageHeight -= shift;
  129. imageInts += shift * imageIntsPerLine;
  130. }
  131. if (left + imageWidth > _frameWidth) {
  132. imageWidth = _frameWidth - left;
  133. }
  134. if (top + imageHeight > _frameHeight) {
  135. imageHeight = _frameHeight - top;
  136. }
  137. if (imageWidth < 0 || imageHeight < 0) return;
  138. auto frameInts = _frameInts + top * _frameIntsPerLine + left;
  139. auto frameIntsPerLineAdd = _frameIntsPerLine - imageWidth;
  140. for (auto y = 0; y != imageHeight; ++y) {
  141. for (auto x = 0; x != imageWidth; ++x) {
  142. auto source = *frameInts;
  143. auto shadowAlpha = qMax(_frameAlpha - int(source >> 24), 0);
  144. *frameInts = anim::unshifted(anim::shifted(source) * 256 + anim::shifted(*imageInts) * shadowAlpha);
  145. ++frameInts;
  146. ++imageInts;
  147. }
  148. frameInts += frameIntsPerLineAdd;
  149. imageInts += imageIntsPerLineAdded;
  150. }
  151. }
  152. void RoundShadowAnimation::paintShadowVertical(int left, int top, int bottom, const QImage &image) {
  153. auto imageWidth = image.width();
  154. auto imageInts = reinterpret_cast<const uint32*>(image.constBits());
  155. if (left < 0) {
  156. auto shift = -base::take(left);
  157. imageWidth -= shift;
  158. imageInts += shift;
  159. }
  160. if (top < 0) top = 0;
  161. accumulate_min(bottom, _frameHeight);
  162. accumulate_min(imageWidth, _frameWidth - left);
  163. if (imageWidth < 0 || bottom <= top) return;
  164. auto frameInts = _frameInts + top * _frameIntsPerLine + left;
  165. auto frameIntsPerLineAdd = _frameIntsPerLine - imageWidth;
  166. for (auto y = top; y != bottom; ++y) {
  167. for (auto x = 0; x != imageWidth; ++x) {
  168. auto source = *frameInts;
  169. auto shadowAlpha = _frameAlpha - (source >> 24);
  170. *frameInts = anim::unshifted(anim::shifted(source) * 256 + anim::shifted(*imageInts) * shadowAlpha);
  171. ++frameInts;
  172. ++imageInts;
  173. }
  174. frameInts += frameIntsPerLineAdd;
  175. imageInts -= imageWidth;
  176. }
  177. }
  178. void RoundShadowAnimation::paintShadowHorizontal(int left, int right, int top, const QImage &image) {
  179. auto imageHeight = image.height();
  180. auto imageInts = reinterpret_cast<const uint32*>(image.constBits());
  181. auto imageIntsPerLine = (image.bytesPerLine() >> 2);
  182. if (top < 0) {
  183. auto shift = -base::take(top);
  184. imageHeight -= shift;
  185. imageInts += shift * imageIntsPerLine;
  186. }
  187. if (left < 0) left = 0;
  188. accumulate_min(right, _frameWidth);
  189. accumulate_min(imageHeight, _frameHeight - top);
  190. if (imageHeight < 0 || right <= left) return;
  191. auto frameInts = _frameInts + top * _frameIntsPerLine + left;
  192. auto frameIntsPerLineAdd = _frameIntsPerLine - (right - left);
  193. for (auto y = 0; y != imageHeight; ++y) {
  194. auto imagePattern = anim::shifted(*imageInts);
  195. for (auto x = left; x != right; ++x) {
  196. auto source = *frameInts;
  197. auto shadowAlpha = _frameAlpha - (source >> 24);
  198. *frameInts = anim::unshifted(anim::shifted(source) * 256 + imagePattern * shadowAlpha);
  199. ++frameInts;
  200. }
  201. frameInts += frameIntsPerLineAdd;
  202. imageInts += imageIntsPerLine;
  203. }
  204. }
  205. void PanelAnimation::setFinalImage(QImage &&finalImage, QRect inner) {
  206. Expects(!started());
  207. const auto pixelRatio = style::DevicePixelRatio();
  208. _finalImage = PixmapFromImage(
  209. std::move(finalImage).convertToFormat(
  210. QImage::Format_ARGB32_Premultiplied));
  211. Assert(!_finalImage.isNull());
  212. _finalWidth = _finalImage.width();
  213. _finalHeight = _finalImage.height();
  214. Assert(!(_finalWidth % pixelRatio));
  215. Assert(!(_finalHeight % pixelRatio));
  216. _finalInnerLeft = inner.x();
  217. _finalInnerTop = inner.y();
  218. _finalInnerWidth = inner.width();
  219. _finalInnerHeight = inner.height();
  220. Assert(!(_finalInnerLeft % pixelRatio));
  221. Assert(!(_finalInnerTop % pixelRatio));
  222. Assert(!(_finalInnerWidth % pixelRatio));
  223. Assert(!(_finalInnerHeight % pixelRatio));
  224. _finalInnerRight = _finalInnerLeft + _finalInnerWidth;
  225. _finalInnerBottom = _finalInnerTop + _finalInnerHeight;
  226. Assert(QRect(0, 0, _finalWidth, _finalHeight).contains(inner));
  227. setStartWidth();
  228. setStartHeight();
  229. setStartAlpha();
  230. setStartFadeTop();
  231. createFadeMask();
  232. setWidthDuration();
  233. setHeightDuration();
  234. setAlphaDuration();
  235. if (!_skipShadow) {
  236. setShadow(_st.shadow);
  237. }
  238. auto checkCorner = [this, inner](Corner &corner) {
  239. if (!corner.valid()) return;
  240. if ((_startWidth >= 0 && _startWidth < _finalWidth)
  241. || (_startHeight >= 0 && _startHeight < _finalHeight)) {
  242. Assert(corner.width <= inner.width());
  243. Assert(corner.height <= inner.height());
  244. }
  245. };
  246. checkCorner(_topLeft);
  247. checkCorner(_topRight);
  248. checkCorner(_bottomLeft);
  249. checkCorner(_bottomRight);
  250. }
  251. void PanelAnimation::setStartWidth() {
  252. _startWidth = qRound(_st.startWidth * _finalInnerWidth);
  253. if (_startWidth >= 0) Assert(_startWidth <= _finalInnerWidth);
  254. }
  255. void PanelAnimation::setStartHeight() {
  256. _startHeight = qRound(_st.startHeight * _finalInnerHeight);
  257. if (_startHeight >= 0) Assert(_startHeight <= _finalInnerHeight);
  258. }
  259. void PanelAnimation::setStartAlpha() {
  260. _startAlpha = qRound(_st.startOpacity * 255);
  261. Assert(_startAlpha >= 0 && _startAlpha < 256);
  262. }
  263. void PanelAnimation::setStartFadeTop() {
  264. _startFadeTop = qRound(_st.startFadeTop * _finalInnerHeight);
  265. }
  266. void PanelAnimation::createFadeMask() {
  267. auto resultHeight = qRound(_finalImage.height() * _st.fadeHeight);
  268. if (auto remove = (resultHeight % style::DevicePixelRatio())) {
  269. resultHeight -= remove;
  270. }
  271. auto finalAlpha = qRound(_st.fadeOpacity * 255);
  272. Assert(finalAlpha >= 0 && finalAlpha < 256);
  273. auto result = QImage(style::DevicePixelRatio(), resultHeight, QImage::Format_ARGB32_Premultiplied);
  274. auto ints = reinterpret_cast<uint32*>(result.bits());
  275. auto intsPerLineAdded = (result.bytesPerLine() >> 2) - style::DevicePixelRatio();
  276. auto up = (_origin == PanelAnimation::Origin::BottomLeft || _origin == PanelAnimation::Origin::BottomRight);
  277. auto from = up ? resultHeight : 0, to = resultHeight - from, delta = up ? -1 : 1;
  278. auto fadeFirstAlpha = up ? (finalAlpha + 1) : 1;
  279. auto fadeLastAlpha = up ? 1 : (finalAlpha + 1);
  280. _fadeFirst = QBrush(QColor(_st.fadeBg->c.red(), _st.fadeBg->c.green(), _st.fadeBg->c.blue(), (_st.fadeBg->c.alpha() * fadeFirstAlpha) >> 8));
  281. _fadeLast = QBrush(QColor(_st.fadeBg->c.red(), _st.fadeBg->c.green(), _st.fadeBg->c.blue(), (_st.fadeBg->c.alpha() * fadeLastAlpha) >> 8));
  282. for (auto y = from; y != to; y += delta) {
  283. auto alpha = static_cast<uint32>(finalAlpha * y) / resultHeight;
  284. auto value = (0xFFU << 24) | (alpha << 16) | (alpha << 8) | alpha;
  285. for (auto x = 0; x != style::DevicePixelRatio(); ++x) {
  286. *ints++ = value;
  287. }
  288. ints += intsPerLineAdded;
  289. }
  290. _fadeMask = PixmapFromImage(style::colorizeImage(result, _st.fadeBg));
  291. _fadeHeight = _fadeMask.height();
  292. }
  293. void PanelAnimation::setSkipShadow(bool skipShadow) {
  294. Assert(!started());
  295. _skipShadow = skipShadow;
  296. }
  297. void PanelAnimation::setWidthDuration() {
  298. _widthDuration = _st.widthDuration;
  299. Assert(_widthDuration >= 0.);
  300. Assert(_widthDuration <= 1.);
  301. }
  302. void PanelAnimation::setHeightDuration() {
  303. Assert(!started());
  304. _heightDuration = _st.heightDuration;
  305. Assert(_heightDuration >= 0.);
  306. Assert(_heightDuration <= 1.);
  307. }
  308. void PanelAnimation::setAlphaDuration() {
  309. Assert(!started());
  310. _alphaDuration = _st.opacityDuration;
  311. Assert(_alphaDuration >= 0.);
  312. Assert(_alphaDuration <= 1.);
  313. }
  314. void PanelAnimation::start() {
  315. Assert(!_finalImage.isNull());
  316. RoundShadowAnimation::start(_finalWidth, _finalHeight, _finalImage.devicePixelRatio());
  317. auto checkCorner = [this](const Corner &corner) {
  318. if (!corner.valid()) return;
  319. if (_startWidth >= 0) Assert(corner.width <= _startWidth);
  320. if (_startHeight >= 0) Assert(corner.height <= _startHeight);
  321. Assert(corner.width <= _finalInnerWidth);
  322. Assert(corner.height <= _finalInnerHeight);
  323. };
  324. checkCorner(_topLeft);
  325. checkCorner(_topRight);
  326. checkCorner(_bottomLeft);
  327. checkCorner(_bottomRight);
  328. }
  329. auto PanelAnimation::computeState(float64 dt, float64 opacity) const
  330. -> PaintState {
  331. auto &transition = anim::easeOutCirc;
  332. if (dt < _alphaDuration) {
  333. opacity *= transition(1., dt / _alphaDuration);
  334. }
  335. const auto widthProgress = (_startWidth < 0 || dt >= _widthDuration)
  336. ? 1.
  337. : transition(1., dt / _widthDuration);
  338. const auto heightProgress = (_startHeight < 0 || dt >= _heightDuration)
  339. ? 1.
  340. : transition(1., dt / _heightDuration);
  341. const auto frameWidth = (widthProgress < 1.)
  342. ? anim::interpolate(_startWidth, _finalInnerWidth, widthProgress)
  343. : _finalInnerWidth;
  344. const auto frameHeight = (heightProgress < 1.)
  345. ? anim::interpolate(_startHeight, _finalInnerHeight, heightProgress)
  346. : _finalInnerHeight;
  347. const auto ratio = style::DevicePixelRatio();
  348. return {
  349. .opacity = opacity,
  350. .widthProgress = widthProgress,
  351. .heightProgress = heightProgress,
  352. .fade = transition(1., dt),
  353. .width = frameWidth / ratio,
  354. .height = frameHeight / ratio,
  355. };
  356. }
  357. auto PanelAnimation::paintFrame(
  358. QPainter &p,
  359. int x,
  360. int y,
  361. int outerWidth,
  362. float64 dt,
  363. float64 opacity)
  364. -> PaintState {
  365. Assert(started());
  366. Assert(dt >= 0.);
  367. const auto pixelRatio = style::DevicePixelRatio();
  368. const auto state = computeState(dt, opacity);
  369. opacity = state.opacity;
  370. _frameAlpha = anim::interpolate(1, 256, opacity);
  371. const auto frameWidth = state.width * pixelRatio;
  372. const auto frameHeight = state.height * pixelRatio;
  373. auto frameLeft = (_origin == Origin::TopLeft || _origin == Origin::BottomLeft) ? _finalInnerLeft : (_finalInnerRight - frameWidth);
  374. auto frameTop = (_origin == Origin::TopLeft || _origin == Origin::TopRight) ? _finalInnerTop : (_finalInnerBottom - frameHeight);
  375. auto frameRight = frameLeft + frameWidth;
  376. auto frameBottom = frameTop + frameHeight;
  377. auto fadeTop = (_fadeHeight > 0) ? std::clamp(anim::interpolate(_startFadeTop, _finalInnerHeight, state.fade), 0, frameHeight) : frameHeight;
  378. if (auto decrease = (fadeTop % pixelRatio)) {
  379. fadeTop -= decrease;
  380. }
  381. auto fadeBottom = (fadeTop < frameHeight) ? std::min(fadeTop + _fadeHeight, frameHeight) : frameHeight;
  382. auto fadeSkipLines = 0;
  383. if (_origin == Origin::BottomLeft || _origin == Origin::BottomRight) {
  384. fadeTop = frameHeight - fadeTop;
  385. fadeBottom = frameHeight - fadeBottom;
  386. qSwap(fadeTop, fadeBottom);
  387. fadeSkipLines = fadeTop + _fadeHeight - fadeBottom;
  388. }
  389. fadeTop += frameTop;
  390. fadeBottom += frameTop;
  391. if (opacity < 1.) {
  392. _frame.fill(Qt::transparent);
  393. }
  394. {
  395. QPainter p(&_frame);
  396. p.setOpacity(opacity);
  397. auto painterFrameLeft = frameLeft / pixelRatio;
  398. auto painterFrameTop = frameTop / pixelRatio;
  399. auto painterFadeBottom = fadeBottom / pixelRatio;
  400. p.drawPixmap(painterFrameLeft, painterFrameTop, _finalImage, frameLeft, frameTop, frameWidth, frameHeight);
  401. if (_fadeHeight) {
  402. if (frameTop != fadeTop) {
  403. p.fillRect(painterFrameLeft, painterFrameTop, frameWidth, fadeTop - frameTop, _fadeFirst);
  404. }
  405. if (fadeTop != fadeBottom) {
  406. auto painterFadeTop = fadeTop / pixelRatio;
  407. auto painterFrameWidth = frameWidth / pixelRatio;
  408. p.drawPixmap(painterFrameLeft, painterFadeTop, painterFrameWidth, painterFadeBottom - painterFadeTop, _fadeMask, 0, fadeSkipLines, pixelRatio, fadeBottom - fadeTop);
  409. }
  410. if (fadeBottom != frameBottom) {
  411. p.fillRect(painterFrameLeft, painterFadeBottom, frameWidth, frameBottom - fadeBottom, _fadeLast);
  412. }
  413. }
  414. }
  415. // Draw corners
  416. paintCorner(_topLeft, frameLeft, frameTop);
  417. paintCorner(_topRight, frameRight - _topRight.width, frameTop);
  418. paintCorner(_bottomLeft, frameLeft, frameBottom - _bottomLeft.height);
  419. paintCorner(_bottomRight, frameRight - _bottomRight.width, frameBottom - _bottomRight.height);
  420. // Draw shadow upon the transparent
  421. auto outerLeft = frameLeft;
  422. auto outerTop = frameTop;
  423. auto outerRight = frameRight;
  424. auto outerBottom = frameBottom;
  425. if (_shadow.valid()) {
  426. outerLeft -= _shadow.extend.left();
  427. outerTop -= _shadow.extend.top();
  428. outerRight += _shadow.extend.right();
  429. outerBottom += _shadow.extend.bottom();
  430. }
  431. if (pixelRatio > 1) {
  432. if (auto skipLeft = (outerLeft % pixelRatio)) {
  433. outerLeft -= skipLeft;
  434. }
  435. if (auto skipTop = (outerTop % pixelRatio)) {
  436. outerTop -= skipTop;
  437. }
  438. if (auto skipRight = (outerRight % pixelRatio)) {
  439. outerRight += (pixelRatio - skipRight);
  440. }
  441. if (auto skipBottom = (outerBottom % pixelRatio)) {
  442. outerBottom += (pixelRatio - skipBottom);
  443. }
  444. }
  445. if (opacity == 1.) {
  446. // Fill above the frame top with transparent.
  447. auto fillTopInts = (_frameInts + outerTop * _frameIntsPerLine + outerLeft);
  448. auto fillWidth = (outerRight - outerLeft) * sizeof(uint32);
  449. for (auto fillTop = frameTop - outerTop; fillTop != 0; --fillTop) {
  450. memset(fillTopInts, 0, fillWidth);
  451. fillTopInts += _frameIntsPerLine;
  452. }
  453. // Fill to the left and to the right of the frame with transparent.
  454. auto fillLeft = (frameLeft - outerLeft) * sizeof(uint32);
  455. auto fillRight = (outerRight - frameRight) * sizeof(uint32);
  456. if (fillLeft || fillRight) {
  457. auto fillInts = _frameInts + frameTop * _frameIntsPerLine;
  458. for (auto y = frameTop; y != frameBottom; ++y) {
  459. memset(fillInts + outerLeft, 0, fillLeft);
  460. memset(fillInts + frameRight, 0, fillRight);
  461. fillInts += _frameIntsPerLine;
  462. }
  463. }
  464. // Fill below the frame bottom with transparent.
  465. auto fillBottomInts = (_frameInts + frameBottom * _frameIntsPerLine + outerLeft);
  466. for (auto fillBottom = outerBottom - frameBottom; fillBottom != 0; --fillBottom) {
  467. memset(fillBottomInts, 0, fillWidth);
  468. fillBottomInts += _frameIntsPerLine;
  469. }
  470. }
  471. if (_shadow.valid()) {
  472. paintShadow(outerLeft, outerTop, outerRight, outerBottom);
  473. }
  474. // Debug
  475. //frameInts = _frameInts;
  476. //auto pattern = anim::shifted((static_cast<uint32>(0xFF) << 24) | (static_cast<uint32>(0xFF) << 16) | (static_cast<uint32>(0xFF) << 8) | static_cast<uint32>(0xFF));
  477. //for (auto y = 0; y != _finalHeight; ++y) {
  478. // for (auto x = 0; x != _finalWidth; ++x) {
  479. // auto source = *frameInts;
  480. // auto sourceAlpha = (source >> 24);
  481. // *frameInts = anim::unshifted(anim::shifted(source) * 256 + pattern * (256 - sourceAlpha));
  482. // ++frameInts;
  483. // }
  484. // frameInts += _frameIntsPerLineAdded;
  485. //}
  486. p.drawImage(style::rtlpoint(x + (outerLeft / pixelRatio), y + (outerTop / pixelRatio), outerWidth), _frame, QRect(outerLeft, outerTop, outerRight - outerLeft, outerBottom - outerTop));
  487. return state;
  488. }
  489. } // namespace Ui