From 542185152669fcf4d6f8aeeb97987cade293a3b5 Mon Sep 17 00:00:00 2001 From: Scratch Date: Fri, 10 Apr 2020 20:47:06 +1000 Subject: [PATCH] UI: Add window projector option "fit to content" Adds an option to the context menu of a windowed projector to allow resizing the aspect ratio of the client area of the window to the contents of what's being projected (so that there's no extra space). --- UI/data/locale/en-US.ini | 1 + UI/window-projector.cpp | 34 +++++++++++++++++++++++++++++++++- UI/window-projector.hpp | 1 + 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/UI/data/locale/en-US.ini b/UI/data/locale/en-US.ini index dcbd055a8..eaa84d002 100644 --- a/UI/data/locale/en-US.ini +++ b/UI/data/locale/en-US.ini @@ -42,6 +42,7 @@ SceneWindow="Windowed Projector (Scene)" SourceWindow="Windowed Projector (Source)" MultiviewProjector="Multiview (Fullscreen)" MultiviewWindowed="Multiview (Windowed)" +ResizeProjectorWindowToContent="Fit window to content" Clear="Clear" Revert="Revert" Show="Show" diff --git a/UI/window-projector.cpp b/UI/window-projector.cpp index 73fe8b87a..2ea160067 100644 --- a/UI/window-projector.cpp +++ b/UI/window-projector.cpp @@ -828,10 +828,15 @@ void OBSProjector::mousePressEvent(QMouseEvent *event) SLOT(OpenFullScreenProjector())); popup.addMenu(projectorMenu); - if (GetMonitor() > -1) + if (GetMonitor() > -1) { popup.addAction(QTStr("Windowed"), this, SLOT(OpenWindowedProjector())); + } else if (!this->isMaximized()) { + popup.addAction(QTStr("ResizeProjectorWindowToContent"), + this, SLOT(ResizeToContent())); + } + popup.addAction(QTStr("Close"), this, SLOT(EscapeTriggered())); popup.exec(QCursor::pos()); } @@ -1055,6 +1060,33 @@ void OBSProjector::OpenWindowedProjector() UpdateProjectorTitle(QT_UTF8(obs_source_get_name(source))); } +void OBSProjector::ResizeToContent() +{ + OBSSource source = GetSource(); + uint32_t targetCX; + uint32_t targetCY; + int x, y, newX, newY; + float scale; + + if (source) { + targetCX = std::max(obs_source_get_width(source), 1u); + targetCY = std::max(obs_source_get_height(source), 1u); + } else { + struct obs_video_info ovi; + obs_get_video_info(&ovi); + targetCX = ovi.base_width; + targetCY = ovi.base_height; + } + + QSize size = this->size(); + GetScaleAndCenterPos(targetCX, targetCY, size.width(), size.height(), x, + y, scale); + + newX = size.width() - (x * 2); + newY = size.height() - (y * 2); + resize(newX, newY); +} + void OBSProjector::closeEvent(QCloseEvent *event) { EscapeTriggered(); diff --git a/UI/window-projector.hpp b/UI/window-projector.hpp index 0831e9187..8b5e5a918 100644 --- a/UI/window-projector.hpp +++ b/UI/window-projector.hpp @@ -78,6 +78,7 @@ private: private slots: void EscapeTriggered(); void OpenFullScreenProjector(); + void ResizeToContent(); void OpenWindowedProjector(); public: -- GitLab