- Main Page
- Packages
- Classes
- Files

- File List
- File Members

# D:/guillaume/guillara/3D/DXGfx/DXCommon/wdxmutSettingsDlg.cs

Go to the documentation of this file.

    00001 //--------------------------------------------------------------------------------------
    00002 // File: DXMUTSettingsDlg.cs
    00003 //
    00004 // Dialog for selection of device settings
    00005 //
    00006 // Copyright (c) Microsoft Corporation. All rights reserved.
    00007 //--------------------------------------------------------------------------------------
    00008 using System;
    00009 using System.IO;
    00010 using System.Collections.Generic;
    00011 using System.Runtime.InteropServices;
    00012 using Microsoft.DirectX;
    00013 using Microsoft.DirectX.Direct3D;
    00014
    00015 namespace Microsoft.Samples.DirectX.UtilityToolkit
    00016 {
    00017     #region Control Ids
    00018     public enum SettingsDialogControlIds
    00019     {
    00020         Static = -1,
    00021         None,
    00022         OK,
    00023         Cancel,
    00024         Adapter,
    00025         DeviceType,
    00026         IsWindowed,
    00027         Fullscreen,
    00028         AdapterFormat,
    00029         AdapterFormatLabel,
    00030         Resolution,
    00031         ResolutionLabel,
    00032         RefreshRate,
    00033         RefreshRateLabel,
    00034         BackBufferFormat,
    00035         DepthStencil,
    00036         MultisampleType,
    00037         MultisampleQuality,
    00038         VertexProcessing,
    00039         PresentInterval,
    00040         DeviceClip,
    00041         RadioButtonGroup = 0x100,
    00042     }
    00043     #endregion
    00044
    00048     public class SettingsDialog
    00049     {
    00050         #region Creation
    00052         public SettingsDialog(Framework sample)
    00053         {
    00054             parent = sample;
    00055             windowWidth = Framework.DefaultSizeWidth; windowHeight = Framework.DefaultSizeHeight;
    00056             CreateControls();
    00057         }
    00058         #endregion
    00059
    00060         #region Class Data
    00061         private Framework parent; // Parent framework for this dialog
    00062         private Dialog dialog; // Dialog that will be rendered
    00063         private uint windowWidth; // Width of window
    00064         private uint windowHeight; // Height of window
    00065         private DeviceSettings globalSettings; // Device settings
    00066         private StateBlock state; // state block for device
    00067         #endregion
    00068
    00069         #region Control variables
    00070         // Combo boxes
    00071         private ComboBox resolution;
    00072         private ComboBox adapterCombo;
    00073         private ComboBox deviceCombo;
    00074         private ComboBox adapterFormatCombo;
    00075         private ComboBox refreshCombo;
    00076         private ComboBox backBufferCombo;
    00077         private ComboBox depthStencilCombo;
    00078         private ComboBox multiSampleTypeCombo;
    00079         private ComboBox multiSampleQualityCombo;
    00080         private ComboBox vertexCombo;
    00081         private ComboBox presentCombo;
    00082         // Check boxes
    00083         private Checkbox clipBox;
    00084         // Radio buttons
    00085         private RadioButton windowedButton;
    00086         private RadioButton fullscreenButton;
    00087         // Static controls that are cared about
    00088         private StaticText adapterFormatStatic;
    00089         private StaticText resolutionStatic;
    00090         private StaticText refreshStatic;
    00091         #endregion
    00092
    00096         private void CreateControls()
    00097         {
    00098             dialog = new Dialog(parent);
    00099             dialog.IsUsingKeyboardInput = true;
    00100             dialog.SetFont(0, "Arial", 15, FontWeight.Normal);
    00101             dialog.SetFont(1, "Arial", 28, FontWeight.Bold);
    00102
    00103             // Right justify static controls
    00104             Element e = dialog.GetDefaultElement(ControlType.StaticText, 0);
    00105             e.stringFormat = DrawStringFormat.VerticalCenter | DrawStringFormat.Right;
    00106
    00107             // Title
    00108             StaticText title = dialog.AddStatic((int)SettingsDialogControlIds.Static, "Direct3D Settings", 10, 5, 400, 50);
    00109             e = title[0];
    00110             e.FontIndex = 1;
    00111             e.stringFormat = DrawStringFormat.Top | DrawStringFormat.Left;
    00112
    00113             // Adapter
    00114             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Display Adapter", 10, 50, 180, 23);
    00115             adapterCombo = dialog.AddComboBox((int)SettingsDialogControlIds.Adapter, 200, 50, 300, 23);
    00116
    00117             // Device Type
    00118             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Render Device", 10, 75, 180, 23);
    00119             deviceCombo = dialog.AddComboBox((int)SettingsDialogControlIds.DeviceType, 200, 75, 300, 23);
    00120
    00121             // Windowed / Fullscreen
    00122             windowedButton = dialog.AddRadioButton((int)SettingsDialogControlIds.IsWindowed, (int)SettingsDialogControlIds.RadioButtonGroup,
    00123                 "Windowed", 240, 105, 300, 16, false);
    00124             clipBox = dialog.AddCheckBox((int)SettingsDialogControlIds.DeviceClip, "Clip to device when window spans across multiple monitors",
    00125                 250, 126, 400, 16, false);
    00126             fullscreenButton = dialog.AddRadioButton((int)SettingsDialogControlIds.Fullscreen, (int)SettingsDialogControlIds.RadioButtonGroup, "Full Screen",
    00127                 240, 147, 300, 16, false);
    00128
    00129             // Adapter Format
    00130             adapterFormatStatic = dialog.AddStatic((int)SettingsDialogControlIds.AdapterFormatLabel, "Adapter Format",
    00131                 10, 180, 180, 23);
    00132             adapterFormatCombo = dialog.AddComboBox((int)SettingsDialogControlIds.AdapterFormat, 200, 180, 300, 23);
    00133
    00134             // Resolution
    00135             resolutionStatic = dialog.AddStatic((int)SettingsDialogControlIds.ResolutionLabel, "Resolution", 10, 205, 180, 23);
    00136             resolution = dialog.AddComboBox((int)SettingsDialogControlIds.Resolution, 200, 205, 300, 23);
    00137             resolution.SetDropHeight(106);
    00138
    00139             // Refresh Rate
    00140             refreshStatic = dialog.AddStatic((int)SettingsDialogControlIds.RefreshRateLabel, "Refresh Rate", 10, 230, 180, 23);
    00141             refreshCombo = dialog.AddComboBox((int)SettingsDialogControlIds.RefreshRate, 200, 230, 300, 23);
    00142
    00143             // BackBuffer Format
    00144             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Back Buffer Format", 10, 265, 180, 23);
    00145             backBufferCombo = dialog.AddComboBox((int)SettingsDialogControlIds.BackBufferFormat, 200, 265, 300, 23);
    00146
    00147             // Depth Stencil
    00148             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Depth/Stencil Format", 10, 290, 180, 23);
    00149             depthStencilCombo = dialog.AddComboBox((int)SettingsDialogControlIds.DepthStencil, 200, 290, 300, 23);
    00150
    00151             // Multisample Type
    00152             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Multisample Type", 10, 315, 180, 23);
    00153             multiSampleTypeCombo = dialog.AddComboBox((int)SettingsDialogControlIds.MultisampleType, 200, 315, 300, 23);
    00154
    00155             // Multisample Quality
    00156             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Multisample Quality", 10, 340, 180, 23);
    00157             multiSampleQualityCombo = dialog.AddComboBox((int)SettingsDialogControlIds.MultisampleQuality, 200, 340, 300, 23);
    00158
    00159             // Vertex Processing
    00160             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Vertex Processing", 10, 365, 180, 23);
    00161             vertexCombo = dialog.AddComboBox((int)SettingsDialogControlIds.VertexProcessing, 200, 365, 300, 23);
    00162
    00163             // Present Interval
    00164             dialog.AddStatic((int)SettingsDialogControlIds.Static, "Present Interval", 10, 390, 180, 23);
    00165             presentCombo = dialog.AddComboBox((int)SettingsDialogControlIds.PresentInterval, 200, 390, 300, 23);
    00166
    00167             // Add the ok/cancel buttons
    00168             Button okButton = dialog.AddButton((int)SettingsDialogControlIds.OK, "OK", 230, 435, 73, 31);
    00169             Button cancelButton = dialog.AddButton((int)SettingsDialogControlIds.Cancel, "Cancel", 315, 435, 73, 31, 0, true);
    00170             okButton.Click += new EventHandler(OnOkClicked);
    00171             cancelButton.Click += new EventHandler(OnCancelClicked);
    00172         }
    00173
    00175         public void Refresh()
    00176         {
    00177             // Get some information
    00178             globalSettings = parent.DeviceSettings.Clone();
    00179             System.Drawing.Rectangle client = parent.WindowClientRectangle;
    00180             windowWidth = (uint)client.Width;
    00181             windowHeight = (uint)client.Height;
    00182
    00183             // Fill the UI with the current settings
    00184             if (!deviceCombo.ContainsItem(globalSettings.DeviceType.ToString()))
    00185                 deviceCombo.AddItem(globalSettings.DeviceType.ToString(), globalSettings.DeviceType.ToString());
    00186
    00187             SetWindowed(globalSettings.presentParams.IsWindowed);
    00188             clipBox.IsChecked = ((globalSettings.presentParams.PresentFlag & PresentFlag.DeviceClip) != 0);
    00189
    00190             if (!adapterFormatCombo.ContainsItem(globalSettings.AdapterFormat.ToString()))
    00191                 adapterFormatCombo.AddItem(globalSettings.AdapterFormat.ToString(), globalSettings.AdapterFormat);
    00192
    00193             AddResolution((short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight);
    00194             AddRefreshRate(globalSettings.presentParams.FullScreenRefreshRateInHz);
    00195
    00196             if (!backBufferCombo.ContainsItem(globalSettings.presentParams.BackBufferFormat.ToString()))
    00197                 backBufferCombo.AddItem(globalSettings.presentParams.BackBufferFormat.ToString(), globalSettings.presentParams.BackBufferFormat);
    00198
    00199             if (!depthStencilCombo.ContainsItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString()))
    00200                 depthStencilCombo.AddItem(globalSettings.presentParams.AutoDepthStencilFormat.ToString(), globalSettings.presentParams.AutoDepthStencilFormat);
    00201
    00202             if (!multiSampleTypeCombo.ContainsItem(globalSettings.presentParams.MultiSampleType.ToString()))
    00203                 multiSampleTypeCombo.AddItem(globalSettings.presentParams.MultiSampleType.ToString(), globalSettings.presentParams.MultiSampleType);
    00204
    00205             if (!multiSampleQualityCombo.ContainsItem(globalSettings.presentParams.MultiSampleQuality.ToString()))
    00206                 multiSampleQualityCombo.AddItem(globalSettings.presentParams.MultiSampleQuality.ToString(), globalSettings.presentParams.MultiSampleQuality);
    00207
    00208             if (!presentCombo.ContainsItem(globalSettings.presentParams.PresentationInterval.ToString()))
    00209                 presentCombo.AddItem(globalSettings.presentParams.PresentationInterval.ToString(), globalSettings.presentParams.PresentationInterval);
    00210
    00211             BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags);
    00212             if (flags.PureDevice)
    00213                 AddVertexProcessing(CreateFlags.PureDevice);
    00214             else if (flags.HardwareVertexProcessing)
    00215                 AddVertexProcessing(CreateFlags.HardwareVertexProcessing);
    00216             else if (flags.SoftwareVertexProcessing)
    00217                 AddVertexProcessing(CreateFlags.SoftwareVertexProcessing);
    00218             else if (flags.MixedVertexProcessing)
    00219                 AddVertexProcessing(CreateFlags.MixedVertexProcessing);
    00220
    00221             // Get the adapters list from Enumeration object
    00222             List<EnumAdapterInformation> adapterInfoList = Enumeration.AdapterInformationList;
    00223
    00224             if (adapterInfoList.Count == 0)
    00225                 throw new NoCompatibleDevicesException();
    00226
    00227             adapterCombo.Clear();
    00228
    00229             // Add all of the adapters
    00230             for (int iAdapter = 0; iAdapter < adapterInfoList.Count; iAdapter++)
    00231             {
    00232                 EnumAdapterInformation adapterInfo = adapterInfoList[iAdapter] as EnumAdapterInformation;
    00233                 if (!adapterCombo.ContainsItem(adapterInfo.UniqueDescription))
    00234                     adapterCombo.AddItem(adapterInfo.UniqueDescription, iAdapter);
    00235             }
    00236             adapterCombo.SetSelectedByData(globalSettings.AdapterOrdinal);
    00237
    00238             // The adapter changed, call the handler
    00239             OnAdapterChanged(adapterCombo, EventArgs.Empty);
    00240
    00241             Dialog.SetRefreshTime((float)FrameworkTimer.GetTime());
    00242         }
    00243
    00245         public void OnRender(float elapsedTime)
    00246         {
    00247             state.Capture();
    00248             parent.Device.RenderState.FillMode = FillMode.Solid;
    00249             dialog.OnRender(elapsedTime);
    00250             state.Apply();
    00251         }
    00252
    00254         public void HandleMessages(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam)
    00255         {
    00256             dialog.MessageProc(hWnd, msg, wParam, lParam);
    00257         }
    00258         #region Device event callbacks
    00262         public void OnCreateDevice(Device d)
    00263         {
    00264             // Hook all the events we care about
    00265             resolution.Changed += new EventHandler(OnResolutionChanged);
    00266             adapterCombo.Changed += new EventHandler(OnAdapterChanged);
    00267             deviceCombo.Changed += new EventHandler(OnDeviceChanged);
    00268             adapterFormatCombo.Changed += new EventHandler(OnAdapterFormatChange);
    00269             refreshCombo.Changed += new EventHandler(OnRefreshRateChanged);
    00270             backBufferCombo.Changed += new EventHandler(OnBackBufferChanged);
    00271             depthStencilCombo.Changed += new EventHandler(OnDepthStencilChanged);
    00272             multiSampleTypeCombo.Changed += new EventHandler(OnMultisampleTypeChanged);
    00273             multiSampleQualityCombo.Changed += new EventHandler(OnMultisampleQualityChanged);
    00274             vertexCombo.Changed += new EventHandler(OnVertexProcessingChanged);
    00275             presentCombo.Changed += new EventHandler(OnPresentIntervalChanged);
    00276             clipBox.Changed += new EventHandler(OnClipWindowChanged);
    00277             windowedButton.Changed += new EventHandler(OnWindowedFullscreenChanged);
    00278             fullscreenButton.Changed += new EventHandler(OnWindowedFullscreenChanged);
    00279         }
    00280
    00284         public void OnResetDevice()
    00285         {
    00286             SurfaceDescription desc = parent.BackBufferSurfaceDescription;
    00287
    00288             // Set up the dialog
    00289             dialog.SetLocation(0, 0);
    00290             dialog.SetSize(desc.Width, desc.Height);
    00291             dialog.SetBackgroundColors(new ColorValue((float)98 / 255, (float)138 / 255, (float)206 / 255),
    00292                 new ColorValue((float)54 / 255, (float)105 / 255, (float)192 / 255),
    00293                 new ColorValue((float)54 / 255, (float)105 / 255, (float)192 / 255),
    00294                 new ColorValue((float)10 / 255, (float)73 / 255, (float)179 / 255));
    00295
    00296             Device device = parent.Device;
    00297             device.BeginStateBlock();
    00298             device.RenderState.FillMode = FillMode.Solid;
    00299             state = device.EndStateBlock();
    00300
    00301         }
    00302
    00306         public void OnLostDevice()
    00307         {
    00308             if (state != null)
    00309                 state.Dispose();
    00310
    00311             state = null;
    00312         }
    00313
    00315         public void OnDestroyDevice(object sender, EventArgs e)
    00316         {
    00317             // Clear the focus
    00318             Dialog.ClearFocus();
    00319             // Unhook all the events we care about
    00320             resolution.Changed -= new EventHandler(OnResolutionChanged);
    00321             adapterCombo.Changed -= new EventHandler(OnAdapterChanged);
    00322             deviceCombo.Changed -= new EventHandler(OnDeviceChanged);
    00323             adapterFormatCombo.Changed -= new EventHandler(OnAdapterFormatChange);
    00324             refreshCombo.Changed -= new EventHandler(OnRefreshRateChanged);
    00325             backBufferCombo.Changed -= new EventHandler(OnBackBufferChanged);
    00326             depthStencilCombo.Changed -= new EventHandler(OnDepthStencilChanged);
    00327             multiSampleTypeCombo.Changed -= new EventHandler(OnMultisampleTypeChanged);
    00328             multiSampleQualityCombo.Changed -= new EventHandler(OnMultisampleQualityChanged);
    00329             vertexCombo.Changed -= new EventHandler(OnVertexProcessingChanged);
    00330             presentCombo.Changed -= new EventHandler(OnPresentIntervalChanged);
    00331             clipBox.Changed -= new EventHandler(OnClipWindowChanged);
    00332             windowedButton.Changed -= new EventHandler(OnWindowedFullscreenChanged);
    00333             fullscreenButton.Changed -= new EventHandler(OnWindowedFullscreenChanged);
    00334         }
    00335
    00336         #endregion
    00337
    00339         private EnumDeviceInformation GetCurrentDeviceInfo()
    00340         {
    00341             return Enumeration.GetDeviceInfo(globalSettings.AdapterOrdinal, globalSettings.DeviceType);
    00342         }
    00344         private EnumAdapterInformation GetCurrentAdapterInfo()
    00345         {
    00346             return Enumeration.GetAdapterInformation(globalSettings.AdapterOrdinal);
    00347         }
    00349         private EnumDeviceSettingsCombo GetCurrentDeviceSettingsCombo()
    00350         {
    00351             return Enumeration.GetDeviceSettingsCombo(globalSettings.AdapterOrdinal,
    00352                 globalSettings.DeviceType, globalSettings.AdapterFormat,
    00353                 globalSettings.presentParams.BackBufferFormat, globalSettings.presentParams.IsWindowed);
    00354         }
    00355
    00356         // TODO: SetDeviceSettingsFromUI
    00357         #region Update UI Methods
    00359         private void SetWindowed(bool windowed)
    00360         {
    00361             windowedButton.IsChecked = windowed;
    00362             fullscreenButton.IsChecked = !windowed;
    00363         }
    00365         private void AddResolution(short width, short height)
    00366         {
    00367             string itemText = string.Format("{0} by {1}", width, height);
    00368             // Store the resolution in a single variable
    00369             uint resolutionData = NativeMethods.MakeUInt32(width, height);
    00370
    00371             // Add this item
    00372             if (!resolution.ContainsItem(itemText))
    00373                 resolution.AddItem(itemText, resolutionData);
    00374         }
    00376         private void AddRefreshRate(int rate)
    00377         {
    00378             string itemText = (rate == 0) ? "Default Rate" : string.Format("{0} Hz", rate);
    00379             // Add this item
    00380             if (!refreshCombo.ContainsItem(itemText))
    00381                 refreshCombo.AddItem(itemText, rate);
    00382         }
    00384         private void AddVertexProcessing(CreateFlags flags)
    00385         {
    00386             string itemText = "Unknown vertex processing type";
    00387             switch (flags)
    00388             {
    00389                 case CreateFlags.PureDevice:
    00390                     itemText = "Pure hardware vertex processing"; break;
    00391                 case CreateFlags.HardwareVertexProcessing:
    00392                     itemText = "Hardware vertex processing"; break;
    00393                 case CreateFlags.SoftwareVertexProcessing:
    00394                     itemText = "Software vertex processing"; break;
    00395                 case CreateFlags.MixedVertexProcessing:
    00396                     itemText = "Mixed vertex processing"; break;
    00397             }
    00398             // Add this item
    00399             if (!vertexCombo.ContainsItem(itemText))
    00400                 vertexCombo.AddItem(itemText, flags);
    00401         }
    00402         #endregion
    00403
    00404         #region Event handlers for the controls
    00406         private void OnResolutionChanged(object sender, EventArgs e)
    00407         {
    00408             ComboBox cb = sender as ComboBox;
    00409
    00410             // Set the resolution
    00411             uint data = (uint)cb.GetSelectedData();
    00412             int width = NativeMethods.LoWord(data);
    00413             int height = NativeMethods.HiWord(data);
    00414             globalSettings.presentParams.BackBufferWidth = width;
    00415             globalSettings.presentParams.BackBufferHeight = height;
    00416
    00417             int refreshRate = globalSettings.presentParams.FullScreenRefreshRateInHz;
    00418
    00419             // Update the refresh rate list
    00420             refreshCombo.Clear();
    00421
    00422             EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo();
    00423             Format adapterFormat = globalSettings.AdapterFormat;
    00424             foreach (DisplayMode dm in adapterInfo.displayModeList)
    00425             {
    00426                 if (dm.Format == adapterFormat &&
    00427                     dm.Width == width &&
    00428                     dm.Height == height)
    00429                 {
    00430                     AddRefreshRate(dm.RefreshRate);
    00431                 }
    00432             }
    00433
    00434             // select and update
    00435             refreshCombo.SetSelectedByData(refreshRate);
    00436             OnRefreshRateChanged(refreshCombo, e);
    00437         }
    00438
    00440         private void OnAdapterChanged(object sender, EventArgs e)
    00441         {
    00442             ComboBox cb = sender as ComboBox;
    00443             // Store the adapter index
    00444             globalSettings.AdapterOrdinal = (uint)(int)cb.GetSelectedData();
    00445
    00446             // Remove all the items from the device type
    00447             deviceCombo.Clear();
    00448
    00449             // Get the adapter information
    00450             EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo();
    00451
    00452             // Add each device type to the combo list
    00453             foreach (EnumDeviceInformation edi in adapterInfo.deviceInfoList)
    00454             {
    00455                 if (!deviceCombo.ContainsItem(edi.DeviceType.ToString()))
    00456                     deviceCombo.AddItem(edi.DeviceType.ToString(), edi.DeviceType);
    00457             }
    00458             deviceCombo.SetSelectedByData(globalSettings.DeviceType);
    00459
    00460             // Device type was changed update
    00461             OnDeviceChanged(deviceCombo, e);
    00462         }
    00464         private void OnDeviceChanged(object sender, EventArgs e)
    00465         {
    00466             ComboBox cb = sender as ComboBox;
    00467             globalSettings.DeviceType = (DeviceType)cb.GetSelectedData();
    00468
    00469             // Update windowed/full screen radio buttons
    00470             bool hasWindowCombo = false;
    00471             bool hasFullscreen = false;
    00472
    00473             EnumDeviceInformation edi = GetCurrentDeviceInfo();
    00474
    00475             // See if there are any windowed/fullscreen combos
    00476             foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList)
    00477             {
    00478                 if (edsc.IsWindowed)
    00479                     hasWindowCombo = true;
    00480                 else
    00481                     hasFullscreen = true;
    00482             }
    00483
    00484             // Set the controls enable/disable property based on whether they are available or not
    00485             dialog.SetControlEnable((int)SettingsDialogControlIds.IsWindowed, hasWindowCombo);
    00486             dialog.SetControlEnable((int)SettingsDialogControlIds.Fullscreen, hasFullscreen);
    00487
    00488             SetWindowed(globalSettings.presentParams.IsWindowed && hasWindowCombo);
    00489
    00490             OnWindowedFullscreenChanged(null, e);
    00491         }
    00492
    00494         private void OnAdapterFormatChange(object sender, EventArgs e)
    00495         {
    00496             ComboBox cb = sender as ComboBox;
    00497             Format adapterFormat = (Format)cb.GetSelectedData();
    00498
    00499             // Resolutions
    00500             resolution.Clear();
    00501
    00502             EnumAdapterInformation adapterInfo = GetCurrentAdapterInfo();
    00503             foreach (DisplayMode dm in adapterInfo.displayModeList)
    00504             {
    00505                 if (dm.Format == adapterFormat)
    00506                     AddResolution((short)dm.Width, (short)dm.Height);
    00507             }
    00508
    00509             uint currentResolution = NativeMethods.MakeUInt32(
    00510                 (short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight);
    00511
    00512             resolution.SetSelectedByData(currentResolution);
    00513             // Resolution changed
    00514             OnResolutionChanged(resolution, e);
    00515
    00516             // Back buffer formats
    00517             backBufferCombo.Clear();
    00518
    00519             EnumDeviceInformation edi = GetCurrentDeviceInfo();
    00520             bool hasWindowedBackBuffer = false;
    00521             bool isWindowed = windowedButton.IsChecked;
    00522
    00523             foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList)
    00524             {
    00525                 if (edsc.IsWindowed == isWindowed &&
    00526                     edsc.AdapterFormat == globalSettings.AdapterFormat)
    00527                 {
    00528                     hasWindowedBackBuffer = true;
    00529                     if (!backBufferCombo.ContainsItem(edsc.BackBufferFormat.ToString()))
    00530                         backBufferCombo.AddItem(edsc.BackBufferFormat.ToString(), edsc.BackBufferFormat);
    00531                 }
    00532             }
    00533             // Update back buffer
    00534             backBufferCombo.SetSelectedByData(globalSettings.presentParams.BackBufferFormat);
    00535             OnBackBufferChanged(backBufferCombo, e);
    00536
    00537             if (!hasWindowedBackBuffer)
    00538             {
    00539                 dialog.SetControlEnable((int)SettingsDialogControlIds.IsWindowed, false);
    00540                 if (globalSettings.presentParams.IsWindowed)
    00541                 {
    00542                     SetWindowed(false);
    00543                     OnWindowedFullscreenChanged(null, e);
    00544                 }
    00545             }
    00546         }
    00547
    00549         private void OnRefreshRateChanged(object sender, EventArgs e)
    00550         {
    00551             ComboBox c = sender as ComboBox;
    00552             globalSettings.presentParams.FullScreenRefreshRateInHz = (int)c.GetSelectedData();
    00553         }
    00554
    00556         private void OnBackBufferChanged(object sender, EventArgs e)
    00557         {
    00558             ComboBox cb = sender as ComboBox;
    00559             globalSettings.presentParams.BackBufferFormat = (Format)backBufferCombo.GetSelectedData();
    00560
    00561             // Store formats
    00562             Format adapterFormat = globalSettings.AdapterFormat;
    00563             Format backFormat = globalSettings.presentParams.BackBufferFormat;
    00564
    00565             EnumDeviceInformation edi = GetCurrentDeviceInfo();
    00566
    00567             // Get possible vertex processing
    00568             bool isAllowSoftware = Enumeration.IsSoftwareVertexProcessingPossible;
    00569             bool isAllowHardware = Enumeration.IsHardwareVertexProcessingPossible;
    00570             bool isAllowPure = Enumeration.IsPureHardwareVertexProcessingPossible;
    00571             bool isAllowMixed = Enumeration.IsMixedVertexProcessingPossible;
    00572
    00573             foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList)
    00574             {
    00575                 if (edsc.IsWindowed == globalSettings.presentParams.IsWindowed &&
    00576                     edsc.AdapterFormat == adapterFormat &&
    00577                     edsc.BackBufferFormat == backFormat)
    00578                 {
    00579                     // Clear the depth stencil buffer
    00580                     depthStencilCombo.Clear();
    00581                     depthStencilCombo.IsEnabled = (globalSettings.presentParams.EnableAutoDepthStencil);
    00582                     if (globalSettings.presentParams.EnableAutoDepthStencil)
    00583                     {
    00584                         foreach (Format f in edsc.depthStencilFormatList)
    00585                         {
    00586                             if (!depthStencilCombo.ContainsItem(f.ToString()))
    00587                                 depthStencilCombo.AddItem(f.ToString(), f);
    00588                         }
    00589
    00590                         depthStencilCombo.SetSelectedByData(globalSettings.presentParams.AutoDepthStencilFormat);
    00591                     }
    00592                     else
    00593                     {
    00594                         if (!depthStencilCombo.ContainsItem("(not used)"))
    00595                             depthStencilCombo.AddItem("(not used)", null);
    00596                     }
    00597                     OnDepthStencilChanged(depthStencilCombo, e);
    00598
    00599                     // Now remove all the vertex processing information
    00600                     vertexCombo.Clear();
    00601                     if (isAllowPure)
    00602                         AddVertexProcessing(CreateFlags.PureDevice);
    00603                     if (isAllowHardware)
    00604                         AddVertexProcessing(CreateFlags.HardwareVertexProcessing);
    00605                     if (isAllowSoftware)
    00606                         AddVertexProcessing(CreateFlags.SoftwareVertexProcessing);
    00607                     if (isAllowMixed)
    00608                         AddVertexProcessing(CreateFlags.MixedVertexProcessing);
    00609
    00610                     // Select the right one
    00611                     BehaviorFlags flags = new BehaviorFlags(globalSettings.BehaviorFlags);
    00612                     if (flags.PureDevice)
    00613                         vertexCombo.SetSelectedByData(CreateFlags.PureDevice);
    00614                     else if (flags.HardwareVertexProcessing)
    00615                         vertexCombo.SetSelectedByData(CreateFlags.HardwareVertexProcessing);
    00616                     else if (flags.SoftwareVertexProcessing)
    00617                         vertexCombo.SetSelectedByData(CreateFlags.SoftwareVertexProcessing);
    00618                     else if (flags.MixedVertexProcessing)
    00619                         vertexCombo.SetSelectedByData(CreateFlags.MixedVertexProcessing);
    00620
    00621                     OnVertexProcessingChanged(vertexCombo, e);
    00622
    00623                     // Now present intervals
    00624                     presentCombo.Clear();
    00625                     foreach (PresentInterval pf in edsc.presentIntervalList)
    00626                     {
    00627                         if (!presentCombo.ContainsItem(pf.ToString()))
    00628                             presentCombo.AddItem(pf.ToString(), pf);
    00629                     }
    00630
    00631                     presentCombo.SetSelectedByData(globalSettings.presentParams.PresentationInterval);
    00632                     OnPresentIntervalChanged(presentCombo, e);
    00633                 }
    00634             }
    00635
    00636         }
    00637
    00639         private void OnDepthStencilChanged(object sender, EventArgs e)
    00640         {
    00641             ComboBox cb = sender as ComboBox;
    00642             DepthFormat stencilFormat = (DepthFormat)cb.GetSelectedData();
    00643
    00644             if (globalSettings.presentParams.EnableAutoDepthStencil)
    00645                 globalSettings.presentParams.AutoDepthStencilFormat = stencilFormat;
    00646
    00647             EnumDeviceSettingsCombo combo = GetCurrentDeviceSettingsCombo();
    00648
    00649             // Remove all of the multisample items and add the new ones
    00650             multiSampleTypeCombo.Clear();
    00651             foreach (MultiSampleType mst in combo.multiSampleTypeList)
    00652             {
    00653                 bool conflictFound = false;
    00654                 foreach (EnumDepthStencilMultisampleConflict c in combo.depthStencilConflictList)
    00655                 {
    00656                     if (c.DepthStencilFormat == stencilFormat &&
    00657                         c.MultisampleType == mst)
    00658                     {
    00659                         conflictFound = true;
    00660                         break;
    00661                     }
    00662                 }
    00663
    00664                 if (!conflictFound)
    00665                 {
    00666                     if (!multiSampleTypeCombo.ContainsItem(mst.ToString()))
    00667                         multiSampleTypeCombo.AddItem(mst.ToString(), mst);
    00668                 }
    00669             }
    00670             // Select the correct multisampling type
    00671             multiSampleTypeCombo.SetSelectedByData(globalSettings.presentParams.MultiSampleType);
    00672             OnMultisampleTypeChanged(multiSampleTypeCombo, e);
    00673         }
    00674
    00676         private void OnMultisampleTypeChanged(object sender, EventArgs e)
    00677         {
    00678             ComboBox cb = sender as ComboBox;
    00679             MultiSampleType mst = (MultiSampleType)cb.GetSelectedData();
    00680             globalSettings.presentParams.MultiSampleType = mst;
    00681
    00682             EnumDeviceSettingsCombo combo = GetCurrentDeviceSettingsCombo();
    00683
    00684             int maxQuality = 0;
    00685             for (int i = 0; i < combo.multiSampleTypeList.Count; i++)
    00686             {
    00687                 MultiSampleType msType = (MultiSampleType)combo.multiSampleTypeList[i];
    00688                 if (msType == mst)
    00689                 {
    00690                     maxQuality = (int)combo.multiSampleQualityList[i];
    00691                 }
    00692             }
    00693
    00694             // We have the max quality now, add to our list
    00695             multiSampleQualityCombo.Clear();
    00696             for (int i = 0; i < maxQuality; i++)
    00697             {
    00698                 if (!multiSampleQualityCombo.ContainsItem(i.ToString()))
    00699                     multiSampleQualityCombo.AddItem(i.ToString(), i);
    00700             }
    00701             multiSampleQualityCombo.SetSelectedByData(globalSettings.presentParams.MultiSampleQuality);
    00702             OnMultisampleQualityChanged(multiSampleQualityCombo, e);
    00703         }
    00705         private void OnMultisampleQualityChanged(object sender, EventArgs e)
    00706         {
    00707             ComboBox cb = sender as ComboBox;
    00708             globalSettings.presentParams.MultiSampleQuality = (int)cb.GetSelectedData();
    00709         }
    00711         private void OnVertexProcessingChanged(object sender, EventArgs e)
    00712         {
    00713             ComboBox cb = sender as ComboBox;
    00714
    00715             CreateFlags behavior = globalSettings.BehaviorFlags;
    00716
    00717             // Clear flags
    00718             behavior &= ~CreateFlags.HardwareVertexProcessing;
    00719             behavior &= ~CreateFlags.SoftwareVertexProcessing;
    00720             behavior &= ~CreateFlags.PureDevice;
    00721             behavior &= ~CreateFlags.MixedVertexProcessing;
    00722
    00723             // Determine new flags
    00724             CreateFlags newFlags = (CreateFlags)vertexCombo.GetSelectedData();
    00725             if ((newFlags & CreateFlags.PureDevice) != 0)
    00726                 newFlags |= CreateFlags.HardwareVertexProcessing;
    00727
    00728             // Make changes
    00729             globalSettings.BehaviorFlags = behavior | newFlags;
    00730         }
    00732         private void OnPresentIntervalChanged(object sender, EventArgs e)
    00733         {
    00734             ComboBox cb = sender as ComboBox;
    00735             globalSettings.presentParams.PresentationInterval = (PresentInterval)cb.GetSelectedData();
    00736         }
    00738         private void OnClipWindowChanged(object sender, EventArgs e)
    00739         {
    00740             Checkbox cb = sender as Checkbox;
    00741             if (cb.IsChecked)
    00742                 globalSettings.presentParams.PresentFlag |= PresentFlag.DeviceClip;
    00743             else
    00744                 globalSettings.presentParams.PresentFlag &= ~PresentFlag.DeviceClip;
    00745         }
    00747         private void OnWindowedFullscreenChanged(object sender, EventArgs e)
    00748         {
    00749             bool isWindowed = windowedButton.IsChecked;
    00750             globalSettings.presentParams.IsWindowed = isWindowed;
    00751
    00752             // Set the control enabled or disabled properties
    00753             dialog.SetControlEnable((int)SettingsDialogControlIds.AdapterFormatLabel, !isWindowed);
    00754             dialog.SetControlEnable((int)SettingsDialogControlIds.ResolutionLabel, !isWindowed);
    00755             dialog.SetControlEnable((int)SettingsDialogControlIds.RefreshRateLabel, !isWindowed);
    00756
    00757             dialog.SetControlEnable((int)SettingsDialogControlIds.AdapterFormat, !isWindowed);
    00758             dialog.SetControlEnable((int)SettingsDialogControlIds.Resolution, !isWindowed);
    00759             dialog.SetControlEnable((int)SettingsDialogControlIds.RefreshRate, !isWindowed);
    00760             dialog.SetControlEnable((int)SettingsDialogControlIds.DeviceClip, isWindowed);
    00761
    00762             bool deviceClip = ((globalSettings.presentParams.PresentFlag & PresentFlag.DeviceClip) != 0);
    00763
    00764             // If windowed, get the appropriate adapter format from Direct3D
    00765             if (globalSettings.presentParams.IsWindowed)
    00766             {
    00767                 DisplayMode mode = Manager.Adapters[(int)globalSettings.AdapterOrdinal].CurrentDisplayMode;
    00768                 globalSettings.AdapterFormat = mode.Format;
    00769                 globalSettings.presentParams.BackBufferWidth = mode.Width;
    00770                 globalSettings.presentParams.BackBufferHeight = mode.Height;
    00771                 globalSettings.presentParams.FullScreenRefreshRateInHz = mode.RefreshRate;
    00772             }
    00773
    00774             // Update the clip check box
    00775             clipBox.IsChecked = deviceClip;
    00776
    00777             // Update the adapter format list
    00778             adapterFormatCombo.Clear();
    00779
    00780             EnumDeviceInformation edi = GetCurrentDeviceInfo();
    00781
    00782             if (isWindowed)
    00783             {
    00784                 if (!adapterFormatCombo.ContainsItem(globalSettings.AdapterFormat.ToString()))
    00785                     adapterFormatCombo.AddItem(globalSettings.AdapterFormat.ToString(), globalSettings.AdapterFormat);
    00786             }
    00787             else
    00788             {
    00789                 // Add all the supported formats
    00790                 foreach (EnumDeviceSettingsCombo edsc in edi.deviceSettingsList)
    00791                 {
    00792                     if (!adapterFormatCombo.ContainsItem(edsc.AdapterFormat.ToString()))
    00793                         adapterFormatCombo.AddItem(edsc.AdapterFormat.ToString(), edsc.AdapterFormat);
    00794                 }
    00795             }
    00796             adapterFormatCombo.SetSelectedByData(globalSettings.AdapterFormat);
    00797             // Adapter format changed, update there
    00798             OnAdapterFormatChange(adapterFormatCombo, EventArgs.Empty);
    00799
    00800             // Update resolution
    00801             if (isWindowed)
    00802             {
    00803                 resolution.Clear();
    00804                 AddResolution((short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight);
    00805             }
    00806             resolution.SetSelectedByData(NativeMethods.MakeUInt32(
    00807                 (short)globalSettings.presentParams.BackBufferWidth, (short)globalSettings.presentParams.BackBufferHeight));
    00808
    00809             // Resolution changed
    00810             OnResolutionChanged(resolution, EventArgs.Empty);
    00811
    00812             // Update refresh
    00813             if (isWindowed)
    00814             {
    00815                 refreshCombo.Clear();
    00816                 AddRefreshRate(globalSettings.presentParams.FullScreenRefreshRateInHz);
    00817             }
    00818
    00819             // Select the correct refresh rate
    00820             refreshCombo.SetSelectedByData(globalSettings.presentParams.FullScreenRefreshRateInHz);
    00821
    00822             // refresh rate changed
    00823             OnRefreshRateChanged(refreshCombo, EventArgs.Empty);
    00824         }
    00826         private void OnCancelClicked(object sender, EventArgs e)
    00827         {
    00828             // Nothing left to do, quit showing the screen
    00829             parent.ShowSettingsDialog(false);
    00830         }
    00832         private void OnOkClicked(object sender, EventArgs e)
    00833         {
    00834             // The device needs to be updated
    00835             if (globalSettings.presentParams.IsWindowed)
    00836             {
    00837                 globalSettings.presentParams.FullScreenRefreshRateInHz = 0;
    00838                 globalSettings.presentParams.BackBufferWidth = (int)windowWidth;
    00839                 globalSettings.presentParams.BackBufferHeight = (int)windowHeight;
    00840             }
    00841
    00842             if (globalSettings.presentParams.MultiSampleType != MultiSampleType.None)
    00843             {
    00844                 globalSettings.presentParams.PresentFlag &= ~PresentFlag.LockableBackBuffer;
    00845             }
    00846
    00847             // Create a device
    00848             parent.CreateDeviceFromSettings(globalSettings);
    00849
    00850             // Stop showing the dialog now
    00851             parent.ShowSettingsDialog(false);
    00852         }
    00853         #endregion
    00854     }
    00855 }