From 248df769ebd15fd191c0db61a33f3aa6f66aaa42 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 5 Jun 2024 20:21:32 +0200 Subject: [PATCH] Added an 'imageCropPos' property to the carousel element --- es-core/src/ThemeData.cpp | 1 + .../components/primary/CarouselComponent.h | 36 +++++++++++++------ .../src/components/primary/PrimaryComponent.h | 2 +- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 40ad04961..3ea686100 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -135,6 +135,7 @@ std::map> {"itemAxisHorizontal", BOOLEAN}, {"itemAxisRotation", FLOAT}, {"imageFit", STRING}, + {"imageCropPos", NORMALIZED_PAIR}, {"imageInterpolation", STRING}, {"imageCornerRadius", FLOAT}, {"imageColor", COLOR}, diff --git a/es-core/src/components/primary/CarouselComponent.h b/es-core/src/components/primary/CarouselComponent.h index 1e950788e..0645885cc 100644 --- a/es-core/src/components/primary/CarouselComponent.h +++ b/es-core/src/components/primary/CarouselComponent.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// ES-DE +// ES-DE Frontend // CarouselComponent.h // // Carousel, usable in both the system and gamelist views. @@ -193,6 +193,7 @@ private: bool mHasUnfocusedItemSaturation; float mUnfocusedItemDimming; ImageFit mImagefit; + glm::vec2 mImageCropPos; unsigned int mCarouselColor; unsigned int mCarouselColorEnd; bool mColorGradientHorizontal; @@ -270,6 +271,7 @@ CarouselComponent::CarouselComponent() , mHasUnfocusedItemSaturation {false} , mUnfocusedItemDimming {1.0f} , mImagefit {ImageFit::CONTAIN} + , mImageCropPos {0.5f, 0.5f} , mCarouselColor {0} , mCarouselColorEnd {0} , mColorGradientHorizontal {true} @@ -307,12 +309,16 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); item->setLinearInterpolation(mLinearInterpolation); item->setMipmapping(true); - if (mImagefit == ImageFit::CONTAIN) + if (mImagefit == ImageFit::CONTAIN) { item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); - else if (mImagefit == ImageFit::FILL) + } + else if (mImagefit == ImageFit::FILL) { item->setResize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); - else if (mImagefit == ImageFit::COVER) + } + else if (mImagefit == ImageFit::COVER) { + item->setCropPos(mImageCropPos); item->setCroppedSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); + } item->setCornerRadius(mImageCornerRadius); item->setImage(entry.data.imagePath); if (mImageBrightness != 0.0) @@ -334,15 +340,19 @@ void CarouselComponent::addEntry(Entry& entry, const std::shared_ptr(false, dynamic); mDefaultImage->setLinearInterpolation(mLinearInterpolation); mDefaultImage->setMipmapping(true); - if (mImagefit == ImageFit::CONTAIN) + if (mImagefit == ImageFit::CONTAIN) { mDefaultImage->setMaxSize( glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); - else if (mImagefit == ImageFit::FILL) + } + else if (mImagefit == ImageFit::FILL) { mDefaultImage->setResize( glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); - else if (mImagefit == ImageFit::COVER) + } + else if (mImagefit == ImageFit::COVER) { + mDefaultImage->setCropPos(mImageCropPos); mDefaultImage->setCroppedSize( glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); + } mDefaultImage->setCornerRadius(mImageCornerRadius); mDefaultImage->setImage(entry.data.defaultImagePath); if (mImageBrightness != 0.0) @@ -411,12 +421,16 @@ void CarouselComponent::updateEntry(Entry& entry, const std::shared_ptr(false, true); item->setLinearInterpolation(mLinearInterpolation); item->setMipmapping(true); - if (mImagefit == ImageFit::CONTAIN) + if (mImagefit == ImageFit::CONTAIN) { item->setMaxSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); - else if (mImagefit == ImageFit::FILL) + } + else if (mImagefit == ImageFit::FILL) { item->setResize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); - else if (mImagefit == ImageFit::COVER) + } + else if (mImagefit == ImageFit::COVER) { + item->setCropPos(mImageCropPos); item->setCroppedSize(glm::round(mItemSize * (mItemScale >= 1.0f ? mItemScale : 1.0f))); + } item->setCornerRadius(mImageCornerRadius); item->setImage(entry.data.imagePath); if (mImageBrightness != 0.0) @@ -1444,6 +1458,8 @@ void CarouselComponent::applyTheme(const std::shared_ptr& theme, } else if (imageFit == "cover") { mImagefit = ImageFit::COVER; + if (elem->has("imageCropPos")) + mImageCropPos = glm::clamp(elem->get("imageCropPos"), 0.0f, 1.0f); } else { mImagefit = ImageFit::CONTAIN; diff --git a/es-core/src/components/primary/PrimaryComponent.h b/es-core/src/components/primary/PrimaryComponent.h index 613c3821e..14b8d8881 100644 --- a/es-core/src/components/primary/PrimaryComponent.h +++ b/es-core/src/components/primary/PrimaryComponent.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// ES-DE +// ES-DE Frontend // PrimaryComponent.h // // Base class for the primary components (carousel, grid and textlist).