From b4338a3fb744c02ae82e8009adc540fe6f1d55e3 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Mon, 7 Nov 2022 23:58:22 +0100 Subject: [PATCH] Refactored some image resizing functions. --- es-app/src/guis/GuiMetaDataEd.cpp | 3 +-- es-core/src/GuiComponent.h | 4 ++-- es-core/src/components/AnimatedImageComponent.cpp | 7 +++---- es-core/src/components/ImageComponent.cpp | 6 +++--- es-core/src/components/ImageComponent.h | 6 +----- es-core/src/components/SwitchComponent.h | 1 - es-core/src/components/VideoComponent.h | 6 ------ es-core/src/components/VideoFFmpegComponent.cpp | 4 ++-- es-core/src/components/VideoFFmpegComponent.h | 2 +- 9 files changed, 13 insertions(+), 26 deletions(-) diff --git a/es-app/src/guis/GuiMetaDataEd.cpp b/es-app/src/guis/GuiMetaDataEd.cpp index 40593ba15..4104af36f 100644 --- a/es-app/src/guis/GuiMetaDataEd.cpp +++ b/es-app/src/guis/GuiMetaDataEd.cpp @@ -149,8 +149,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md, case MD_BOOL: { ed = std::make_shared(); // Make the switches slightly smaller. - glm::vec2 switchSize {ed->getSize() * 0.9f}; - ed->setResize(ceilf(switchSize.x), switchSize.y); + ed->setSize(glm::ceil(ed->getSize() * 0.9f)); ed->setChangedColor(ICONCOLOR_USERMARKED); row.addElement(ed, false, true); diff --git a/es-core/src/GuiComponent.h b/es-core/src/GuiComponent.h index 827bb57bc..8727af152 100644 --- a/es-core/src/GuiComponent.h +++ b/es-core/src/GuiComponent.h @@ -104,8 +104,8 @@ public: virtual glm::vec2 getSize() const { return mSize; } void setSize(const glm::vec2& size) { setSize(size.x, size.y); } void setSize(const float w, const float h); - virtual void setResize(float width, float height) {} - virtual void setResize(float width, float height, bool rasterize) {} + virtual void setResize(const float width, const float height) {} + virtual void setResize(const glm::vec2& size, bool rasterize = true) {} virtual void onSizeChanged() {} virtual glm::vec2 getRotationSize() const { return getSize(); } diff --git a/es-core/src/components/AnimatedImageComponent.cpp b/es-core/src/components/AnimatedImageComponent.cpp index b1745954d..4f530cc5a 100644 --- a/es-core/src/components/AnimatedImageComponent.cpp +++ b/es-core/src/components/AnimatedImageComponent.cpp @@ -32,7 +32,7 @@ void AnimatedImageComponent::load(const AnimationDef* def) } auto img = std::unique_ptr(new ImageComponent); - img->setResize(mSize.x, mSize.y); + img->setResize(mSize); img->setImage(std::string(def->frames[i].path), false); mFrames.push_back(ImageFrame(std::move(img), def->frames[i].time)); @@ -53,9 +53,8 @@ void AnimatedImageComponent::reset() void AnimatedImageComponent::onSizeChanged() { - for (auto it = mFrames.cbegin(); it != mFrames.cend(); ++it) { - it->first->setResize(mSize.x, mSize.y); - } + for (auto it = mFrames.cbegin(); it != mFrames.cend(); ++it) + it->first->setResize(mSize); } void AnimatedImageComponent::update(int deltaTime) diff --git a/es-core/src/components/ImageComponent.cpp b/es-core/src/components/ImageComponent.cpp index fd9c142c4..9922485b8 100644 --- a/es-core/src/components/ImageComponent.cpp +++ b/es-core/src/components/ImageComponent.cpp @@ -123,16 +123,16 @@ void ImageComponent::setImage(const std::shared_ptr& texture, b resize(); } -void ImageComponent::setResize(float width, float height) +void ImageComponent::setResize(const float width, const float height) { mTargetSize = glm::vec2 {width, height}; mTargetIsMax = false; resize(); } -void ImageComponent::setResize(float width, float height, bool rasterize) +void ImageComponent::setResize(const glm::vec2& size, bool rasterize) { - mTargetSize = glm::vec2 {width, height}; + mTargetSize = size; mTargetIsMax = false; resize(rasterize); } diff --git a/es-core/src/components/ImageComponent.h b/es-core/src/components/ImageComponent.h index 2a8eb2e8c..54d0d6e63 100644 --- a/es-core/src/components/ImageComponent.h +++ b/es-core/src/components/ImageComponent.h @@ -39,11 +39,7 @@ public: // Can be set before or after an image is loaded. // setMaxSize() and setResize() are mutually exclusive. void setResize(const float width, const float height) override; - void setResize(const glm::vec2& size, bool rasterize = true) - { - setResize(size.x, size.y, rasterize); - } - void setResize(const float width, const float height, bool rasterize) override; + void setResize(const glm::vec2& size, bool rasterize = true) override; // Resize the image to be as large as possible but fit within a box of this size. // Can be set before or after an image is loaded. diff --git a/es-core/src/components/SwitchComponent.h b/es-core/src/components/SwitchComponent.h index 653f3d13a..60843e59a 100644 --- a/es-core/src/components/SwitchComponent.h +++ b/es-core/src/components/SwitchComponent.h @@ -22,7 +22,6 @@ public: void render(const glm::mat4& parentTrans) override; void onSizeChanged() override { mImage.setSize(mSize); } - void setResize(float width, float height) override { setSize(width, height); } bool getState() const { return mState; } void setState(bool state); std::string getValue() const override; diff --git a/es-core/src/components/VideoComponent.h b/es-core/src/components/VideoComponent.h index 8072930a0..d214dead5 100644 --- a/es-core/src/components/VideoComponent.h +++ b/es-core/src/components/VideoComponent.h @@ -76,12 +76,6 @@ public: void update(int deltaTime) override; - // Resize the video to fit this size. If one axis is zero, scale that axis to maintain - // aspect ratio. If both are non-zero, potentially break the aspect ratio. If both are - // zero, no resizing. This can be set before or after a video is loaded. - // setMaxSize() and setResize() are mutually exclusive. - virtual void setResize(float width, float height) override = 0; - // Resize the video to be as large as possible but fit within a box of this size. // This can be set before or after a video is loaded. // Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive. diff --git a/es-core/src/components/VideoFFmpegComponent.cpp b/es-core/src/components/VideoFFmpegComponent.cpp index 05a80b638..b78994535 100644 --- a/es-core/src/components/VideoFFmpegComponent.cpp +++ b/es-core/src/components/VideoFFmpegComponent.cpp @@ -60,12 +60,12 @@ VideoFFmpegComponent::VideoFFmpegComponent() { } -void VideoFFmpegComponent::setResize(float width, float height) +void VideoFFmpegComponent::setResize(const float width, const float height) { // This resize function is used when stretching videos to full screen in the video screensaver. mTargetSize = glm::vec2 {width, height}; mTargetIsMax = false; - mStaticImage.setResize(width, height); + mStaticImage.setResize(mTargetSize); resize(); } diff --git a/es-core/src/components/VideoFFmpegComponent.h b/es-core/src/components/VideoFFmpegComponent.h index 240fd2a6a..e4f69147d 100644 --- a/es-core/src/components/VideoFFmpegComponent.h +++ b/es-core/src/components/VideoFFmpegComponent.h @@ -40,7 +40,7 @@ public: // aspect ratio. If both are non-zero, potentially break the aspect ratio. If both are // zero, no resizing. This can be set before or after a video is loaded. // setMaxSize() and setResize() are mutually exclusive. - void setResize(float width, float height) override; + void setResize(const float width, const float height) override; // Resize the video to be as large as possible but fit within a box of this size. // This can be set before or after a video is loaded.