mirror of
https://github.com/Swiftgram/Telegram-iOS.git
synced 2025-12-07 06:43:43 +00:00
lottie/render: Use AlignCenter rule when the composition dosen't scale exactly to the requested size.
Change-Id: Ibd8aa929186104378287b65785afbc799cad0e04
This commit is contained in:
parent
792cd0d5f5
commit
e62f74b624
@ -92,16 +92,25 @@ VSize LOTCompItem::size() const
|
|||||||
|
|
||||||
bool LOTCompItem::update(int frameNo)
|
bool LOTCompItem::update(int frameNo)
|
||||||
{
|
{
|
||||||
VMatrix m;
|
|
||||||
float sx, sy;
|
|
||||||
|
|
||||||
// check if cached frame is same as requested frame.
|
// check if cached frame is same as requested frame.
|
||||||
if (!mUpdateViewBox && (mCurFrameNo == frameNo)) return false;
|
if (!mUpdateViewBox && (mCurFrameNo == frameNo)) return false;
|
||||||
|
|
||||||
sx = mViewSize.width() / float(mCompData->size().width());
|
/*
|
||||||
sy = mViewSize.height() / float(mCompData->size().height());
|
* if viewbox dosen't scale exactly to the viewport
|
||||||
|
* we scale the viewbox keeping AspectRatioPreserved and then align the
|
||||||
|
* viewbox to the viewport using AlignCenter rule.
|
||||||
|
*/
|
||||||
|
VSize viewPort = mViewSize;
|
||||||
|
VSize viewBox = mCompData->size();
|
||||||
|
|
||||||
|
float sx = float(viewPort.width()) / viewBox.width();
|
||||||
|
float sy = float(viewPort.height()) / viewBox.height();
|
||||||
float scale = fmin(sx, sy);
|
float scale = fmin(sx, sy);
|
||||||
m.scale(scale, scale);
|
float tx = (viewPort.width() - viewBox.width() * scale) * 0.5;
|
||||||
|
float ty = (viewPort.height() - viewBox.height() * scale) * 0.5;
|
||||||
|
|
||||||
|
VMatrix m;
|
||||||
|
m.scale(scale, scale).translate(tx, ty);
|
||||||
|
|
||||||
// update the layer from back to front
|
// update the layer from back to front
|
||||||
for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
|
for (auto i = mLayers.rbegin(); i != mLayers.rend(); ++i) {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user