mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 07:35:38 +00:00
Added a 'cropPos' property to the video element
This commit is contained in:
parent
96452849e7
commit
3008011acd
|
@ -323,8 +323,9 @@ std::map<std::string, std::map<std::string, ThemeData::ElementPropertyType>>
|
||||||
{"video",
|
{"video",
|
||||||
{{"pos", NORMALIZED_PAIR},
|
{{"pos", NORMALIZED_PAIR},
|
||||||
{"size", NORMALIZED_PAIR},
|
{"size", NORMALIZED_PAIR},
|
||||||
{"cropSize", NORMALIZED_PAIR},
|
|
||||||
{"maxSize", NORMALIZED_PAIR},
|
{"maxSize", NORMALIZED_PAIR},
|
||||||
|
{"cropSize", NORMALIZED_PAIR},
|
||||||
|
{"cropPos", NORMALIZED_PAIR},
|
||||||
{"origin", NORMALIZED_PAIR},
|
{"origin", NORMALIZED_PAIR},
|
||||||
{"rotation", FLOAT},
|
{"rotation", FLOAT},
|
||||||
{"rotationOrigin", NORMALIZED_PAIR},
|
{"rotationOrigin", NORMALIZED_PAIR},
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
//
|
//
|
||||||
// ES-DE
|
// ES-DE Frontend
|
||||||
// VideoComponent.cpp
|
// VideoComponent.cpp
|
||||||
//
|
//
|
||||||
// Base class for playing videos.
|
// Base class for playing videos.
|
||||||
|
@ -26,6 +26,8 @@ VideoComponent::VideoComponent()
|
||||||
, mVideoCornerRadius {0.0f}
|
, mVideoCornerRadius {0.0f}
|
||||||
, mColorGradientHorizontal {true}
|
, mColorGradientHorizontal {true}
|
||||||
, mTargetSize {0.0f, 0.0f}
|
, mTargetSize {0.0f, 0.0f}
|
||||||
|
, mCropPos {0.5f, 0.5f}
|
||||||
|
, mCropOffset {0.0f, 0.0f}
|
||||||
, mVideoAreaPos {0.0f, 0.0f}
|
, mVideoAreaPos {0.0f, 0.0f}
|
||||||
, mVideoAreaSize {0.0f, 0.0f}
|
, mVideoAreaSize {0.0f, 0.0f}
|
||||||
, mTopLeftCrop {0.0f, 0.0f}
|
, mTopLeftCrop {0.0f, 0.0f}
|
||||||
|
@ -161,6 +163,8 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
|
||||||
glm::vec2 videoCropSize {elem->get<glm::vec2>("cropSize")};
|
glm::vec2 videoCropSize {elem->get<glm::vec2>("cropSize")};
|
||||||
videoCropSize.x = glm::clamp(videoCropSize.x, 0.01f, 2.0f);
|
videoCropSize.x = glm::clamp(videoCropSize.x, 0.01f, 2.0f);
|
||||||
videoCropSize.y = glm::clamp(videoCropSize.y, 0.01f, 2.0f);
|
videoCropSize.y = glm::clamp(videoCropSize.y, 0.01f, 2.0f);
|
||||||
|
if (elem->has("cropPos"))
|
||||||
|
mCropPos = glm::clamp(elem->get<glm::vec2>("cropPos"), 0.0f, 1.0f);
|
||||||
setCroppedSize(videoCropSize * scale);
|
setCroppedSize(videoCropSize * scale);
|
||||||
mVideoAreaSize = videoCropSize * scale;
|
mVideoAreaSize = videoCropSize * scale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
//
|
//
|
||||||
// ES-DE
|
// ES-DE Frontend
|
||||||
// VideoComponent.h
|
// VideoComponent.h
|
||||||
//
|
//
|
||||||
// Base class for playing videos.
|
// Base class for playing videos.
|
||||||
|
@ -115,6 +115,8 @@ protected:
|
||||||
float mVideoCornerRadius;
|
float mVideoCornerRadius;
|
||||||
bool mColorGradientHorizontal;
|
bool mColorGradientHorizontal;
|
||||||
glm::vec2 mTargetSize;
|
glm::vec2 mTargetSize;
|
||||||
|
glm::vec2 mCropPos;
|
||||||
|
glm::vec2 mCropOffset;
|
||||||
glm::vec2 mVideoAreaPos;
|
glm::vec2 mVideoAreaPos;
|
||||||
glm::vec2 mVideoAreaSize;
|
glm::vec2 mVideoAreaSize;
|
||||||
glm::vec2 mTopLeftCrop;
|
glm::vec2 mTopLeftCrop;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
//
|
//
|
||||||
// ES-DE
|
// ES-DE Frontend
|
||||||
// VideoFFmpegComponent.cpp
|
// VideoFFmpegComponent.cpp
|
||||||
//
|
//
|
||||||
// Video player based on FFmpeg.
|
// Video player based on FFmpeg.
|
||||||
|
@ -88,6 +88,7 @@ void VideoFFmpegComponent::setCroppedSize(const glm::vec2& size)
|
||||||
mTargetSize = size;
|
mTargetSize = size;
|
||||||
mTargetIsMax = false;
|
mTargetIsMax = false;
|
||||||
mTargetIsCrop = true;
|
mTargetIsCrop = true;
|
||||||
|
mStaticImage.setCropPos(mCropPos);
|
||||||
mStaticImage.setCroppedSize(size);
|
mStaticImage.setCroppedSize(size);
|
||||||
resize();
|
resize();
|
||||||
}
|
}
|
||||||
|
@ -122,6 +123,9 @@ void VideoFFmpegComponent::resize()
|
||||||
// Size texture to allow for cropped video to fill the entire area.
|
// Size texture to allow for cropped video to fill the entire area.
|
||||||
const float cropFactor {
|
const float cropFactor {
|
||||||
std::max(mTargetSize.x / textureSize.x, mTargetSize.y / textureSize.y)};
|
std::max(mTargetSize.x / textureSize.x, mTargetSize.y / textureSize.y)};
|
||||||
|
mTopLeftCrop = {0.0f, 0.0f};
|
||||||
|
mBottomRightCrop = {1.0f, 1.0f};
|
||||||
|
mCropOffset = {0.0f, 0.0f};
|
||||||
mSize = textureSize * cropFactor;
|
mSize = textureSize * cropFactor;
|
||||||
|
|
||||||
if (std::round(mSize.y) > std::round(mTargetSize.y)) {
|
if (std::round(mSize.y) > std::round(mTargetSize.y)) {
|
||||||
|
@ -129,12 +133,20 @@ void VideoFFmpegComponent::resize()
|
||||||
mTopLeftCrop.y = cropSize / 2.0f;
|
mTopLeftCrop.y = cropSize / 2.0f;
|
||||||
mBottomRightCrop.y = 1.0f - (cropSize / 2.0f);
|
mBottomRightCrop.y = 1.0f - (cropSize / 2.0f);
|
||||||
mSize.y = mSize.y - (mSize.y * cropSize);
|
mSize.y = mSize.y - (mSize.y * cropSize);
|
||||||
|
if (mCropPos.y != 0.5f) {
|
||||||
|
const float cropPosY {mCropPos.y + 0.5f};
|
||||||
|
mCropOffset.y = (cropSize * cropPosY) - cropSize;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
const float cropSize {1.0f - (mTargetSize.x / std::round(mSize.x))};
|
const float cropSize {1.0f - (mTargetSize.x / std::round(mSize.x))};
|
||||||
mTopLeftCrop.x = cropSize / 2.0f;
|
mTopLeftCrop.x = cropSize / 2.0f;
|
||||||
mBottomRightCrop.x = 1.0f - (cropSize / 2.0f);
|
mBottomRightCrop.x = 1.0f - (cropSize / 2.0f);
|
||||||
mSize.x = mSize.x - (mSize.x * cropSize);
|
mSize.x = mSize.x - (mSize.x * cropSize);
|
||||||
|
if (mCropPos.x != 0.5f) {
|
||||||
|
const float cropPosX {mCropPos.x + 0.5f};
|
||||||
|
mCropOffset.x = cropSize - (cropSize * cropPosX);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -201,10 +213,10 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// clang-format off
|
// clang-format off
|
||||||
vertices[0] = {{0.0f, 0.0f }, {mTopLeftCrop.x, 1.0f - mBottomRightCrop.y}, 0xFFFFFFFF};
|
vertices[0] = {{0.0f, 0.0f }, {mTopLeftCrop.x - mCropOffset.x, 1.0f - mBottomRightCrop.y + mCropOffset.y}, 0xFFFFFFFF};
|
||||||
vertices[1] = {{0.0f, mSize.y}, {mTopLeftCrop.x, 1.0f - mTopLeftCrop.y }, 0xFFFFFFFF};
|
vertices[1] = {{0.0f, mSize.y}, {mTopLeftCrop.x - mCropOffset.x, 1.0f - mTopLeftCrop.y + mCropOffset.y }, 0xFFFFFFFF};
|
||||||
vertices[2] = {{mSize.x, 0.0f }, {mBottomRightCrop.x * 1.0f, 1.0f - mBottomRightCrop.y}, 0xFFFFFFFF};
|
vertices[2] = {{mSize.x, 0.0f }, {(mBottomRightCrop.x * 1.0f) - mCropOffset.x, 1.0f - mBottomRightCrop.y + mCropOffset.y}, 0xFFFFFFFF};
|
||||||
vertices[3] = {{mSize.x, mSize.y}, {mBottomRightCrop.x * 1.0f, 1.0f - mTopLeftCrop.y }, 0xFFFFFFFF};
|
vertices[3] = {{mSize.x, mSize.y}, {(mBottomRightCrop.x * 1.0f) - mCropOffset.x, 1.0f - mTopLeftCrop.y + mCropOffset.y }, 0xFFFFFFFF};
|
||||||
// clang-format on
|
// clang-format on
|
||||||
|
|
||||||
vertices[0].color = mColorShift;
|
vertices[0].color = mColorShift;
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
// SPDX-License-Identifier: MIT
|
// SPDX-License-Identifier: MIT
|
||||||
//
|
//
|
||||||
// ES-DE
|
// ES-DE Frontend
|
||||||
// VideoFFmpegComponent.h
|
// VideoFFmpegComponent.h
|
||||||
//
|
//
|
||||||
// Video player based on FFmpeg.
|
// Video player based on FFmpeg.
|
||||||
|
|
Loading…
Reference in a new issue