public override void Create( string name, int width, int height, bool fullScreen, NamedParameterList miscParams )
{
SWF.Control parentHWnd = null;
SWF.Control externalHWnd = null;
_fsaaType = D3D.MultisampleType.None;
_fsaaQuality = 0;
fsaa = 0;
vSync = false;
vSyncInterval = 1;
var title = name;
var colorDepth = 32;
var left = int.MaxValue; // Defaults to screen center
var top = int.MaxValue; // Defaults to screen center
var depthBuffer = true;
var border = "";
var outerSize = false;
_useNVPerfHUD = false;
var enableDoubleClick = false;
var monitorIndex = -1;
if ( miscParams != null )
{
object opt;
;
// left (x)
if (miscParams.TryGetValue("left", out opt))
left = Int32.Parse( opt.ToString() );
// top (y)
if (miscParams.TryGetValue("top", out opt))
top = Int32.Parse( opt.ToString() );
// Window title
if (miscParams.TryGetValue("title", out opt))
title = (string)opt;
// parentWindowHandle -> parentHWnd
if (miscParams.TryGetValue("parentWindowHandle", out opt))
{
// This is Axiom specific
var handle = opt;
var ptr = IntPtr.Zero;
if (handle.GetType() == typeof(IntPtr))
{
ptr = (IntPtr)handle;
}
else if (handle.GetType() == typeof(Int32))
{
ptr = new IntPtr( (int)handle );
}
else
throw new AxiomException( "unhandled parentWindowHandle type" );
parentHWnd = SWF.Control.FromHandle( ptr );
}
// externalWindowHandle -> externalHWnd
if (miscParams.TryGetValue("externalWindowHandle", out opt))
{
// This is Axiom specific
var handle = opt;
var ptr = IntPtr.Zero;
if (handle.GetType() == typeof(IntPtr))
{
ptr = (IntPtr)handle;
}
else if (handle.GetType() == typeof(Int32))
{
ptr = new IntPtr((int)handle);
}
else
throw new AxiomException("unhandled externalWindowHandle type");
externalHWnd = SWF.Control.FromHandle( ptr );
}
// vsync [parseBool]
if (miscParams.TryGetValue("vsync", out opt))
vSync = bool.Parse( opt.ToString() );
// hidden [parseBool]
if (miscParams.TryGetValue("hidden", out opt))
_hidden = bool.Parse( opt.ToString() );
// vsyncInterval [parseUnsignedInt]
if (miscParams.TryGetValue("vsyncInterval", out opt))
vSyncInterval = Int32.Parse( opt.ToString() );
// displayFrequency
if (miscParams.TryGetValue("displayFrequency", out opt))
_displayFrequency = Int32.Parse( opt.ToString() );
// colourDepth
if (miscParams.TryGetValue("colorDepth", out opt))
colorDepth = Int32.Parse( opt.ToString() );
// depthBuffer [parseBool]
if (miscParams.TryGetValue("depthBuffer", out opt))
depthBuffer = bool.Parse( opt.ToString() );
// FSAA type
if (miscParams.TryGetValue("FSAA", out opt))
_fsaaType = (MultisampleType)opt;
// FSAA quality
if (miscParams.TryGetValue("FSAAQuality", out opt))
fsaaHint = opt.ToString();
// window border style
if (miscParams.TryGetValue("border", out opt))
border = ( (string)opt ).ToLower();
// set outer dimensions?
if (miscParams.TryGetValue("outerDimensions", out opt))
outerSize = bool.Parse( opt.ToString() );
// NV perf HUD?
if (miscParams.TryGetValue("useNVPerfHUD", out opt))
_useNVPerfHUD = bool.Parse( opt.ToString() );
// sRGB?
if (miscParams.TryGetValue("gamma", out opt))
hwGamma = bool.Parse(opt.ToString());
// monitor index
if (miscParams.TryGetValue("monitorIndex", out opt))
monitorIndex = Int32.Parse(opt.ToString());
if (miscParams.TryGetValue("show", out opt))
_hidden = bool.Parse(opt.ToString());
// enable double click messages
if (miscParams.TryGetValue("enableDoubleClick", out opt))
enableDoubleClick = bool.Parse(opt.ToString());
}
isFullScreen = fullScreen;
// Destroy current window if any
if ( hWnd != null )
{
Dispose();
}
System.Drawing.Rectangle rc;
if ( externalHWnd == null )
{
WindowsExtendedStyle dwStyleEx = 0;
var hMonitor = IntPtr.Zero;
// If we specified which adapter we want to use - find it's monitor.
if ( monitorIndex != -1 )
{
var direct3D9 = D3DRenderSystem.Direct3D9;
for ( var i = 0; i < direct3D9.AdapterCount; ++i )
{
if ( i != monitorIndex )
continue;
hMonitor = direct3D9.GetAdapterMonitor( i );
break;
}
}
// If we didn't specified the adapter index, or if it didn't find it
if ( hMonitor == IntPtr.Zero )
{
// Fill in anchor point.
var windowAnchorPoint = new Point( left, top );
// Get the nearest monitor to this window.
hMonitor = DisplayMonitor.FromPoint( windowAnchorPoint, MonitorSearchFlags.DefaultToNearest ).Handle;
}
var monitorInfo = new DisplayMonitor( hMonitor );
// Update window style flags.
fullscreenWinStyle = WindowStyles.WS_CLIPCHILDREN | WindowStyles.WS_POPUP;
windowedWinStyle = WindowStyles.WS_CLIPCHILDREN;
if ( !_hidden )
{
fullscreenWinStyle |= WindowStyles.WS_VISIBLE;
windowedWinStyle |= WindowStyles.WS_VISIBLE;
}
if ( parentHWnd != null )
{
windowedWinStyle |= WindowStyles.WS_CHILD;
}
else
{
if ( border == "none" )
windowedWinStyle |= WindowStyles.WS_POPUP;
else if ( border == "fixed" )
windowedWinStyle |= WindowStyles.WS_OVERLAPPED | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION |
WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX;
else
windowedWinStyle |= WindowStyles.WS_OVERLAPPEDWINDOW;
}
var winWidth = width;
var winHeight = height;
// No specified top left -> Center the window in the middle of the monitor
if ( left == int.MaxValue || top == int.MaxValue )
{
var screenw = monitorInfo.WorkingArea.Right - monitorInfo.WorkingArea.Left;
var screenh = monitorInfo.WorkingArea.Bottom - monitorInfo.WorkingArea.Top;
// clamp window dimensions to screen size
var outerw = ( winWidth < screenw ) ? winWidth : screenw;
var outerh = ( winHeight < screenh ) ? winHeight : screenh;
if ( left == int.MaxValue )
left = monitorInfo.WorkingArea.Left + ( screenw - outerw )/2;
else if ( monitorIndex != -1 )
left += monitorInfo.WorkingArea.Left;
if ( top == int.MaxValue )
top = monitorInfo.WorkingArea.Top + ( screenh - outerh )/2;
else if ( monitorIndex != -1 )
top += monitorInfo.WorkingArea.Top;
}
else if ( monitorIndex != -1 )
{
left += monitorInfo.WorkingArea.Left;
top += monitorInfo.WorkingArea.Top;
}
this.width = desiredWidth = width;
this.height = desiredHeight = height;
this.top = top;
this.left = left;
if ( fullScreen )
{
dwStyleEx |= WindowsExtendedStyle.WS_EX_TOPMOST;
this.top = monitorInfo.Bounds.Top;
this.left = monitorInfo.Bounds.Left;
}
else
{
AdjustWindow( width, height, ref winWidth, ref winHeight );
if ( !outerSize )
{
// Calculate window dimensions required
// to get the requested client area
rc = new System.Drawing.Rectangle( 0, 0, this.width, this.height );
AdjustWindowRect( ref rc, GetWindowStyle( fullScreen ), false );
this.width = rc.Right - rc.Left;
this.height = rc.Bottom - rc.Top;
// Clamp window rect to the nearest display monitor.
if ( this.left < monitorInfo.WorkingArea.Left )
this.left = monitorInfo.WorkingArea.Left;
if ( this.top < monitorInfo.WorkingArea.Top )
this.top = monitorInfo.WorkingArea.Top;
if ( winWidth > monitorInfo.WorkingArea.Right - this.left )
winWidth = monitorInfo.WorkingArea.Right - this.left;
if ( winHeight > monitorInfo.WorkingArea.Bottom - this.top )
winHeight = monitorInfo.WorkingArea.Bottom - this.top;
}
}
WindowClassStyle classStyle = 0;
if ( enableDoubleClick )
classStyle |= WindowClassStyle.CS_DBLCLKS;
// Register the window class
// NB allow 4 bytes of window data for D3D9RenderWindow pointer
/*
WNDCLASS wc = {
classStyle, WindowEventUtilities::_WndProc, 0, 0, hInst,
LoadIcon( 0, IDI_APPLICATION ), LoadCursor( NULL, IDC_ARROW ),
(HBRUSH)GetStockObject( BLACK_BRUSH ), 0, "OgreD3D9Wnd"
};
RegisterClass( &wc );
// Create our main window
// Pass pointer to self
_isExternal = false;
hWnd = CreateWindowEx( dwStyleEx, "OgreD3D9Wnd", title.c_str(), getWindowStyle( fullScreen ),
mLeft, mTop, winWidth, winHeight, parentHWnd, 0, hInst, this );
*/
var wnd = new DefaultForm(classStyle, dwStyleEx, title, GetWindowStyle(fullScreen),
this.left, this.top, winWidth, winHeight, parentHWnd);
hWnd = wnd;
wnd.RenderWindow = this;
WindowEventMonitor.Instance.RegisterWindow( this );
}
else
{
hWnd = externalHWnd;
_isExternal = true;
}
// top and left represent outer window coordinates
rc = new System.Drawing.Rectangle(hWnd.Location, hWnd.Size);
this.top = rc.Top;
this.left = rc.Left;
// width and height represent interior drawable area
rc = hWnd.ClientRectangle;
this.width = rc.Right;
this.height = rc.Bottom;
this.name = name;
depthBufferPoolId = depthBuffer ? PoolId.Default : PoolId.NoDepth;
this.depthBuffer = null;
this.colorDepth = colorDepth;
LogManager.Instance.Write("D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp",
this.name, this.width, this.height, this.colorDepth);
active = true;
_isClosed = false;
IsHidden = _hidden;
}