Added an itemAxisRotation carousel property for rotating items around their own axis.

This commit is contained in:
Leon Styhre 2023-01-11 23:33:50 +01:00
parent f9779ded9a
commit 78a9bac280
2 changed files with 21 additions and 0 deletions

View file

@ -146,6 +146,7 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
{"itemRotation", FLOAT}, {"itemRotation", FLOAT},
{"itemRotationOrigin", NORMALIZED_PAIR}, {"itemRotationOrigin", NORMALIZED_PAIR},
{"itemAxisHorizontal", BOOLEAN}, {"itemAxisHorizontal", BOOLEAN},
{"itemAxisRotation", FLOAT},
{"imageInterpolation", STRING}, {"imageInterpolation", STRING},
{"imageColor", COLOR}, {"imageColor", COLOR},
{"imageColorEnd", COLOR}, {"imageColorEnd", COLOR},

View file

@ -145,6 +145,7 @@ private:
float mItemRotation; float mItemRotation;
glm::vec2 mItemRotationOrigin; glm::vec2 mItemRotationOrigin;
bool mItemAxisHorizontal; bool mItemAxisHorizontal;
float mItemAxisRotation;
bool mLinearInterpolation; bool mLinearInterpolation;
unsigned int mImageColorShift; unsigned int mImageColorShift;
unsigned int mImageColorShiftEnd; unsigned int mImageColorShiftEnd;
@ -201,6 +202,7 @@ CarouselComponent<T>::CarouselComponent()
, mItemRotation {7.5f} , mItemRotation {7.5f}
, mItemRotationOrigin {-3.0f, 0.5f} , mItemRotationOrigin {-3.0f, 0.5f}
, mItemAxisHorizontal {false} , mItemAxisHorizontal {false}
, mItemAxisRotation {0.0f}
, mLinearInterpolation {false} , mLinearInterpolation {false}
, mImageColorShift {0xFFFFFFFF} , mImageColorShift {0xFFFFFFFF}
, mImageColorShiftEnd {0xFFFFFFFF} , mImageColorShiftEnd {0xFFFFFFFF}
@ -1049,6 +1051,21 @@ template <typename T> void CarouselComponent<T>::render(const glm::mat4& parentT
renderItem.trans = positionCalc; 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}; float metadataOpacity {1.0f};
@ -1318,6 +1335,9 @@ void CarouselComponent<T>::applyTheme(const std::shared_ptr<ThemeData>& theme,
mItemAxisHorizontal = mItemAxisHorizontal =
(elem->has("itemAxisHorizontal") && elem->get<bool>("itemAxisHorizontal")); (elem->has("itemAxisHorizontal") && elem->get<bool>("itemAxisHorizontal"));
if (elem->has("itemAxisRotation"))
mItemAxisRotation = elem->get<float>("itemAxisRotation");
if (elem->has("imageColor")) { if (elem->has("imageColor")) {
mImageColorShift = elem->get<unsigned int>("imageColor"); mImageColorShift = elem->get<unsigned int>("imageColor");
mImageColorShiftEnd = mImageColorShift; mImageColorShiftEnd = mImageColorShift;