mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2025-04-10 19:15:13 +00:00
Added 'imageSize', 'imageMaxSize', 'imageCropSize' and 'imageCropPos' properties to the video element
This commit is contained in:
parent
9c5166abab
commit
15ea7dcb34
|
@ -355,6 +355,10 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
|||
{"maxSize", NORMALIZED_PAIR},
|
||||
{"cropSize", NORMALIZED_PAIR},
|
||||
{"cropPos", NORMALIZED_PAIR},
|
||||
{"imageSize", NORMALIZED_PAIR},
|
||||
{"imageMaxSize", NORMALIZED_PAIR},
|
||||
{"imageCropSize", NORMALIZED_PAIR},
|
||||
{"imageCropPos", NORMALIZED_PAIR},
|
||||
{"origin", NORMALIZED_PAIR},
|
||||
{"rotation", FLOAT},
|
||||
{"rotationOrigin", NORMALIZED_PAIR},
|
||||
|
|
|
@ -28,9 +28,11 @@ VideoComponent::VideoComponent()
|
|||
, mColorGradientHorizontal {true}
|
||||
, mTargetSize {0.0f, 0.0f}
|
||||
, mCropPos {0.5f, 0.5f}
|
||||
, mImageCropPos {0.5f, 0.5f}
|
||||
, mCropOffset {0.0f, 0.0f}
|
||||
, mVideoAreaPos {0.0f, 0.0f}
|
||||
, mVideoAreaSize {0.0f, 0.0f}
|
||||
, mImageAreaSize {0.0f, 0.0f}
|
||||
, mTopLeftCrop {0.0f, 0.0f}
|
||||
, mBottomRightCrop {1.0f, 1.0f}
|
||||
, mPillarboxThreshold {0.85f, 0.90f}
|
||||
|
@ -137,6 +139,41 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
|||
getParent()->getSize() :
|
||||
glm::vec2 {mRenderer->getScreenWidth(), mRenderer->getScreenHeight()}};
|
||||
|
||||
if (properties & ThemeFlags::SIZE) {
|
||||
if (elem->has("imageSize")) {
|
||||
glm::vec2 imageSize {elem->get<glm::vec2>("imageSize")};
|
||||
if (imageSize == glm::vec2 {0.0f, 0.0f}) {
|
||||
LOG(LogWarning)
|
||||
<< "VideoComponent: Invalid theme configuration, property \"imageSize\" "
|
||||
"for element \""
|
||||
<< element.substr(6) << "\" is set to zero";
|
||||
imageSize = {0.01f, 0.01f};
|
||||
}
|
||||
if (imageSize.x > 0.0f)
|
||||
imageSize.x = glm::clamp(imageSize.x, 0.01f, 2.0f);
|
||||
if (imageSize.y > 0.0f)
|
||||
imageSize.y = glm::clamp(imageSize.y, 0.01f, 2.0f);
|
||||
setImageResize(imageSize.x * scale.x, imageSize.y * scale.y);
|
||||
mImageAreaSize = imageSize * scale;
|
||||
}
|
||||
else if (elem->has("imageMaxSize")) {
|
||||
glm::vec2 imageMaxSize {elem->get<glm::vec2>("imageMaxSize")};
|
||||
imageMaxSize.x = glm::clamp(imageMaxSize.x, 0.01f, 2.0f);
|
||||
imageMaxSize.y = glm::clamp(imageMaxSize.y, 0.01f, 2.0f);
|
||||
setImageMaxSize(imageMaxSize * scale);
|
||||
mImageAreaSize = imageMaxSize * scale;
|
||||
}
|
||||
else if (elem->has("imageCropSize")) {
|
||||
glm::vec2 imageCropSize {elem->get<glm::vec2>("imageCropSize")};
|
||||
imageCropSize.x = glm::clamp(imageCropSize.x, 0.01f, 2.0f);
|
||||
imageCropSize.y = glm::clamp(imageCropSize.y, 0.01f, 2.0f);
|
||||
if (elem->has("imageCropPos"))
|
||||
mImageCropPos = glm::clamp(elem->get<glm::vec2>("imageCropPos"), 0.0f, 1.0f);
|
||||
setImageCroppedSize(imageCropSize * scale);
|
||||
mImageAreaSize = imageCropSize * scale;
|
||||
}
|
||||
}
|
||||
|
||||
if (properties & ThemeFlags::SIZE) {
|
||||
if (elem->has("size")) {
|
||||
glm::vec2 videoSize {elem->get<glm::vec2>("size")};
|
||||
|
|
|
@ -73,14 +73,20 @@ public:
|
|||
|
||||
void update(int deltaTime) 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.
|
||||
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
|
||||
// Resize the video to be as large as possible within the defined size without breaking
|
||||
// its aspect ratio. This can be set before or after a video is loaded.
|
||||
// setMaxSize() and setResize() are mutually exclusive.
|
||||
virtual void setMaxSize(float width, float height) = 0;
|
||||
void setMaxSize(const glm::vec2& size) { setMaxSize(size.x, size.y); }
|
||||
// Resize and crop the video so it fills the entire area.
|
||||
virtual void setCroppedSize(const glm::vec2& size) = 0;
|
||||
|
||||
// Specific size functions for the static image.
|
||||
virtual void setImageResize(const float width, const float height) = 0;
|
||||
virtual void setImageMaxSize(float width, float height) = 0;
|
||||
void setImageMaxSize(const glm::vec2& size) { setImageMaxSize(size.x, size.y); }
|
||||
virtual void setImageCroppedSize(const glm::vec2& size) = 0;
|
||||
|
||||
// Basic video controls.
|
||||
void startVideoPlayer();
|
||||
virtual void stopVideoPlayer(bool muteAudio = true) {}
|
||||
|
@ -116,9 +122,11 @@ protected:
|
|||
bool mColorGradientHorizontal;
|
||||
glm::vec2 mTargetSize;
|
||||
glm::vec2 mCropPos;
|
||||
glm::vec2 mImageCropPos;
|
||||
glm::vec2 mCropOffset;
|
||||
glm::vec2 mVideoAreaPos;
|
||||
glm::vec2 mVideoAreaSize;
|
||||
glm::vec2 mImageAreaSize;
|
||||
glm::vec2 mTopLeftCrop;
|
||||
glm::vec2 mBottomRightCrop;
|
||||
glm::vec2 mPillarboxThreshold;
|
||||
|
|
|
@ -69,7 +69,8 @@ void VideoFFmpegComponent::setResize(const float width, const float height)
|
|||
mTargetSize = glm::vec2 {width, height};
|
||||
mTargetIsMax = false;
|
||||
mTargetIsCrop = false;
|
||||
mStaticImage.setResize(mTargetSize);
|
||||
if (mImageAreaSize == glm::vec2 {0.0f, 0.0f})
|
||||
mStaticImage.setResize(mTargetSize);
|
||||
resize();
|
||||
}
|
||||
|
||||
|
@ -80,7 +81,8 @@ void VideoFFmpegComponent::setMaxSize(float width, float height)
|
|||
mTargetSize = glm::vec2 {width, height};
|
||||
mTargetIsMax = true;
|
||||
mTargetIsCrop = false;
|
||||
mStaticImage.setMaxSize(width, height);
|
||||
if (mImageAreaSize == glm::vec2 {0.0f, 0.0f})
|
||||
mStaticImage.setMaxSize(width, height);
|
||||
resize();
|
||||
}
|
||||
|
||||
|
@ -89,11 +91,29 @@ void VideoFFmpegComponent::setCroppedSize(const glm::vec2& size)
|
|||
mTargetSize = size;
|
||||
mTargetIsMax = false;
|
||||
mTargetIsCrop = true;
|
||||
mStaticImage.setCropPos(mCropPos);
|
||||
mStaticImage.setCroppedSize(size);
|
||||
if (mImageAreaSize == glm::vec2 {0.0f, 0.0f}) {
|
||||
mStaticImage.setCropPos(mCropPos);
|
||||
mStaticImage.setCroppedSize(size);
|
||||
}
|
||||
resize();
|
||||
}
|
||||
|
||||
void VideoFFmpegComponent::setImageResize(const float width, const float height)
|
||||
{
|
||||
mStaticImage.setResize(glm::vec2 {width, height});
|
||||
}
|
||||
|
||||
void VideoFFmpegComponent::setImageMaxSize(float width, float height)
|
||||
{
|
||||
mStaticImage.setMaxSize(width, height);
|
||||
}
|
||||
|
||||
void VideoFFmpegComponent::setImageCroppedSize(const glm::vec2& size)
|
||||
{
|
||||
mStaticImage.setCropPos(mImageCropPos);
|
||||
mStaticImage.setCroppedSize(size);
|
||||
}
|
||||
|
||||
void VideoFFmpegComponent::resize()
|
||||
{
|
||||
if (!mTexture)
|
||||
|
|
|
@ -42,13 +42,18 @@ public:
|
|||
// setMaxSize() and setResize() are mutually exclusive.
|
||||
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.
|
||||
// Never breaks the aspect ratio. setMaxSize() and setResize() are mutually exclusive.
|
||||
// Resize the video to be as large as possible within the defined size without breaking
|
||||
// its aspect ratio. This can be set before or after a video is loaded.
|
||||
// setMaxSize() and setResize() are mutually exclusive.
|
||||
void setMaxSize(float width, float height) override;
|
||||
// Resize and crop the video so it fills the entire area.
|
||||
void setCroppedSize(const glm::vec2& size) override;
|
||||
|
||||
// Specific size functions for the static image.
|
||||
void setImageResize(const float width, const float height) override;
|
||||
void setImageMaxSize(float width, float height) override;
|
||||
void setImageCroppedSize(const glm::vec2& size) override;
|
||||
|
||||
// Basic video controls.
|
||||
void stopVideoPlayer(bool muteAudio = true) override;
|
||||
void pauseVideoPlayer() override;
|
||||
|
|
Loading…
Reference in a new issue