?? dxmut.cs
字號:
// Override the window's initial size and position if there were cmd line args
if (State.OverrideStartX != -1)
{
State.DefaultStartingLocation = System.Windows.Forms.FormStartPosition.Manual;
x = State.OverrideStartX;
}
if (State.OverrideStartY != -1)
{
State.DefaultStartingLocation = System.Windows.Forms.FormStartPosition.Manual;
y = State.OverrideStartY;
}
// Create the new window
GraphicsWindow renderWindow = new GraphicsWindow(this);
// Hook the events
HookEvents(renderWindow);
// Are we in the default start location?
if (State.DefaultStartingLocation == System.Windows.Forms.FormStartPosition.WindowsDefaultLocation)
{
State.IsWindowCreatedWithDefaultPositions = true;
renderWindow.StartPosition = System.Windows.Forms.FormStartPosition.WindowsDefaultLocation;
}
else
{
State.IsWindowCreatedWithDefaultPositions = false;
renderWindow.Location = new System.Drawing.Point(x, y);
}
// Calculate the window size
System.Drawing.Size windowSize = DefaultStartingSize;
if (State.OverrideWidth != 0)
windowSize.Width = State.OverrideWidth;
if (State.OverrideHeight != 0)
windowSize.Height = State.OverrideHeight;
// Set the size
renderWindow.ClientSize = windowSize;
// Store the window title
State.WindowTitle = windowTitle;
renderWindow.Text = windowTitle;
// Set current cursor
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.Default;
// Get the window's rectangles
renderWindow.Visible = false;
renderWindow.CreateControl();
State.ClientRectangle = renderWindow.ClientRectangle;
State.WindowBoundsRectangle = renderWindow.Bounds;
// Update state
State.WasWindowCreated = true;
State.WindowFocus = renderWindow;
State.WindowDeviceFullScreen = renderWindow;
State.WindowDeviceWindowed = renderWindow;
}
}
/// <summary>
/// Calls into CreateWindow with default paramters
/// </summary>
public void CreateWindow(string windowTitle)
{
CreateWindow(windowTitle, LoadFirstIconFromResource(), null, -1, -1);
}
/// <summary>
/// Sets a previously created window for the framework to use. If Init has
/// not already been called, it will call it with default parameters. Instead
/// of calling this you can call CreateWindow to create a new window.
/// </summary>
public void SetWindow(System.Windows.Forms.Control windowFocus, System.Windows.Forms.Control windowDeviceFullscreen,
System.Windows.Forms.Control windowDeviceWindowed, bool handleMessages)
{
if (State.IsInsideDeviceCallback)
throw new InvalidOperationException("You cannot create a window from inside a callback.");
State.WasWindowCreateCalled = true;
// To avoid confusion, we do not allow any window handles to be null here. The
// caller must pass in valid window handles for all three parameters. The same
// window handles may be used for more than one parameter.
if ((windowDeviceFullscreen == null) || (windowDeviceWindowed == null)
|| (windowFocus == null))
{
throw new InvalidOperationException("You must pass in valid window handles.");
}
if (handleMessages)
{
// Use the static windows procedure defined here
HookEvents(windowFocus);
}
// Are we inited?
if (!State.IsInited)
{
// If Init was already called and failed, fail again
if (State.WasInitCalled)
{
throw new InvalidOperationException("Initialize was already called and failed.");
}
// Call initialize with default params
Initialize(true, true, true);
}
// Get the window's rectangles
State.ClientRectangle = windowDeviceWindowed.ClientRectangle;
State.WindowBoundsRectangle = windowDeviceWindowed.Bounds;
// Update state
State.WasWindowCreated = true;
State.WindowFocus = windowFocus;
State.WindowDeviceFullScreen = windowDeviceFullscreen;
State.WindowDeviceWindowed = windowDeviceWindowed;
}
/// <summary>
/// Sets a previously created window for the framework to use. If Init has
/// not already been called, it will call it with default parameters. Instead
/// of calling this you can call CreateWindow to create a new window.
/// </summary>
public void SetWinformWindow(System.Windows.Forms.Control windowFocus, System.Windows.Forms.Control windowDeviceFullscreen,
System.Windows.Forms.Control windowDeviceWindowed)
{
if (State.IsInsideDeviceCallback)
throw new InvalidOperationException("You cannot create a window from inside a callback.");
State.WasWindowCreateCalled = true;
// To avoid confusion, we do not allow any controls to be null here. The
// caller must pass in valid windows for all three parameters. The same
// window may be used for more than one parameter.
if ((windowDeviceFullscreen == null) || (windowDeviceWindowed == null)
|| (windowFocus == null))
{
throw new InvalidOperationException("You must pass in valid window handles.");
}
// Are we inited?
if (!State.IsInited)
{
// If Init was already called and failed, fail again
if (State.WasInitCalled)
{
throw new InvalidOperationException("Initialize was already called and failed.");
}
// Call initialize with default params
Initialize(true, true, true);
}
// Update state
State.WasWindowCreated = true;
State.WindowFocus = windowFocus;
State.WindowDeviceFullScreen = windowDeviceFullscreen;
State.WindowDeviceWindowed = windowDeviceWindowed;
}
/// <summary>
/// Creates a Direct3D device. If CreateWindow or SetWindow has not already
/// been called, it will call CreateWindow with default parameters.
/// Instead of calling this, you can call SetDevice or CreateDeviceFromSettings
/// </summary>
public void CreateDevice(uint adapterOridinal, bool windowed, int suggestedWidth,
int suggestedHeight, IDeviceCreation callback)
{
if (State.IsInsideDeviceCallback)
throw new InvalidOperationException("You cannot create a window from inside a callback.");
// Store callbacks in global state
SetDeviceCreationInterface(callback);
// Update device create being called
State.WasDeviceCreateCalled = true;
// Was the window created? If not, create it now
if (!State.WasWindowCreated)
{
// If CreateWindow or SetWindow was already called and failed, then fail again.
if (State.WasWindowCreateCalled)
{
throw new InvalidOperationException("CreateWindow was already called and failed.");
}
// Create a default window
CreateWindow("Direct3D Window", null, null, -1, -1);
}
// Force an enumeration with the updated Device Acceptable callback
Enumeration.Enumerate(State.DeviceCreationInterface);
// Set up the match options
MatchOptions match = new MatchOptions();
match.AdapterOrdinal = MatchType.PreserveInput;
match.DeviceType = MatchType.IgnoreInput;
match.Windowed = MatchType.PreserveInput;
match.AdapterFormat = MatchType.IgnoreInput;
match.VertexProcessing = MatchType.IgnoreInput;
match.Resolution = MatchType.ClosestToInput;
match.BackBufferFormat = MatchType.IgnoreInput;
match.BackBufferCount = MatchType.IgnoreInput;
match.MultiSample = MatchType.IgnoreInput;
match.SwapEffect = MatchType.IgnoreInput;
match.DepthFormat = MatchType.IgnoreInput;
match.StencilFormat = MatchType.IgnoreInput;
match.PresentFlags = MatchType.IgnoreInput;
match.RefreshRate = MatchType.IgnoreInput;
match.PresentInterval = MatchType.IgnoreInput;
// Get the device settings
DeviceSettings settings = new DeviceSettings();
settings.presentParams = new PresentParameters();
settings.AdapterOrdinal = adapterOridinal;
settings.presentParams.Windowed = windowed;
settings.presentParams.BackBufferWidth = suggestedWidth;
settings.presentParams.BackBufferHeight = suggestedHeight;
// Override with settings for command line
if (State.OverrideWidth != 0)
settings.presentParams.BackBufferWidth = State.OverrideWidth;
if (State.OverrideHeight != 0)
settings.presentParams.BackBufferHeight = State.OverrideHeight;
if (State.OverrideAdapterOrdinal != -1)
settings.AdapterOrdinal = (uint)State.OverrideAdapterOrdinal;
if (State.IsOverridingFullScreen)
{
settings.presentParams.Windowed = false;
if ((State.OverrideWidth == 0) && (State.OverrideHeight == 0))
match.Resolution = MatchType.IgnoreInput;
}
if (State.IsOverridingWindowed)
settings.presentParams.Windowed = true;
if (State.IsOverridingForceHardware)
{
settings.DeviceType = DeviceType.Hardware;
match.DeviceType = MatchType.PreserveInput;
}
if (State.IsOverridingForceReference)
{
settings.DeviceType = DeviceType.Reference;
match.DeviceType = MatchType.PreserveInput;
}
if (State.IsOverridingForcePureHardwareVertexProcessing)
{
settings.BehaviorFlags = CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice;
match.VertexProcessing = MatchType.PreserveInput;
}
if (State.IsOverridingForceHardwareVertexProcessing)
{
settings.BehaviorFlags = CreateFlags.HardwareVertexProcessing;
match.VertexProcessing = MatchType.PreserveInput;
}
if (State.IsOverridingForceSoftwareVertexProcessing)
{
settings.BehaviorFlags = CreateFlags.SoftwareVertexProcessing;
match.VertexProcessing = MatchType.PreserveInput;
}
try
{
settings = FindValidDeviceSettings(settings, match);
}
catch(Exception e)
{
DisplayErrorMessage(e);
throw;
}
// If the modify device callback isn't null, call it to
// let the app change the settings
if (State.DeviceCreationInterface != null)
{
Caps c = Manager.GetDeviceCaps((int)settings.AdapterOrdinal, settings.DeviceType);
State.DeviceCreationInterface.ModifyDeviceSettings(settings, c);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -