Browse Source

UI: Add ability to resize output based on source size

cg2121 7 years ago
parent
commit
7f9109091d
3 changed files with 55 additions and 0 deletions
  1. 5 0
      UI/data/locale/en-US.ini
  2. 48 0
      UI/window-basic-main.cpp
  3. 2 0
      UI/window-basic-main.hpp

+ 5 - 0
UI/data/locale/en-US.ini

@@ -865,3 +865,8 @@ About.GetInvolved="Get Involved"
 About.Authors="Authors"
 About.License="License"
 About.Contribute="Want to contribute?"
+
+# Dynamic output size
+ResizeOutputSizeOfSource="Resize output (source size)"
+ResizeOutputSizeOfSource.Text="The base and canvas resolution will be resized to the size of the current source."
+ResizeOutputSizeOfSource.Continue="Do you want to continue?"

+ 48 - 0
UI/window-basic-main.cpp

@@ -4227,6 +4227,21 @@ void OBSBasic::CreateSourcePopupMenu(int idx, bool preview)
 			popup.addSeparator();
 		}
 
+		QAction *resizeOutput = popup.addAction(
+				QTStr("ResizeOutputSizeOfSource"), this,
+				SLOT(ResizeOutputSizeOfSource()));
+
+		int width = obs_source_get_width(source);
+		int height = obs_source_get_height(source);
+
+		resizeOutput->setEnabled(!(ui->streamButton->isChecked() ||
+				ui->recordButton->isChecked() ||
+				(replayBufferButton &&
+				replayBufferButton->isChecked())));
+
+		if (width == 0 || height == 0)
+			resizeOutput->setEnabled(false);
+
 		popup.addMenu(AddScaleFilteringMenu(sceneItem));
 		popup.addSeparator();
 
@@ -6733,6 +6748,39 @@ void OBSBasic::on_actionShowAbout_triggered()
 	about->setAttribute(Qt::WA_DeleteOnClose, true);
 }
 
+void OBSBasic::ResizeOutputSizeOfSource()
+{
+	if (ui->streamButton->isChecked() || ui->recordButton->isChecked() ||
+			(replayBufferButton && replayBufferButton->isChecked()))
+		return;
+
+	QMessageBox resize_output(this);
+	resize_output.setText(QTStr("ResizeOutputSizeOfSource.Text") +
+			"\n\n" + QTStr("ResizeOutputSizeOfSource.Continue"));
+	QAbstractButton *Yes = resize_output.addButton(QTStr("Yes"),
+			QMessageBox::YesRole);
+	resize_output.addButton(QTStr("No"), QMessageBox::NoRole);
+	resize_output.setIcon(QMessageBox::Warning);
+	resize_output.setWindowTitle(QTStr("ResizeOutputSizeOfSource"));
+	resize_output.exec();
+
+	if (resize_output.clickedButton() != Yes)
+		return;
+
+	OBSSource source = obs_sceneitem_get_source(GetCurrentSceneItem());
+
+	int width = obs_source_get_width(source);
+	int height = obs_source_get_height(source);
+
+	config_set_uint(basicConfig, "Video", "BaseCX", width);
+	config_set_uint(basicConfig, "Video", "BaseCY", height);
+	config_set_uint(basicConfig, "Video", "OutputCX", width);
+	config_set_uint(basicConfig, "Video", "OutputCY", height);
+
+	ResetVideo();
+	on_actionFitToScreen_triggered();
+}
+
 ColorSelect::ColorSelect(QWidget *parent)
 	: QWidget(parent),
 	  ui(new Ui::ColorSelect)

+ 2 - 0
UI/window-basic-main.hpp

@@ -742,6 +742,8 @@ private slots:
 
 	void StackedMixerAreaContextMenuRequested();
 
+	void ResizeOutputSizeOfSource();
+
 public slots:
 	void on_actionResetTransform_triggered();