diff --git a/src/common/tvgMath.h b/src/common/tvgMath.h index a3f7a61f..a0507866 100644 --- a/src/common/tvgMath.h +++ b/src/common/tvgMath.h @@ -114,38 +114,38 @@ static inline void identity(Matrix* m) } -static inline void scale(Matrix* m, float sx, float sy) +static inline void scale(Matrix* m, const Point& p) { - m->e11 *= sx; - m->e22 *= sy; + m->e11 *= p.x; + m->e22 *= p.y; } -static inline void scaleR(Matrix* m, float x, float y) +static inline void scaleR(Matrix* m, const Point& p) { - if (x != 1.0f) { - m->e11 *= x; - m->e21 *= x; + if (p.x != 1.0f) { + m->e11 *= p.x; + m->e21 *= p.x; } - if (y != 1.0f) { - m->e22 *= y; - m->e12 *= y; + if (p.y != 1.0f) { + m->e22 *= p.y; + m->e12 *= p.y; } } -static inline void translate(Matrix* m, float x, float y) +static inline void translate(Matrix* m, const Point& p) { - m->e13 += x; - m->e23 += y; + m->e13 += p.x; + m->e23 += p.y; } -static inline void translateR(Matrix* m, float x, float y) +static inline void translateR(Matrix* m, const Point& p) { - if (x == 0.0f && y == 0.0f) return; - m->e13 += (x * m->e11 + y * m->e12); - m->e23 += (x * m->e21 + y * m->e22); + if (p.x == 0.0f && p.y == 0.0f) return; + m->e13 += (p.x * m->e11 + p.y * m->e12); + m->e23 += (p.x * m->e21 + p.y * m->e22); } diff --git a/src/loaders/lottie/tvgLottieBuilder.cpp b/src/loaders/lottie/tvgLottieBuilder.cpp index 8e47e4db..d0d8661a 100644 --- a/src/loaders/lottie/tvgLottieBuilder.cpp +++ b/src/loaders/lottie/tvgLottieBuilder.cpp @@ -110,12 +110,8 @@ static bool _updateTransform(LottieTransform* transform, float frameNo, bool aut return false; } - if (transform->coords) { - translate(&matrix, transform->coords->x(frameNo, exps), transform->coords->y(frameNo, exps)); - } else { - auto position = transform->position(frameNo, exps); - translate(&matrix, position.x, position.y); - } + if (transform->coords) translate(&matrix, {transform->coords->x(frameNo, exps), transform->coords->y(frameNo, exps)}); + else translate(&matrix, transform->position(frameNo, exps)); auto angle = 0.0f; if (autoOrient) angle = transform->position.angle(frameNo); @@ -133,11 +129,10 @@ static bool _updateTransform(LottieTransform* transform, float frameNo, bool aut } auto scale = transform->scale(frameNo, exps); - scaleR(&matrix, scale.x * 0.01f, scale.y * 0.01f); + scaleR(&matrix, scale * 0.01f); //Lottie specific anchor transform. - auto anchor = transform->anchor(frameNo, exps); - translateR(&matrix, -anchor.x, -anchor.y); + translateR(&matrix, -transform->anchor(frameNo, exps)); //invisible just in case. if (scale.x == 0.0f || scale.y == 0.0f) opacity = 0; @@ -345,10 +340,10 @@ static void _repeat(LottieGroup* parent, Shape* path, RenderContext* ctx) Matrix m; identity(&m); - translate(&m, repeater->position.x * multiplier + repeater->anchor.x, repeater->position.y * multiplier + repeater->anchor.y); - scale(&m, powf(repeater->scale.x * 0.01f, multiplier), powf(repeater->scale.y * 0.01f, multiplier)); + translate(&m, repeater->position * multiplier + repeater->anchor); + scale(&m, {powf(repeater->scale.x * 0.01f, multiplier), powf(repeater->scale.y * 0.01f, multiplier)}); rotate(&m, repeater->rotation * multiplier); - translateR(&m, -repeater->anchor.x, -repeater->anchor.y); + translateR(&m, -repeater->anchor); m = repeater->transform * m; Matrix inv; @@ -791,8 +786,7 @@ void LottieBuilder::updatePolystar(LottieGroup* parent, LottieObject** child, fl //Optimize: Can we skip the individual coords transform? Matrix matrix; identity(&matrix); - auto position = star->position(frameNo, exps); - translate(&matrix, position.x, position.y); + translate(&matrix, star->position(frameNo, exps)); rotate(&matrix, star->rotation(frameNo, exps)); if (ctx->transform) matrix = *ctx->transform * matrix; @@ -1162,7 +1156,7 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo) // TextGroup transformation is performed once if (textGroup->paints().size() == 0 && needGroup) { identity(&textGroupMatrix); - translate(&textGroupMatrix, cursor.x, cursor.y); + translate(&textGroupMatrix, cursor); auto alignment = text->alignOption.anchor(frameNo); @@ -1172,20 +1166,18 @@ void LottieBuilder::updateText(LottieLayer* layer, float frameNo) rotate(&textGroupMatrix, rotation); - auto pivotX = alignment.x * -1; - auto pivotY = alignment.y * -1; - //center pivoting - textGroupMatrix.e13 += (pivotX * textGroupMatrix.e11 + pivotX * textGroupMatrix.e12); - textGroupMatrix.e23 += (pivotY * textGroupMatrix.e21 + pivotY * textGroupMatrix.e22); + auto pivot = alignment * -1; + textGroupMatrix.e13 += (pivot.x * textGroupMatrix.e11 + pivot.x * textGroupMatrix.e12); + textGroupMatrix.e23 += (pivot.y * textGroupMatrix.e21 + pivot.y * textGroupMatrix.e22); textGroup->transform(textGroupMatrix); } auto& matrix = shape->transform(); identity(&matrix); - translate(&matrix, translation.x / scale + cursor.x - textGroupMatrix.e13, translation.y / scale + cursor.y - textGroupMatrix.e23); - tvg::scale(&matrix, scaling.x * capScale, scaling.y * capScale); + translate(&matrix, (translation / scale + cursor) - Point{textGroupMatrix.e13, textGroupMatrix.e23}); + tvg::scale(&matrix, scaling * capScale); shape->transform(matrix); } diff --git a/src/loaders/svg/tvgSvgSceneBuilder.cpp b/src/loaders/svg/tvgSvgSceneBuilder.cpp index 23e54c2f..2cf5b3b2 100644 --- a/src/loaders/svg/tvgSvgSceneBuilder.cpp +++ b/src/loaders/svg/tvgSvgSceneBuilder.cpp @@ -771,7 +771,7 @@ static Paint* _textBuildHelper(SvgLoaderData& loaderData, const SvgNode* node, c if (node->transform) textTransform = *node->transform; else textTransform = {1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f}; - translateR(&textTransform, node->node.text.x, node->node.text.y - textNode->fontSize); + translateR(&textTransform, {node->node.text.x, node->node.text.y - textNode->fontSize}); text->transform(textTransform); //TODO: handle def values of font and size as used in a system? diff --git a/src/renderer/gl_engine/tvgGlRenderPass.cpp b/src/renderer/gl_engine/tvgGlRenderPass.cpp index c693def1..f85e4ef2 100644 --- a/src/renderer/gl_engine/tvgGlRenderPass.cpp +++ b/src/renderer/gl_engine/tvgGlRenderPass.cpp @@ -56,7 +56,7 @@ void GlRenderPass::getMatrix(float *dst, const Matrix &matrix) const Matrix postMatrix{}; identity(&postMatrix); - translate(&postMatrix, -vp.x, -vp.y); + translate(&postMatrix, {(float)-vp.x, (float)-vp.y}); auto m = postMatrix * matrix; diff --git a/src/renderer/tvgPaint.h b/src/renderer/tvgPaint.h index 0d224a54..d61f6650 100644 --- a/src/renderer/tvgPaint.h +++ b/src/renderer/tvgPaint.h @@ -72,7 +72,7 @@ namespace tvg m.e31 = 0.0f; m.e32 = 0.0f; m.e33 = 1.0f; - tvg::scale(&m, scale, scale); + tvg::scale(&m, {scale, scale}); tvg::rotate(&m, degree); } } tr;