From f2400941912fb8965efd68e35f648109c36906f6 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 5 Jun 2024 20:22:44 +0200 Subject: [PATCH] Added an 'imageCropPos' property to the grid element --- es-core/src/ThemeData.cpp | 1 + .../src/components/primary/GridComponent.h | 36 +++++++++++++------ 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/es-core/src/ThemeData.cpp b/es-core/src/ThemeData.cpp index 3ea686100..e359c5ed5 100644 --- a/es-core/src/ThemeData.cpp +++ b/es-core/src/ThemeData.cpp @@ -203,6 +203,7 @@ std::map> {"unfocusedItemSaturation", FLOAT}, {"unfocusedItemDimming", FLOAT}, {"imageFit", STRING}, + {"imageCropPos", NORMALIZED_PAIR}, {"imageInterpolation", STRING}, {"imageRelativeScale", FLOAT}, {"imageCornerRadius", FLOAT}, diff --git a/es-core/src/components/primary/GridComponent.h b/es-core/src/components/primary/GridComponent.h index 939edc5e2..78c7bc4ff 100644 --- a/es-core/src/components/primary/GridComponent.h +++ b/es-core/src/components/primary/GridComponent.h @@ -1,6 +1,6 @@ // SPDX-License-Identifier: MIT // -// ES-DE +// ES-DE Frontend // GridComponent.h // // Grid, usable in both the system and gamelist views. @@ -161,6 +161,7 @@ private: bool mHasUnfocusedItemSaturation; float mUnfocusedItemDimming; ImageFit mImagefit; + glm::vec2 mImageCropPos; bool mImageLinearInterpolation; float mImageRelativeScale; float mImageCornerRadius; @@ -239,6 +240,7 @@ GridComponent::GridComponent() , mHasUnfocusedItemSaturation {false} , mUnfocusedItemDimming {1.0f} , mImagefit {ImageFit::CONTAIN} + , mImageCropPos {0.5f, 0.5f} , mImageLinearInterpolation {true} , mImageRelativeScale {1.0f} , mImageCornerRadius {0.0f} @@ -304,12 +306,16 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& auto item = std::make_shared(false, dynamic); item->setLinearInterpolation(mImageLinearInterpolation); item->setMipmapping(true); - if (mImagefit == ImageFit::CONTAIN) + if (mImagefit == ImageFit::CONTAIN) { item->setMaxSize(glm::round(mItemSize * mImageRelativeScale)); - else if (mImagefit == ImageFit::FILL) + } + else if (mImagefit == ImageFit::FILL) { item->setResize(glm::round(mItemSize * mImageRelativeScale)); - else if (mImagefit == ImageFit::COVER) + } + else if (mImagefit == ImageFit::COVER) { + item->setCropPos(mImageCropPos); item->setCroppedSize(glm::round(mItemSize * mImageRelativeScale)); + } item->setCornerRadius(mImageCornerRadius); item->setImage(entry.data.imagePath); if (mImageBrightness != 0.0) @@ -336,12 +342,16 @@ void GridComponent::addEntry(Entry& entry, const std::shared_ptr& mDefaultImage = std::make_shared(false, dynamic); mDefaultImage->setLinearInterpolation(mImageLinearInterpolation); mDefaultImage->setMipmapping(true); - if (mImagefit == ImageFit::CONTAIN) + if (mImagefit == ImageFit::CONTAIN) { mDefaultImage->setMaxSize(glm::round(mItemSize * mImageRelativeScale)); - else if (mImagefit == ImageFit::FILL) + } + else if (mImagefit == ImageFit::FILL) { mDefaultImage->setResize(glm::round(mItemSize * mImageRelativeScale)); - else if (mImagefit == ImageFit::COVER) + } + else if (mImagefit == ImageFit::COVER) { + mDefaultImage->setCropPos(mImageCropPos); mDefaultImage->setCroppedSize(glm::round(mItemSize * mImageRelativeScale)); + } mDefaultImage->setCornerRadius(mImageCornerRadius); mDefaultImage->setImage(entry.data.defaultImagePath); if (mImageBrightness != 0.0) @@ -393,12 +403,16 @@ void GridComponent::updateEntry(Entry& entry, const std::shared_ptr(false, true); item->setLinearInterpolation(mImageLinearInterpolation); item->setMipmapping(true); - if (mImagefit == ImageFit::CONTAIN) + if (mImagefit == ImageFit::CONTAIN) { item->setMaxSize(glm::round(mItemSize * mImageRelativeScale)); - else if (mImagefit == ImageFit::FILL) + } + else if (mImagefit == ImageFit::FILL) { item->setResize(glm::round(mItemSize * mImageRelativeScale)); - else if (mImagefit == ImageFit::COVER) + } + else if (mImagefit == ImageFit::COVER) { + item->setCropPos(mImageCropPos); item->setCroppedSize(glm::round(mItemSize * mImageRelativeScale)); + } item->setCornerRadius(mImageCornerRadius); item->setImage(entry.data.imagePath); if (mImageBrightness != 0.0) @@ -1042,6 +1056,8 @@ void GridComponent::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;