Refactored some image resizing functions.

This commit is contained in:
Leon Styhre 2022-11-07 23:58:22 +01:00
parent c73ff02012
commit b4338a3fb7
9 changed files with 13 additions and 26 deletions

View file

@ -149,8 +149,7 @@ GuiMetaDataEd::GuiMetaDataEd(MetaDataList* md,
case MD_BOOL: {
ed = std::make_shared<SwitchComponent>();
// 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);

View file

@ -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(); }

View file

@ -32,7 +32,7 @@ void AnimatedImageComponent::load(const AnimationDef* def)
}
auto img = std::unique_ptr<ImageComponent>(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)

View file

@ -123,16 +123,16 @@ void ImageComponent::setImage(const std::shared_ptr<TextureResource>& 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);
}

View file

@ -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.

View file

@ -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;

View file

@ -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.

View file

@ -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();
}

View file

@ -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.