00001
00002
00003
00004
00005
00006
00007
00008 using System;
00009 using System.Windows.Forms;
00010 using System.Collections;
00011 using Microsoft.DirectX;
00012 using Microsoft.DirectX.Direct3D;
00013
00014 namespace Microsoft.Samples.DirectX.UtilityToolkit
00015 {
00016
00017 #region Framework Interfaces and Eventargs classes
00019 public interface IFrameworkCallback
00020 {
00021 void OnFrameMove(Device device, double totalTime, float elapsedTime);
00022 void OnFrameRender(Device device, double totalTime, float elapsedTime);
00023 }
00024
00026 public interface IDeviceCreation
00027 {
00028 bool IsDeviceAcceptable(Capabilities caps, Format adapterFormat, Format backBufferFormat, bool isWindowed);
00029 void ModifyDeviceSettings(DeviceSettings settings, Capabilities caps);
00030 }
00031
00033 public class DeviceEventArgs : EventArgs
00034 {
00035
00036 public Device Device;
00037 public SurfaceDescription BackBufferDescription;
00038
00039 public DeviceEventArgs(Device d, SurfaceDescription desc)
00040 {
00041 Device = d;
00042 BackBufferDescription = desc;
00043 }
00044 }
00046 public delegate void DeviceEventHandler(object sender, DeviceEventArgs e);
00047 #endregion
00048
00049 #region Device Settings
00053 public class DeviceSettings : ICloneable
00054 {
00055 public uint AdapterOrdinal;
00056 public DeviceType DeviceType;
00057 public Format AdapterFormat;
00058 public CreateFlags BehaviorFlags;
00059 public PresentParameters presentParams;
00060
00061 #region ICloneable Members
00063 public DeviceSettings Clone()
00064 {
00065 DeviceSettings clonedObject = new DeviceSettings();
00066 clonedObject.presentParams = this.presentParams.Copy();
00067 clonedObject.AdapterFormat = this.AdapterFormat;
00068 clonedObject.AdapterOrdinal = this.AdapterOrdinal;
00069 clonedObject.BehaviorFlags = this.BehaviorFlags;
00070 clonedObject.DeviceType = this.DeviceType;
00071
00072 return clonedObject;
00073 }
00075 object ICloneable.Clone() { throw new NotSupportedException("Use the strongly typed overload instead."); }
00076 #endregion
00077 }
00078 #endregion
00079
00080 #region User Timers
00082 public struct TimerData
00083 {
00084 public TimerCallback callback;
00085 public float TimeoutInSecs;
00086 public float Countdown;
00087 public bool IsEnabled;
00088 }
00089 #endregion
00090
00091 #region Callback methods
00092 public delegate IntPtr WndProcCallback(IntPtr hWnd, NativeMethods.WindowMessage msg, IntPtr wParam, IntPtr lParam, ref bool NoFurtherProcessing);
00093 public delegate void TimerCallback(uint eventId);
00094 #endregion
00095
00096 #region Matching Options
00100 public enum MatchType
00101 {
00102 IgnoreInput,
00103 PreserveInput,
00104 ClosestToInput
00105 }
00106
00110 public struct MatchOptions
00111 {
00112 public MatchType AdapterOrdinal;
00113 public MatchType DeviceType;
00114 public MatchType IsWindowed;
00115 public MatchType AdapterFormat;
00116 public MatchType VertexProcessing;
00117 public MatchType Resolution;
00118 public MatchType BackBufferFormat;
00119 public MatchType BackBufferCount;
00120 public MatchType MultiSample;
00121 public MatchType SwapEffect;
00122 public MatchType DepthFormat;
00123 public MatchType StencilFormat;
00124 public MatchType PresentFlags;
00125 public MatchType RefreshRate;
00126 public MatchType PresentInterval;
00127 };
00128 #endregion
00129
00130 #region Framework's data
00134 class FrameworkData
00135 {
00136 #region Instance Data
00137 private Device device;
00138
00139 private DeviceSettings currentDeviceSettings;
00140 private SurfaceDescription backBufferSurfaceDesc;
00141 private Capabilities caps;
00142
00143 private System.Windows.Forms.Control windowFocus;
00144 private System.Windows.Forms.Control windowDeviceFullScreen;
00145 private System.Windows.Forms.Control windowDeviceWindowed;
00146 private IntPtr adapterMonitor;
00147 private double currentTime;
00148 private float elapsedTime;
00149
00150 private System.Windows.Forms.FormStartPosition defaultStartingLocation;
00151 private System.Drawing.Rectangle clientRect;
00152 private System.Drawing.Rectangle fullScreenClientRect;
00153 private System.Drawing.Rectangle windowBoundsRect;
00154 private System.Drawing.Point windowLocation;
00155
00156 private System.Windows.Forms.MainMenu windowMenu;
00157 private double lastStatsUpdateTime;
00158 private uint lastStatsUpdateFrames;
00159 private float frameRate;
00160 private int currentFrameNumber;
00161
00162 private bool isHandlingDefaultHotkeys;
00163 private bool isShowingMsgBoxOnError;
00164 private bool isClipCursorWhenFullScreen;
00165 private bool isShowingCursorWhenFullScreen;
00166 private bool isConstantFrameTime;
00167 private float timePerFrame;
00168 private bool isInWireframeMode;
00169 private bool canAutoChangeAdapter;
00170 private bool isWindowCreatedWithDefaultPositions;
00171 private int applicationExitCode;
00172 private bool isHidingStats;
00173
00174 private bool isInited;
00175 private bool wasWindowCreated;
00176 private bool wasDeviceCreated;
00177
00178 private bool isInitCalled;
00179 private bool isWindowCreateCalled;
00180 private bool isDeviceCreateCalled;
00181
00182 private bool isDeviceObjectsCreated;
00183 private bool isDeviceObjectsReset;
00184 private bool isInsideDeviceCallback;
00185 private bool isInsideMainloop;
00186 private bool isActive;
00187 private bool isTimePaused;
00188 private bool isRenderingPaused;
00189 private int pauseRenderingCount;
00190 private int pauseTimeCount;
00191 private bool isDeviceLost;
00192 private bool isMinimized;
00193 private bool isMaximized;
00194 private bool isSizeChangesIgnored;
00195 private bool isNotifyOnMouseMove;
00196
00197 private int overrideAdapterOrdinal;
00198 private bool overrideWindowed;
00199 private bool overrideFullScreen;
00200 private int overrideStartX;
00201 private int overrideStartY;
00202 private int overrideWidth;
00203 private int overrideHeight;
00204 private bool overrideForceHAL;
00205 private bool overrideForceREF;
00206 private bool overrideForcePureHWVP;
00207 private bool overrideForceHWVP;
00208 private bool overrideForceSWVP;
00209 private bool overrideConstantFrameTime;
00210 private float overrideConstantTimePerFrame;
00211 private int overrideQuitAfterFrame;
00212
00213 private IDeviceCreation deviceCallback;
00214 private IFrameworkCallback frameworkCallback;
00215 private WndProcCallback wndFunc;
00216
00217 private SettingsDialog settings;
00218 private bool isShowingD3DSettingsDlg;
00219
00220 private ArrayList timerList = new ArrayList();
00221 private string staticFrameStats;
00222 private string frameStats;
00223 private string deviceStats;
00224 private string windowTitle;
00225
00226 #endregion
00227
00228 #region Properties
00229 public Device Device { get { return device; } set { device = value; } }
00230 public DeviceSettings CurrentDeviceSettings { get { return currentDeviceSettings; } set { currentDeviceSettings = value; } }
00231 public SurfaceDescription BackBufferSurfaceDesc { get { return backBufferSurfaceDesc; } set { backBufferSurfaceDesc = value; } }
00232 public Capabilities Capabilities { get { return caps; } set { caps = value; } }
00233
00234 public System.Windows.Forms.Control WindowFocus { get { return windowFocus; } set { windowFocus = value; } }
00235 public System.Windows.Forms.Control WindowDeviceFullScreen { get { return windowDeviceFullScreen; } set { windowDeviceFullScreen = value; } }
00236 public System.Windows.Forms.Control WindowDeviceWindowed { get { return windowDeviceWindowed; } set { windowDeviceWindowed = value; } }
00237 public IntPtr AdapterMonitor { get { return adapterMonitor; } set { adapterMonitor = value; } }
00238 public double CurrentTime { get { return currentTime; } set { currentTime = value; } }
00239 public float ElapsedTime { get { return elapsedTime; } set { elapsedTime = value; } }
00240
00241 public System.Windows.Forms.FormStartPosition DefaultStartingLocation { get { return defaultStartingLocation; } set { defaultStartingLocation = value; } }
00242 public System.Drawing.Rectangle ClientRectangle { get { return clientRect; } set { clientRect = value; } }
00243 public System.Drawing.Rectangle FullScreenClientRectangle { get { return fullScreenClientRect; } set { fullScreenClientRect = value; } }
00244 public System.Drawing.Rectangle WindowBoundsRectangle { get { return windowBoundsRect; } set { windowBoundsRect = value; } }
00245 public System.Drawing.Point ClientLocation { get { return windowLocation; } set { windowLocation = value; } }
00246 public System.Windows.Forms.MainMenu Menu { get { return windowMenu; } set { windowMenu = value; } }
00247 public double LastStatsUpdateTime { get { return lastStatsUpdateTime; } set { lastStatsUpdateTime = value; } }
00248 public uint LastStatsUpdateFrames { get { return lastStatsUpdateFrames; } set { lastStatsUpdateFrames = value; } }
00249 public float CurrentFrameRate { get { return frameRate; } set { frameRate = value; } }
00250 public int CurrentFrameNumber { get { return currentFrameNumber; } set { currentFrameNumber = value; } }
00251
00252 public bool IsHandlingDefaultHotkeys { get { return isHandlingDefaultHotkeys; } set { isHandlingDefaultHotkeys = value; } }
00253 public bool IsShowingMsgBoxOnError { get { return isShowingMsgBoxOnError; } set { isShowingMsgBoxOnError = value; } }
00254 public bool AreStatsHidden { get { return isHidingStats; } set { isHidingStats = value; } }
00255 public bool IsCursorClippedWhenFullScreen { get { return isClipCursorWhenFullScreen; } set { isClipCursorWhenFullScreen = value; } }
00256 public bool IsShowingCursorWhenFullScreen { get { return isShowingCursorWhenFullScreen; } set { isShowingCursorWhenFullScreen = value; } }
00257 public bool IsUsingConstantFrameTime { get { return isConstantFrameTime; } set { isConstantFrameTime = value; } }
00258 public float TimePerFrame { get { return timePerFrame; } set { timePerFrame = value; } }
00259 public bool IsInWireframeMode { get { return isInWireframeMode; } set { isInWireframeMode = value; } }
00260 public bool CanAutoChangeAdapter { get { return canAutoChangeAdapter; } set { canAutoChangeAdapter = value; } }
00261 public bool IsWindowCreatedWithDefaultPositions { get { return isWindowCreatedWithDefaultPositions; } set { isWindowCreatedWithDefaultPositions = value; } }
00262 public int ApplicationExitCode { get { return applicationExitCode; } set { applicationExitCode = value; } }
00263
00264 public bool IsInited { get { return isInited; } set { isInited = value; } }
00265 public bool WasWindowCreated { get { return wasWindowCreated; } set { wasWindowCreated = value; } }
00266 public bool WasDeviceCreated { get { return wasDeviceCreated; } set { wasDeviceCreated = value; } }
00267
00268 public bool WasInitCalled { get { return isInitCalled; } set { isInitCalled = value; } }
00269 public bool WasWindowCreateCalled { get { return isWindowCreateCalled; } set { isWindowCreateCalled = value; } }
00270 public bool WasDeviceCreateCalled { get { return isDeviceCreateCalled; } set { isDeviceCreateCalled = value; } }
00271
00272 public bool AreDeviceObjectsCreated { get { return isDeviceObjectsCreated; } set { isDeviceObjectsCreated = value; } }
00273 public bool AreDeviceObjectsReset { get { return isDeviceObjectsReset; } set { isDeviceObjectsReset = value; } }
00274 public bool IsInsideDeviceCallback { get { return isInsideDeviceCallback; } set { isInsideDeviceCallback = value; } }
00275 public bool IsInsideMainloop { get { return isInsideMainloop; } set { isInsideMainloop = value; } }
00276 public bool IsActive { get { return isActive; } set { isActive = value; } }
00277 public bool IsTimePaused { get { return isTimePaused; } set { isTimePaused = value; } }
00278 public bool IsRenderingPaused { get { return isRenderingPaused; } set { isRenderingPaused = value; } }
00279 public int PauseRenderingCount { get { return pauseRenderingCount; } set { pauseRenderingCount = value; } }
00280 public int PauseTimeCount { get { return pauseTimeCount; } set { pauseTimeCount = value; } }
00281 public bool IsDeviceLost { get { return isDeviceLost; } set { isDeviceLost = value; } }
00282 public bool IsMinimized { get { return isMinimized; } set { isMinimized = value; } }
00283 public bool IsMaximized { get { return isMaximized; } set { isMaximized = value; } }
00284 public bool AreSizeChangesIgnored { get { return isSizeChangesIgnored; } set { isSizeChangesIgnored = value; } }
00285 public bool IsNotifiedOnMouseMove { get { return isNotifyOnMouseMove; } set { isNotifyOnMouseMove = value; } }
00286
00287 public int OverrideAdapterOrdinal { get { return overrideAdapterOrdinal; } set { overrideAdapterOrdinal = value; } }
00288 public bool IsOverridingWindowed { get { return overrideWindowed; } set { overrideWindowed = value; } }
00289 public bool IsOverridingFullScreen { get { return overrideFullScreen; } set { overrideFullScreen = value; } }
00290 public int OverrideStartX { get { return overrideStartX; } set { overrideStartX = value; } }
00291 public int OverrideStartY { get { return overrideStartY; } set { overrideStartY = value; } }
00292 public int OverrideWidth { get { return overrideWidth; } set { overrideWidth = value; } }
00293 public int OverrideHeight { get { return overrideHeight; } set { overrideHeight = value; } }
00294 public bool IsOverridingForceHardware { get { return overrideForceHAL; } set { overrideForceHAL = value; } }
00295 public bool IsOverridingForceReference { get { return overrideForceREF; } set { overrideForceREF = value; } }
00296 public bool IsOverridingForcePureHardwareVertexProcessing { get { return overrideForcePureHWVP; } set { overrideForcePureHWVP = value; } }
00297 public bool IsOverridingForceHardwareVertexProcessing { get { return overrideForceHWVP; } set { overrideForceHWVP = value; } }
00298 public bool IsOverridingForceSoftwareVertexProcessing { get { return overrideForceSWVP; } set { overrideForceSWVP = value; } }
00299 public bool IsOverridingConstantFrameTime { get { return overrideConstantFrameTime; } set { overrideConstantFrameTime = value; } }
00300 public float OverrideConstantTimePerFrame { get { return overrideConstantTimePerFrame; } set { overrideConstantTimePerFrame = value; } }
00301 public int OverrideQuitAfterFrame { get { return overrideQuitAfterFrame; } set { overrideQuitAfterFrame = value; } }
00302
00303 public IDeviceCreation DeviceCreationInterface { get { return deviceCallback; } set { deviceCallback = value; } }
00304 public IFrameworkCallback CallbackInterface { get { return frameworkCallback; } set { frameworkCallback = value; } }
00305 public WndProcCallback WndProcFunction { get { return wndFunc; } set { wndFunc = value; } }
00306
00307 public SettingsDialog Settings { get { return settings; } set { settings = value; } }
00308 public bool IsD3DSettingsDialogShowing { get { return isShowingD3DSettingsDlg; } set { isShowingD3DSettingsDlg = value; } }
00309
00310 public ArrayList Timers { get { return timerList; } set { timerList = value; } }
00311 public string StaticFrameStats { get { return staticFrameStats; } set { staticFrameStats = value; } }
00312 public string FrameStats { get { return frameStats; } set { frameStats = value; } }
00313 public string DeviceStats { get { return deviceStats; } set { deviceStats = value; } }
00314 public string WindowTitle { get { return windowTitle; } set { windowTitle = value; } }
00315 #endregion
00316
00320 public FrameworkData()
00321 {
00322
00323 overrideStartX = -1;
00324 overrideStartY = -1;
00325 overrideAdapterOrdinal = -1;
00326 canAutoChangeAdapter = true;
00327 isShowingMsgBoxOnError = true;
00328 isActive = true;
00329 defaultStartingLocation = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation;
00330 }
00331 }
00332 #endregion
00333
00334 #region Framework's Default Window
00338 public class GraphicsWindow : System.Windows.Forms.Form
00339 {
00340 private Framework parent = null;
00341 public GraphicsWindow(Framework frame)
00342 {
00343 parent = frame;
00344 this.MinimumSize = Framework.MinWindowSize;
00345 }
00346
00350 protected override void WndProc(ref Message m)
00351 {
00352 parent.WindowsProcedure(ref m);
00353 base.WndProc(ref m);
00354 }
00355 }
00356 #endregion
00357 }