⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dxmutdata.cs

📁 运用directX完成的坦克游戏雏形
💻 CS
📖 第 1 页 / 共 2 页
字号:
//--------------------------------------------------------------------------------------
// File: DXMUTData.cs
//
// DirectX SDK Managed Direct3D 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's Default Window
	/// <summary>
	/// The main window that will be used for the sample framework
	/// </summary>
	public class GraphicsWindow : System.Windows.Forms.Form
	{
		private Framework frame = null;
		public GraphicsWindow(Framework f)
		{
			frame = f;
			this.MinimumSize = Framework.MinWindowSize;
		}

		private void InitializeComponent()
		{
			// 
			// GraphicsWindow
			// 
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(292, 266);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
			this.MaximizeBox = false;
			this.Name = "GraphicsWindow";

		}

		/// <summary>
		/// Will call into the sample framework's window proc
		/// </summary>
		protected override void WndProc(ref Message m)
		{
			frame.WindowsProcedure(ref m);
			base.WndProc (ref m);
		}


	}
	#endregion

    #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(Caps caps, Format adapterFormat, Format backBufferFormat, bool isWindowed);
        void ModifyDeviceSettings(DeviceSettings settings, Caps 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 = (PresentParameters)this.presentParams.Clone();
            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 Windowed;
        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 Caps 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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -