?? dxmutsettingsdlg.cs
字號:
SurfaceDescription desc = parent.BackBufferSurfaceDescription;
// Set up the dialog
dialog.SetLocation(0, 0);
dialog.SetSize(desc.Width, desc.Height);
dialog.SetBackgroundColors(new ColorValue((float)98/255, (float)138/255, (float)206/255),
new ColorValue((float)54/255, (float)105/255, (float)192/255),
new ColorValue((float)54/255, (float)105/255, (float)192/255),
new ColorValue((float)10/255, (float)73/255, (float)179/255) );
Device device = parent.Device;
device.BeginStateBlock();
device.RenderState.FillMode = FillMode.Solid;
state = device.EndStateBlock();
}
/// <summary>
/// Called when the device is lost
/// </summary>
public void OnLostDevice()
{
if (state != null)
state.Dispose();
state = null;
}
/// <summary>Destroy any resources</summary>
public void OnDestroyDevice(object sender, EventArgs e)
{
// Clear the focus
Dialog.ClearFocus();
// Unhook all the events we care about
resolution.Changed -= new EventHandler(OnResolutionChanged);
adapterCombo.Changed -= new EventHandler(OnAdapterChanged);
deviceCombo.Changed -= new EventHandler(OnDeviceChanged);
adapterFormatCombo.Changed -= new EventHandler(OnAdapterFormatChange);
refreshCombo.Changed -= new EventHandler(OnRefreshRateChanged);
backBufferCombo.Changed -= new EventHandler(OnBackBufferChanged);
depthStencilCombo.Changed -= new EventHandler(OnDepthStencilChanged);
multiSampleTypeCombo.Changed -= new EventHandler(OnMultisampleTypeChanged);
multiSampleQualityCombo.Changed -= new EventHandler(OnMultisampleQualityChanged);
vertexCombo.Changed -= new EventHandler(OnVertexProcessingChanged);
presentCombo.Changed -= new EventHandler(OnPresentIntervalChanged);
clipBox.Changed -= new EventHandler(OnClipWindowChanged);
windowedButton.Changed -= new EventHandler(OnWindowedFullscreenChanged);
fullscreenButton.Changed -= new EventHandler(OnWindowedFullscreenChanged);
}
#endregion
/// <summary>Returns the current device information</summary>
private EnumDeviceInformation GetCurrentDeviceInfo()
{
return Enumeration.GetDeviceInfo(globalSettings.AdapterOrdinal, globalSettings.DeviceType);
}
/// <summary>Returns the current adapter information</summary>
private EnumAdapterInformation GetCurrentAdapterInfo()
{
return Enumeration.GetAdapterInformation(globalSettings.AdapterOrdinal);
}
/// <summary>Returns the current adapter information</summary>
private EnumDeviceSettingsCombo GetCurrentDeviceSettingsCombo()
{
return Enumeration.GetDeviceSettingsCombo(globalSettings.AdapterOrdinal,
globalSettings.DeviceType, globalSettings.AdapterFormat,
globalSettings.presentParams.BackBufferFormat, globalSettings.presentParams.Windowed);
}
// TODO: SetDeviceSettingsFromUI
#region Update UI Methods
/// <summary>Sets whether this is running in windowed or fullscreen mode</summary>
private void SetWindowed(bool windowed)
{
windowedButton.IsChecked = windowed;
fullscreenButton.IsChecked = !windowed;
}
/// <summary>Adds a resolution to the combo box</summary>
private void AddResolution(short width, short height)
{
string itemText = string.Format("{0} by {1}", width, height);
// Store the resolution in a single variable
uint resolutionData = NativeMethods.MakeUInt32(width, height);
// Add this item
if (!resolution.ContainsItem(itemText))
resolution.AddItem(itemText, resolutionData);
}
/// <summary>Adds a refresh rate to the combo box</summary>
private void AddRefreshRate(int rate)
{
string itemText = (rate == 0) ? "Default Rate" : string.Format("{0} Hz", rate);
// Add this item
if (!refreshCombo.ContainsItem(itemText))
refreshCombo.AddItem(itemText, rate);
}
/// <summary>Adds a vertex processing type to the combo box</summary>
private void AddVertexProcessing(CreateFlags flags)
{
string itemText = "Unknown vertex processing type";
switch(flags)
{
case CreateFlags.PureDevice:
itemText = "Pure hardware vertex processing"; break;
case CreateFlags.HardwareVertexProcessing:
itemText = "Hardware vertex processing"; break;
case CreateFlags.SoftwareVertexProcessing:
itemText = "Software vertex processing"; break;
case CreateFlags.MixedVertexProcessing:
itemText = "Mixed vertex processing"; break;
}
// Add this item
if (!vertexCombo.ContainsItem(itemText))
vertexCombo.AddItem(itemText, flags);
}
#endregion
#region Event handlers for the controls
/// <summary>Called when the resolution changes</summary>
private void OnResolutionChanged(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
// Set the resolution
uint data = (uint)cb.GetSelectedData();
int width = NativeMethods.LoWord(data);
int height = NativeMethods.HiWord(data);
globalSettings.presentParams.BackBufferWidth = width;
globalSettings.presentParams.BackBufferHeight = height;
int refreshRate = globalSettings.presentParams.FullScreenRefreshRateInHz;
// Update the refresh rate list
refreshCombo.Clear();
EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo();
Format adapterFormat = globalSettings.AdapterFormat;
foreach(DisplayMode dm in adapterInfo.displayModeList)
{
if (dm.Format == adapterFormat &&
dm.Width == width &&
dm.Height == height)
{
AddRefreshRate(dm.RefreshRate);
}
}
// select and update
refreshCombo.SetSelectedByData(refreshRate);
OnRefreshRateChanged(refreshCombo, e);
}
/// <summary>Called when the adapter changes</summary>
private void OnAdapterChanged(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
// Store the adapter index
globalSettings.AdapterOrdinal = (uint)(int)cb.GetSelectedData();
// Remove all the items from the device type
deviceCombo.Clear();
// Get the adapter information
EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo();
// Add each device type to the combo list
foreach(EnumDeviceInformation edi in adapterInfo.deviceInfoList)
{
if (!deviceCombo.ContainsItem(edi.DeviceType.ToString()))
deviceCombo.AddItem(edi.DeviceType.ToString(), edi.DeviceType);
}
deviceCombo.SetSelectedByData(globalSettings.DeviceType);
// Device type was changed update
OnDeviceChanged(deviceCombo, e);
}
/// <summary>Called when the device type changes</summary>
private void OnDeviceChanged(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
globalSettings.DeviceType = (DeviceType)cb.GetSelectedData();
// Update windowed/full screen radio buttons
bool hasWindowCombo = false;
bool hasFullscreen = false;
EnumDeviceInformation edi = GetCurrentDeviceInfo();
// See if there are any windowed/fullscreen combos
foreach(EnumDeviceSettingsCombo edsc in edi.deviceSettingsList)
{
if (edsc.IsWindowed)
hasWindowCombo = true;
else
hasFullscreen = true;
}
// Set the controls enable/disable property based on whether they are available or not
dialog.SetControlEnable((int)SettingsDialogControlIds.Windowed, hasWindowCombo);
dialog.SetControlEnable((int)SettingsDialogControlIds.Fullscreen, hasFullscreen);
SetWindowed(globalSettings.presentParams.Windowed && hasWindowCombo);
OnWindowedFullscreenChanged(null, e);
}
/// <summary>Called when the adapter format changes</summary>
private void OnAdapterFormatChange(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
Format adapterFormat = (Format)cb.GetSelectedData();
// Resolutions
resolution.Clear();
EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo();
foreach(DisplayMode dm in adapterInfo.displayModeList)
{
if (dm.Format == adapterFormat)
AddResolution((short)dm.Width, (short)dm.Height);
}
uint currentResolution = NativeMethods.MakeUInt32(
(short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight);
resolution.SetSelectedByData(currentResolution);
// Resolution changed
OnResolutionChanged(resolution, e);
// Back buffer formats
backBufferCombo.Clear();
EnumDeviceInformation edi = GetCurrentDeviceInfo();
bool hasWindowedBackBuffer = false;
bool isWindowed = windowedButton.IsChecked;
foreach(EnumDeviceSettingsCombo edsc in edi.deviceSettingsList)
{
if (edsc.IsWindowed == isWindowed &&
edsc.AdapterFormat == globalSettings.AdapterFormat)
{
hasWindowedBackBuffer = true;
if (!backBufferCombo.ContainsItem(edsc.BackBufferFormat.ToString()))
backBufferCombo.AddItem(edsc.BackBufferFormat.ToString(), edsc.BackBufferFormat);
}
}
// Update back buffer
backBufferCombo.SetSelectedByData(globalSettings.presentParams.BackBufferFormat);
OnBackBufferChanged(backBufferCombo, e);
if (!hasWindowedBackBuffer)
{
dialog.SetControlEnable((int)SettingsDialogControlIds.Windowed, false);
if (globalSettings.presentParams.Windowed)
{
SetWindowed(false);
OnWindowedFullscreenChanged(null, e);
}
}
}
/// <summary>Called when the refresh rate changes</summary>
private void OnRefreshRateChanged(object sender, EventArgs e)
{
ComboBox c = sender as ComboBox;
globalSettings.presentParams.FullScreenRefreshRateInHz = (int)c.GetSelectedData();
}
/// <summary>Called when the back buffer format changes</summary>
private void OnBackBufferChanged(object sender, EventArgs e)
{
ComboBox cb = sender as ComboBox;
globalSettings.presentParams.BackBufferFormat = (Format)backBufferCombo.GetSelectedData();
// Store formats
Format adapterFormat = globalSettings.AdapterFormat;
Format backFormat = globalSettings.presentParams.BackBufferFormat;
EnumDeviceInformation edi = GetCurrentDeviceInfo();
// Get possible vertex processing
bool isAllowSoftware = Enumeration.IsSoftwareVertexProcessingPossible;
bool isAllowHardware = Enumeration.IsHardwareVertexProcessingPossible;
bool isAllowPure = Enumeration.IsPureHardwareVertexProcessingPossible;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -