BizHawk/BizHawk.Client.EmuHawk/AVOut/VideoWriterChooserForm.cs

154 lines
3.6 KiB
C#
Raw Normal View History

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using BizHawk.Client.Common;
namespace BizHawk.Client.EmuHawk
{
/// <summary>
/// implements a simple dialog which chooses an IVideoWriter to record with
/// </summary>
public partial class VideoWriterChooserForm : Form
{
2017-04-18 17:27:44 +00:00
private VideoWriterChooserForm()
{
InitializeComponent();
CaptureWidth = Global.Emulator.CoreComm.NominalWidth;
CaptureHeight = Global.Emulator.CoreComm.NominalHeight;
if (Global.Config.AVI_CaptureOSD)
{
using (var bb = GlobalWin.MainForm.CaptureOSD())
{
CaptureWidth = bb.Width;
CaptureHeight = bb.Height;
}
}
2017-04-18 17:27:44 +00:00
lblSize.Text = $"Size:\r\n{CaptureWidth}x{CaptureHeight}";
if (CaptureWidth % 4 != 0 || CaptureHeight % 4 != 0)
2017-04-18 17:27:44 +00:00
{
lblResolutionWarning.Visible = true;
2017-04-18 17:27:44 +00:00
}
else
{
lblResolutionWarning.Visible = false;
}
}
2017-04-18 17:27:44 +00:00
private int CaptureWidth, CaptureHeight;
/// <summary>
/// chose an IVideoWriter
/// </summary>
/// <param name="list">list of IVideoWriters to choose from</param>
/// <param name="owner">parent window</param>
/// <returns>user choice, or null on Cancel\Close\invalid</returns>
public static IVideoWriter DoVideoWriterChoserDlg(IEnumerable<VideoWriterInfo> list, IWin32Window owner, out int resizew, out int resizeh, out bool pad, out bool audiosync)
{
2017-04-18 17:27:44 +00:00
VideoWriterChooserForm dlg = new VideoWriterChooserForm
{
2017-05-10 11:45:23 +00:00
labelDescriptionBody = { Text = "" }
2017-04-18 17:27:44 +00:00
};
2017-04-18 17:27:44 +00:00
int idx = 0;
int idx_select = -1;
dlg.listBox1.BeginUpdate();
foreach (var vw in list)
2014-10-10 18:09:00 +00:00
{
2017-04-18 17:27:44 +00:00
dlg.listBox1.Items.Add(vw);
if (vw.Attribs.ShortName == Global.Config.VideoWriter)
2014-10-10 18:09:00 +00:00
{
2017-04-18 17:27:44 +00:00
idx_select = idx;
2014-10-10 18:09:00 +00:00
}
2017-04-18 17:27:44 +00:00
idx++;
2014-10-10 18:09:00 +00:00
}
2012-06-17 15:09:53 +00:00
2017-04-18 17:27:44 +00:00
dlg.listBox1.SelectedIndex = idx_select;
dlg.listBox1.EndUpdate();
foreach (Control c in dlg.panelSizeSelect.Controls)
2017-04-18 17:27:44 +00:00
{
c.Enabled = false;
2017-04-18 17:27:44 +00:00
}
DialogResult result = dlg.ShowDialog(owner);
IVideoWriter ret;
if (result == DialogResult.OK && dlg.listBox1.SelectedIndex != -1)
2012-06-17 15:09:53 +00:00
{
2014-10-10 18:09:00 +00:00
var vwi = (VideoWriterInfo)dlg.listBox1.SelectedItem;
ret = vwi.Create();
Global.Config.VideoWriter = vwi.Attribs.ShortName;
2012-06-17 15:09:53 +00:00
}
else
2014-10-10 18:09:00 +00:00
{
ret = null;
2014-10-10 18:09:00 +00:00
}
if (ret != null && dlg.checkBoxResize.Checked)
{
resizew = dlg.numericTextBoxW.IntValue;
resizeh = dlg.numericTextBoxH.IntValue;
}
else
{
resizew = -1;
resizeh = -1;
}
pad = dlg.checkBoxPad.Checked;
audiosync = dlg.checkBoxASync.Checked;
dlg.Dispose();
return ret;
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
2017-04-18 17:27:44 +00:00
labelDescriptionBody.Text = listBox1.SelectedIndex != -1
? ((VideoWriterInfo)listBox1.SelectedItem).Attribs.Description
2017-05-10 11:45:23 +00:00
: "";
}
private void checkBoxResize_CheckedChanged(object sender, EventArgs e)
{
foreach (Control c in panelSizeSelect.Controls)
2017-04-18 17:27:44 +00:00
{
c.Enabled = checkBoxResize.Checked;
2017-04-18 17:27:44 +00:00
}
}
private void buttonAuto_Click(object sender, EventArgs e)
{
numericTextBoxW.Text = CaptureWidth.ToString();
numericTextBoxH.Text = CaptureHeight.ToString();
}
private void buttonOK_Click(object sender, EventArgs e)
{
if (checkBoxResize.Checked)
{
try
{
if (numericTextBoxW.IntValue < 1 || numericTextBoxH.IntValue < 1)
{
MessageBox.Show(this, "Size must be positive!");
DialogResult = DialogResult.None;
}
}
catch (FormatException)
{
MessageBox.Show(this, "Size must be numeric!");
DialogResult = DialogResult.None;
}
}
}
}
}