Video pillarboxes and scanline rendering can now be controlled from the theme configuration.

This commit is contained in:
Leon Styhre 2022-02-12 17:46:31 +01:00
parent 6572fa8f23
commit e0540ee03b
3 changed files with 39 additions and 6 deletions

View file

@ -36,6 +36,9 @@ VideoComponent::VideoComponent()
, mGameLaunched {false}
, mBlockPlayer {false}
, mTargetIsMax {false}
, mDrawPillarboxes {true}
, mRenderScanlines {false}
, mLegacyTheme {false}
, mFadeIn {1.0f}
{
// Setup the default configuration.
@ -201,7 +204,7 @@ void VideoComponent::renderSnapshot(const glm::mat4& parentTrans)
// simply looks better than leaving an empty space where the video would have been located.
if (mWindow->getGuiStackSize() > 1 || (mConfig.showSnapshotNoVideo && mVideoPath.empty()) ||
(mStartDelayed && mConfig.showSnapshotDelay)) {
mStaticImage.setOpacity(mOpacity);
mStaticImage.setOpacity(mOpacity * mThemeOpacity);
mStaticImage.render(parentTrans);
}
}
@ -218,6 +221,8 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
const ThemeData::ThemeElement* elem = theme->getElement(view, element, "video");
mLegacyTheme = theme->isLegacyTheme();
if (!elem)
return;
@ -268,6 +273,16 @@ void VideoComponent::applyTheme(const std::shared_ptr<ThemeData>& theme,
if (properties & METADATA && elem->has("imageMetadata"))
setMetadataField(elem->get<std::string>("imageMetadata"));
if (elem->has("pillarboxes"))
mDrawPillarboxes = elem->get<bool>("pillarboxes");
// Scanlines are not compatible with video transparency.
if (elem->has("scanlines")) {
mRenderScanlines = elem->get<bool>("scanlines");
if (mRenderScanlines && mThemeOpacity != 0.0f)
mThemeOpacity = 1.0f;
}
if (elem->has("scrollFadeIn") && elem->get<bool>("scrollFadeIn"))
mComponentThemeFlags |= ComponentThemeFlags::SCROLL_FADE_IN;
}

View file

@ -47,6 +47,8 @@ public:
void setScreensaverMode(bool isScreensaver) { mScreensaverMode = isScreensaver; }
// Set the opacity for the embedded static image.
void setOpacity(float opacity) override { mOpacity = opacity; }
// Set whether to draw black pillarboxes/letterboxes behind videos.
void setDrawPillarboxes(bool state) { mDrawPillarboxes = state; }
bool hasStaticVideo() { return !mConfig.staticVideoPath.empty(); }
bool hasStaticImage() { return mStaticImage.getTextureSize() != glm::ivec2 {0, 0}; }
@ -139,6 +141,9 @@ protected:
bool mGameLaunched;
bool mBlockPlayer;
bool mTargetIsMax;
bool mDrawPillarboxes;
bool mRenderScanlines;
bool mLegacyTheme;
float mFadeIn; // Used for fading in the video screensaver.
Configuration mConfig;

View file

@ -123,6 +123,9 @@ void VideoFFmpegComponent::resize()
void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
{
if (!isVisible() || mThemeOpacity == 0.0f)
return;
VideoComponent::render(parentTrans);
glm::mat4 trans {parentTrans * getTransform()};
GuiComponent::renderChildren(trans);
@ -141,11 +144,18 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
Renderer::Vertex vertices[4];
Renderer::setMatrix(parentTrans);
unsigned int rectColor {0x000000FF};
if (mThemeOpacity != 1.0f) {
color = (static_cast<int>(mThemeOpacity * 255.0f) << 24) + 0x00FFFFFF;
rectColor = static_cast<int>(mThemeOpacity * 255.0f);
}
// Render the black rectangle behind the video.
if (mVideoRectangleCoords.size() == 4) {
Renderer::drawRect(mVideoRectangleCoords[0], mVideoRectangleCoords[1],
mVideoRectangleCoords[2], mVideoRectangleCoords[3], // Line break.
0x000000FF, 0x000000FF);
rectColor, rectColor);
}
// clang-format off
@ -205,9 +215,11 @@ void VideoFFmpegComponent::render(const glm::mat4& parentTrans)
// Render scanlines if this option is enabled. However, if this is the media viewer
// or the video screensaver, then skip this as the scanline rendering is then handled
// in those modules as a postprocessing step.
if ((!mScreensaverMode && !mMediaViewerMode) &&
Settings::getInstance()->getBool("GamelistVideoScanlines"))
vertices[0].shaders = Renderer::SHADER_SCANLINES;
if (!mScreensaverMode && !mMediaViewerMode) {
if ((mLegacyTheme && Settings::getInstance()->getBool("GamelistVideoScanlines")) ||
(!mLegacyTheme && mRenderScanlines))
vertices[0].shaders = Renderer::SHADER_SCANLINES;
}
#endif
// Render it.
@ -867,7 +879,8 @@ void VideoFFmpegComponent::calculateBlackRectangle()
if (mVideoAreaPos != glm::vec2 {} && mVideoAreaSize != glm::vec2 {}) {
mVideoRectangleCoords.clear();
if (Settings::getInstance()->getBool("GamelistVideoPillarbox")) {
if ((mLegacyTheme && Settings::getInstance()->getBool("GamelistVideoPillarbox")) ||
(!mLegacyTheme && mDrawPillarboxes)) {
float rectHeight;
float rectWidth;
// Video is in landscape orientation.