From 78a9bac280faf62b2980fcd347761017ee7668a4 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 11 Jan 2023 23:33:50 +0100 Subject: [PATCH] Added an itemAxisRotation carousel property for rotating items around their own axis. --- es-core/src/ThemeData.cpp | 1 + .../components/primary/CarouselComponent.h | 20 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 64220eee1..90f745c99 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -146,6 +146,7 @@ std::map> {"itemRotation", FLOAT}, {"itemRotationOrigin", NORMALIZED_PAIR}, {"itemAxisHorizontal", BOOLEAN}, + {"itemAxisRotation", FLOAT}, {"imageInterpolation", STRING}, {"imageColor", COLOR}, {"imageColorEnd", COLOR}, diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index 61238d317..50ec24242 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -145,6 +145,7 @@ private: float mItemRotation; glm::vec2 mItemRotationOrigin; bool mItemAxisHorizontal; + float mItemAxisRotation; bool mLinearInterpolation; unsigned int mImageColorShift; unsigned int mImageColorShiftEnd; @@ -201,6 +202,7 @@ CarouselComponent::CarouselComponent() , mItemRotation {7.5f} , mItemRotationOrigin {-3.0f, 0.5f} , mItemAxisHorizontal {false} + , mItemAxisRotation {0.0f} , mLinearInterpolation {false} , mImageColorShift {0xFFFFFFFF} , mImageColorShiftEnd {0xFFFFFFFF} @@ -1049,6 +1051,21 @@ template void CarouselComponent::render(const glm::mat4& parentT renderItem.trans = positionCalc; } } + else if (mItemAxisRotation != 0.0f) { + // Rotate items around their own axis. + const float xOffTransRotate {-(mItemSize.x / 2.0f)}; + const float yOffTransRotate {-(mItemSize.y / 2.0f)}; + + renderItem.trans = + glm::translate(renderItem.trans, + glm::vec3 {xOffTransRotate * -1.0f, yOffTransRotate * -1.0f, 0.0f}); + + renderItem.trans = glm::rotate(renderItem.trans, glm::radians(mItemAxisRotation), + glm::vec3 {0.0f, 0.0f, 1.0f}); + + renderItem.trans = glm::translate(renderItem.trans, + glm::vec3 {xOffTransRotate, yOffTransRotate, 0.0f}); + } float metadataOpacity {1.0f}; @@ -1318,6 +1335,9 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, mItemAxisHorizontal = (elem->has("itemAxisHorizontal") && elem->get("itemAxisHorizontal")); + if (elem->has("itemAxisRotation")) + mItemAxisRotation = elem->get("itemAxisRotation"); + if (elem->has("imageColor")) { mImageColorShift = elem->get("imageColor"); mImageColorShiftEnd = mImageColorShift;