?? wdxmutdata.cs
字號:
//--------------------------------------------------------------------------------------
// File: WDXMUTData.cs
//
// DirectX SDK Managed Direct3D for Whidbey sample framework data class
//
// Copyright (c) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
using System;
using System.Windows.Forms;
using System.Collections;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
namespace Microsoft.Samples.DirectX.UtilityToolkit
{
#region Framework Interfaces and Eventargs classes
/// <summary>Interface that the framework will use to call into samples</summary>
public interface IFrameworkCallback
{
void OnFrameMove(Device device, double totalTime, float elapsedTime);
void OnFrameRender(Device device, double totalTime, float elapsedTime);
}
/// <summary>Interface that the framework will use to determine if a device is acceptable</summary>
public interface IDeviceCreation
{
bool IsDeviceAcceptable(Capabilities caps, Format adapterFormat, Format backBufferFormat, bool isWindowed);
void ModifyDeviceSettings(DeviceSettings settings, Capabilities caps);
}
/// <summary>Event arguments for device creation/reset</summary>
public class DeviceEventArgs : EventArgs
{
// Class data
public Device Device;
public SurfaceDescription BackBufferDescription;
public DeviceEventArgs(Device d, SurfaceDescription desc)
{
Device = d;
BackBufferDescription = desc;
}
}
/// <summary>Event Handler delegate for device creation/reset</summary>
public delegate void DeviceEventHandler(object sender, DeviceEventArgs e);
#endregion
#region Device Settings
/// <summary>
/// Holds the settings for creating a device
/// </summary>
public class DeviceSettings : ICloneable
{
public uint AdapterOrdinal;
public DeviceType DeviceType;
public Format AdapterFormat;
public CreateFlags BehaviorFlags;
public PresentParameters presentParams;
#region ICloneable Members
/// <summary>Clone this object</summary>
public DeviceSettings Clone()
{
DeviceSettings clonedObject = new DeviceSettings();
clonedObject.presentParams = this.presentParams.Copy();
clonedObject.AdapterFormat = this.AdapterFormat;
clonedObject.AdapterOrdinal = this.AdapterOrdinal;
clonedObject.BehaviorFlags = this.BehaviorFlags;
clonedObject.DeviceType = this.DeviceType;
return clonedObject;
}
/// <summary>Clone this object</summary>
object ICloneable.Clone() { throw new NotSupportedException("Use the strongly typed overload instead."); }
#endregion
}
#endregion
#region User Timers
/// <summary>Stores timer callback information</summary>
public struct TimerData
{
public TimerCallback callback;
public float TimeoutInSecs;
public float Countdown;
public bool IsEnabled;
}
#endregion
#region Callback methods
public delegate IntPtr WndProcCallback(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool NoFurtherProcessing);
public delegate void TimerCallback(uint eventId);
#endregion
#region Matching Options
/// <summary>
/// Used when finding valid device settings
/// </summary>
public enum MatchType
{
IgnoreInput, // Use the closest valid value to a default
PreserveInput, // Use input without change, but may cause no valid device to be found
ClosestToInput // Use the closest valid value to the input
}
/// <summary>
/// Options on how to match items
/// </summary>
public struct MatchOptions
{
public MatchType AdapterOrdinal;
public MatchType DeviceType;
public MatchType IsWindowed;
public MatchType AdapterFormat;
public MatchType VertexProcessing;
public MatchType Resolution;
public MatchType BackBufferFormat;
public MatchType BackBufferCount;
public MatchType MultiSample;
public MatchType SwapEffect;
public MatchType DepthFormat;
public MatchType StencilFormat;
public MatchType PresentFlags;
public MatchType RefreshRate;
public MatchType PresentInterval;
};
#endregion
#region Framework's data
/// <summary>
/// Holds data for the Framework class, and all of the properties
/// </summary>
class FrameworkData
{
#region Instance Data
private Device device; // the D3D rendering device
private DeviceSettings currentDeviceSettings; // current device settings
private SurfaceDescription backBufferSurfaceDesc; // back buffer surface description
private Capabilities caps; // D3D caps for current device
private System.Windows.Forms.Control windowFocus; // the main app focus window
private System.Windows.Forms.Control windowDeviceFullScreen; // the main app device window in fullscreen mode
private System.Windows.Forms.Control windowDeviceWindowed; // the main app device window in windowed mode
private IntPtr adapterMonitor; // the monitor of the adapter
private double currentTime; // current time in seconds
private float elapsedTime; // time elapsed since last frame
private System.Windows.Forms.FormStartPosition defaultStartingLocation; // default starting location of the window
private System.Drawing.Rectangle clientRect; // client rect of window
private System.Drawing.Rectangle fullScreenClientRect; // client rect of window when fullscreen
private System.Drawing.Rectangle windowBoundsRect; // window rect of window
private System.Drawing.Point windowLocation; // Location of the window
private System.Windows.Forms.MainMenu windowMenu; // menu of app
private double lastStatsUpdateTime; // last time the stats were updated
private uint lastStatsUpdateFrames; // frames count since last time the stats were updated
private float frameRate; // frames per second
private int currentFrameNumber; // the current frame number
private bool isHandlingDefaultHotkeys; // if true, the sample framework will handle some default hotkeys
private bool isShowingMsgBoxOnError; // if true, then msgboxes are displayed upon errors
private bool isClipCursorWhenFullScreen; // if true, then the sample framework will keep the cursor from going outside the window when full screen
private bool isShowingCursorWhenFullScreen; // if true, then the sample framework will show a cursor when full screen
private bool isConstantFrameTime; // if true, then elapsed frame time will always be 0.05f seconds which is good for debugging or automated capture
private float timePerFrame; // the constant time per frame in seconds, only valid if isConstantFrameTime==true
private bool isInWireframeMode; // if true, then RenderState.FillMode==FillMode.WireFrame else RenderState.FillMode==FillMode.Solid
private bool canAutoChangeAdapter; // if true, then the adapter will automatically change if the window is different monitor
private bool isWindowCreatedWithDefaultPositions; // if true, then default was used and the window should be moved to the right adapter
private int applicationExitCode; // the exit code to be returned to the command line
private bool isInited; // if true, then Init() has succeeded
private bool wasWindowCreated; // if true, then CreateWindow() or SetWindow() has succeeded
private bool wasDeviceCreated; // if true, then CreateDevice*() or SetDevice() has succeeded
private bool isInitCalled; // if true, then Init() was called
private bool isWindowCreateCalled; // if true, then CreateWindow() or SetWindow() was called
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -