From 3ecb821c00826509451e41e3c3e61e7ca84993b1 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Sat, 4 Jun 2022 17:25:36 +0200 Subject: [PATCH] Added size restrictions to the 'size' and 'maxSize' theme properties for the image and video elements. --- es-core/src/components/ImageComponent.cpp | 26 +++++++++++++++++------ es-core/src/components/VideoComponent.cpp | 22 +++++++++++++++---- 2 files changed, 38 insertions(+), 10 deletions(-) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index e515b3158..df6f7e912 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -501,12 +501,26 @@ void ImageComponent::applyTheme(const std::shared_ptr& theme, glm::vec2(Renderer::getScreenWidth(), Renderer::getScreenHeight())}; if (properties & ThemeFlags::SIZE) { - if (elem->has("size")) - setResize(elem->get("size") * scale); - else if (elem->has("maxSize")) - setMaxSize(elem->get("maxSize") * scale); - else if (elem->has("minSize")) - setMinSize(elem->get("minSize") * scale); + if (elem->has("size")) { + glm::vec2 imageSize {elem->get("size")}; + if (imageSize == glm::vec2 {0.0f, 0.0f}) { + LOG(LogWarning) << "ImageComponent: Invalid theme configuration, property " + "for element \"" + << element.substr(6) << "\" is set to zero"; + imageSize = {0.001f, 0.001f}; + } + if (imageSize.x > 0.0f) + imageSize.x = glm::clamp(imageSize.x, 0.001f, 2.0f); + if (imageSize.y > 0.0f) + imageSize.y = glm::clamp(imageSize.y, 0.001f, 2.0f); + setResize(imageSize * scale); + } + else if (elem->has("maxSize")) { + glm::vec2 imageMaxSize {elem->get("maxSize")}; + imageMaxSize.x = glm::clamp(imageMaxSize.x, 0.001f, 2.0f); + imageMaxSize.y = glm::clamp(imageMaxSize.y, 0.001f, 2.0f); + setMaxSize(imageMaxSize * scale); + } } if (elem->has("interpolation")) { diff --git a/es-core/src/components/VideoComponent.cpp b/es-core/src/components/VideoComponent.cpp index 35e58baa7..3db4e6f31 100644 --- a/es-core/src/components/VideoComponent.cpp +++ b/es-core/src/components/VideoComponent.cpp @@ -119,12 +119,26 @@ void VideoComponent::applyTheme(const std::shared_ptr& theme, if (properties & ThemeFlags::SIZE) { if (elem->has("size")) { - setResize(elem->get("size") * scale); - mVideoAreaSize = elem->get("size") * scale; + glm::vec2 videoSize {elem->get("size")}; + if (videoSize == glm::vec2 {0.0f, 0.0f}) { + LOG(LogWarning) << "VideoComponent: Invalid theme configuration, property " + "for element \"" + << element.substr(6) << "\" is set to zero"; + videoSize = {0.01f, 0.01f}; + } + if (videoSize.x > 0.0f) + videoSize.x = glm::clamp(videoSize.x, 0.01f, 2.0f); + if (videoSize.y > 0.0f) + videoSize.y = glm::clamp(videoSize.y, 0.01f, 2.0f); + setResize(videoSize * scale); + mVideoAreaSize = videoSize * scale; } else if (elem->has("maxSize")) { - setMaxSize(elem->get("maxSize") * scale); - mVideoAreaSize = elem->get("maxSize") * scale; + glm::vec2 videoMaxSize {elem->get("maxSize")}; + videoMaxSize.x = glm::clamp(videoMaxSize.x, 0.01f, 2.0f); + videoMaxSize.y = glm::clamp(videoMaxSize.y, 0.01f, 2.0f); + setMaxSize(videoMaxSize * scale); + mVideoAreaSize = videoMaxSize * scale; } }