protected override void WndProc(ref Message m) { switch (m.Msg) { case 0x00000020: // WM_SETCURSOR if (OverrideCursor) { if (Root.Instance.RenderSystem != null) { Root.Instance.RenderSystem.RestoreCursor(); m.Result = new IntPtr(1); // return TRUE; return; } } break; } if (!DefaultForm.WndOverride(ref m)) { base.WndProc(ref m); } }
public override void Create(string name, int width, int height, bool fullScreen, NamedParameterList miscParams) { SWF.Control parentHWnd = null; SWF.Control externalHWnd = null; this._fsaaType = D3D9.MultisampleType.None; this._fsaaQuality = 0; fsaa = 0; this._vSync = false; this._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; var enableDoubleClick = false; this._useNVPerfHUD = false; //var fsaaSamples = 0; //Not used, even in Ogre var fsaaHint = string.Empty; 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)) { this._vSync = bool.Parse(opt.ToString()); } // vsyncInterval [parseUnsignedInt] if (miscParams.TryGetValue("vsyncInterval", out opt)) { this._vSyncInterval = Int32.Parse(opt.ToString()); } // displayFrequency if (miscParams.TryGetValue("displayFrequency", out opt)) { this._displayFrequency = Int32.Parse(opt.ToString()); } // colorDepth 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 settings // FSAA type if (miscParams.TryGetValue("FSAA", out opt)) { this._fsaaType = (D3D9.MultisampleType)opt; } if (miscParams.TryGetValue("FSAAHint", out opt)) { fsaaHint = (string)opt; } // 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)) { this._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()); } // enable double click messages if (miscParams.TryGetValue("enableDoubleClick", out opt)) { enableDoubleClick = bool.Parse(opt.ToString()); } } // Destroy current window if any if (this._windowHandle != null) { Destroy(); } if (externalHWnd == null) { var dwStyle = WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPCHILDREN; var dwStyleEx = (WindowsExtendedStyle)0; var monitorHandle = IntPtr.Zero; RECT rc; // If we specified which adapter we want to use - find it's monitor. if (monitorIndex != -1) { var direct3D9 = D3D9RenderSystem.Direct3D9; for (var i = 0; i < direct3D9.AdapterCount; ++i) { if (i != monitorIndex) { continue; } monitorHandle = direct3D9.GetAdapterMonitor(i); break; } } // If we didn't specified the adapter index, or if it didn't find it if (monitorHandle == IntPtr.Zero) { // Fill in anchor point. var windowAnchorPoint = new Point(left, top); // Get the nearest monitor to this window. monitorHandle = ScreenHelper.GetHandle(windowAnchorPoint); } // Get the target monitor info var monitorInfo = ScreenHelper.FromHandle(monitorHandle); 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 = this._desiredWidth = width; this.height = this._desiredHeight = height; this.top = top; this.left = left; if (fullScreen) { dwStyleEx |= WindowsExtendedStyle.WS_EX_TOPMOST; dwStyle |= WindowStyles.WS_POPUP; this.top = monitorInfo.Bounds.Top; this.left = monitorInfo.Bounds.Left; } else { if (parentHWnd != null) { dwStyle |= WindowStyles.WS_CHILD; } else { if (border == "none") { dwStyle |= WindowStyles.WS_POPUP; } else if (border == "fixed") { dwStyle |= WindowStyles.WS_OVERLAPPED | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX; } else { dwStyle |= WindowStyles.WS_OVERLAPPEDWINDOW; } } AdjustWindow(width, height, dwStyle, out winWidth, out winHeight); if (!outerSize) { // Calculate window dimensions required // to get the requested client area rc = new RECT(0, 0, this.width, this.height); AdjustWindowRect(ref rc, dwStyle, 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; } // Create our main window this._isExternal = false; var wnd = new DefaultForm(classStyle, dwStyleEx, title, dwStyle, this.left, this.top, winWidth, winHeight, parentHWnd); wnd.RenderWindow = this; this._windowHandle = wnd; this._style = dwStyle; WindowEventMonitor.Instance.RegisterWindow(this); } else { this._windowHandle = externalHWnd; this._isExternal = true; } // top and left represent outer window coordinates var rc2 = new System.Drawing.Rectangle(this._windowHandle.Location, this._windowHandle.Size); this.top = rc2.Top; this.left = rc2.Left; // width and height represent interior drawable area rc2 = this._windowHandle.ClientRectangle; this.width = rc2.Right; this.height = rc2.Bottom; this.name = name; isDepthBuffered = depthBuffer; isFullScreen = fullScreen; this.colorDepth = colorDepth; LogManager.Instance.Write("D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", this.name, this.width, this.height, ColorDepth); active = true; this._isClosed = false; }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="colorDepth"></param> /// <param name="isFullScreen"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="depthBuffer"></param>height /// <param name="miscParams"></param> public override void Create(string name, int width, int height, bool isFullScreen, params object[] miscParams) { Control parentWindow = null; Control externalWindow = null; fsaaType = MultiSampleType.None; fsaaQuality = 0; isVSync = false; string title = name; int colorDepth = 32; int left = -1; int top = -1; bool depthBuffer = true; // Parameters that would have been set in the params list, but are not used // border, outerSize useNVPerfHUD = false; multiThreaded = false; Debug.Assert(miscParams.Length % 2 == 0); int index = 0; while (index < miscParams.Length) { string key = (string)miscParams[index++]; object value = miscParams[index++]; switch (key) { case "left": left = (int)value; break; case "top": top = (int)value; break; case "title": title = (string)value; break; case "parentWindow": parentWindow = (Control)value; break; case "externalWindow": externalWindow = (Control)value; break; case "vsync": isVSync = (bool)value; break; case "displayFrequency": displayFrequency = (int)value; break; case "colorDepth": case "colourDepth": colorDepth = (int)value; break; case "depthBuffer": depthBuffer = (bool)value; break; case "FSAA": fsaaType = (MultiSampleType)value; break; case "FSAAQuality": fsaaQuality = (int)value; break; case "useNVPerfHUD": useNVPerfHUD = (bool)value; break; case "multiThreaded": multiThreaded = (bool)value; break; case "initialLoadBitmap": initialLoadBitmap = (string)value; break; case "border": case "outerDimensions": default: log.Warn("Option not yet implemented"); break; } } if (windowHandle != null) Destroy(); if (externalWindow == null) { this.width = width; this.height = height; this.top = top; this.left = left; FormBorderStyle borderStyle = FormBorderStyle.None; FormWindowState windowState = FormWindowState.Normal; if (!isFullScreen) { // If RenderSystem.AllowResize is true, put a // resize border on the window. borderStyle = (Root.Instance.RenderSystem.AllowResize ? FormBorderStyle.Sizable : FormBorderStyle.FixedSingle); windowState = FormWindowState.Normal; } else { borderStyle = FormBorderStyle.None; windowState = FormWindowState.Maximized; this.top = 0; this.left = 0; } isExternal = false; form = new DefaultForm(!isFullScreen, initialLoadBitmap); // Set these two to false, or else windows get created // with different dimensions that requesting in Width // and Height! log.InfoFormat("Initial form settings: AutoSize: {0}; AutoScale: {1}", form.AutoSize, form.AutoScaleMode); form.AutoSize = false; form.AutoScaleMode = AutoScaleMode.None; form.ClientSize = new System.Drawing.Size(width, height); // TODO: I should support the maximize box once I get resize working // form.MaximizeBox = true; form.MaximizeBox = false; form.MinimizeBox = true; form.Top = this.top; form.Left = this.left; form.FormBorderStyle = borderStyle; form.WindowState = windowState; form.Text = title; form.StartPosition = FormStartPosition.CenterScreen; form.BringToFront(); if (isFullScreen) { form.TopMost = true; form.TopLevel = true; form.Width = width; form.Height = height; } // form.Target.Visible = false; form.Show(); // set the default form's renderwindow so it can access it internally form.RenderWindow = this; form.Activate(); windowHandle = form.Target; } else { windowHandle = externalWindow; isExternal = true; this.top = windowHandle.Top; this.left = windowHandle.Left; System.Drawing.Rectangle rect = windowHandle.ClientRectangle; this.width = rect.Width; this.height = rect.Height; } windowHandle.Resize += this.OnExternalWindowEvent; windowHandle.Move += this.OnExternalWindowEvent; this.name = name; this.isDepthBuffered = depthBuffer; this.isFullScreen = isFullScreen; this.colorDepth = colorDepth; CreateD3DResources(); isActive = true; // FIXME: These lines were not in Ogre, but are in Axiom. //D3D.Device device = driver.Device; // device.DeviceReset += new EventHandler(OnResetDevice); //this.OnResetDevice(device, null); }
/// <summary> /// Creates a default form to use for a rendering target. /// </summary> /// <remarks> /// This is used internally whenever <see cref="Initialize"/> is called and autoCreateWindow is set to true. /// </remarks> /// <param name="windowTitle">Title of the window.</param> /// <param name="top">Top position of the window.</param> /// <param name="left">Left position of the window.</param> /// <param name="width">Width of the window.</param> /// <param name="height">Height of the window</param> /// <param name="fullScreen">Prepare the form for fullscreen mode?</param> /// <returns>A form suitable for using as a rendering target.</returns> private DefaultForm CreateDefaultForm(string windowTitle, int top, int left, int width, int height, bool fullScreen) { DefaultForm form = new DefaultForm(); form.ClientSize = new System.Drawing.Size(width,height); form.MaximizeBox = true; form.MinimizeBox = true; form.StartPosition = FormStartPosition.CenterScreen; form.BringToFront(); if(fullScreen) { form.Top = 0; form.Left = 0; form.FormBorderStyle = FormBorderStyle.None; form.WindowState = FormWindowState.Maximized; form.TopMost = true; form.TopLevel = true; } else { form.Top = top; form.Left = left; form.FormBorderStyle = FormBorderStyle.FixedSingle; form.WindowState = FormWindowState.Normal; form.Text = windowTitle; } return form; }
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() ); // colorDepth 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; }
/// <summary> /// /// </summary> /// <param name="name"></param> /// <param name="width"></param> /// <param name="height"></param> /// <param name="colorDepth"></param> /// <param name="isFullScreen"></param> /// <param name="left"></param> /// <param name="top"></param> /// <param name="depthBuffer"></param>height /// <param name="miscParams"></param> public override void Create(string name, int width, int height, bool isFullScreen, params object[] miscParams) { Control parentWindow = null; Control externalWindow = null; fsaaType = MultiSampleType.None; fsaaQuality = 0; isVSync = false; string title = name; int colorDepth = 32; int left = -1; int top = -1; bool depthBuffer = true; // Parameters that would have been set in the params list, but are not used // border, outerSize useNVPerfHUD = false; multiThreaded = false; Debug.Assert(miscParams.Length % 2 == 0); int index = 0; while (index < miscParams.Length) { string key = (string)miscParams[index++]; object value = miscParams[index++]; switch (key) { case "left": left = (int)value; break; case "top": top = (int)value; break; case "title": title = (string)value; break; case "parentWindow": parentWindow = (Control)value; break; case "externalWindow": externalWindow = (Control)value; break; case "vsync": isVSync = (bool)value; break; case "displayFrequency": displayFrequency = (int)value; break; case "colorDepth": case "colourDepth": colorDepth = (int)value; break; case "depthBuffer": depthBuffer = (bool)value; break; case "FSAA": fsaaType = (MultiSampleType)value; break; case "FSAAQuality": fsaaQuality = (int)value; break; case "useNVPerfHUD": useNVPerfHUD = (bool)value; break; case "multiThreaded": multiThreaded = (bool)value; break; case "initialLoadBitmap": initialLoadBitmap = (string)value; break; case "border": case "outerDimensions": default: log.Warn("Option not yet implemented"); break; } } if (windowHandle != null) { Destroy(); } if (externalWindow == null) { this.width = width; this.height = height; this.top = top; this.left = left; FormBorderStyle borderStyle = FormBorderStyle.None; FormWindowState windowState = FormWindowState.Normal; if (!isFullScreen) { // If RenderSystem.AllowResize is true, put a // resize border on the window. borderStyle = (Root.Instance.RenderSystem.AllowResize ? FormBorderStyle.Sizable : FormBorderStyle.FixedSingle); windowState = FormWindowState.Normal; } else { borderStyle = FormBorderStyle.None; windowState = FormWindowState.Maximized; this.top = 0; this.left = 0; } isExternal = false; form = new DefaultForm(!isFullScreen, initialLoadBitmap); // Set these two to false, or else windows get created // with different dimensions that requesting in Width // and Height! log.InfoFormat("Initial form settings: AutoSize: {0}; AutoScale: {1}", form.AutoSize, form.AutoScaleMode); form.AutoSize = false; form.AutoScaleMode = AutoScaleMode.None; form.ClientSize = new System.Drawing.Size(width, height); // TODO: I should support the maximize box once I get resize working // form.MaximizeBox = true; form.MaximizeBox = false; form.MinimizeBox = true; form.Top = this.top; form.Left = this.left; form.FormBorderStyle = borderStyle; form.WindowState = windowState; form.Text = title; form.StartPosition = FormStartPosition.CenterScreen; form.BringToFront(); if (isFullScreen) { form.TopMost = true; form.TopLevel = true; form.Width = width; form.Height = height; } // form.Target.Visible = false; form.Show(); // set the default form's renderwindow so it can access it internally form.RenderWindow = this; form.Activate(); windowHandle = form.Target; } else { windowHandle = externalWindow; isExternal = true; this.top = windowHandle.Top; this.left = windowHandle.Left; System.Drawing.Rectangle rect = windowHandle.ClientRectangle; this.width = rect.Width; this.height = rect.Height; } windowHandle.Resize += this.OnExternalWindowEvent; windowHandle.Move += this.OnExternalWindowEvent; this.name = name; this.isDepthBuffered = depthBuffer; this.isFullScreen = isFullScreen; this.colorDepth = colorDepth; CreateD3DResources(); isActive = true; // FIXME: These lines were not in Ogre, but are in Axiom. //D3D.Device device = driver.Device; // device.DeviceReset += new EventHandler(OnResetDevice); //this.OnResetDevice(device, null); }
public override void Create( string name, int width, int height, bool fullScreen, NamedParameterList miscParams ) { SWF.Control parentHWnd = null; SWF.Control externalHWnd = null; this._fsaaType = D3D9.MultisampleType.None; this._fsaaQuality = 0; fsaa = 0; this._vSync = false; this._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; var enableDoubleClick = false; this._useNVPerfHUD = false; //var fsaaSamples = 0; //Not used, even in Ogre var fsaaHint = string.Empty; 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 ) ) { this._vSync = bool.Parse( opt.ToString() ); } // vsyncInterval [parseUnsignedInt] if ( miscParams.TryGetValue( "vsyncInterval", out opt ) ) { this._vSyncInterval = Int32.Parse( opt.ToString() ); } // displayFrequency if ( miscParams.TryGetValue( "displayFrequency", out opt ) ) { this._displayFrequency = Int32.Parse( opt.ToString() ); } // colorDepth 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 settings // FSAA type if ( miscParams.TryGetValue( "FSAA", out opt ) ) { this._fsaaType = (D3D9.MultisampleType)opt; } if ( miscParams.TryGetValue( "FSAAHint", out opt ) ) { fsaaHint = (string)opt; } // 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 ) ) { this._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() ); } // enable double click messages if ( miscParams.TryGetValue( "enableDoubleClick", out opt ) ) { enableDoubleClick = bool.Parse( opt.ToString() ); } } // Destroy current window if any if ( this._windowHandle != null ) { Destroy(); } if ( externalHWnd == null ) { var dwStyle = WindowStyles.WS_VISIBLE | WindowStyles.WS_CLIPCHILDREN; var dwStyleEx = (WindowsExtendedStyle)0; var monitorHandle = IntPtr.Zero; RECT rc; // If we specified which adapter we want to use - find it's monitor. if ( monitorIndex != -1 ) { var direct3D9 = D3D9RenderSystem.Direct3D9; for ( var i = 0; i < direct3D9.AdapterCount; ++i ) { if ( i != monitorIndex ) { continue; } monitorHandle = direct3D9.GetAdapterMonitor( i ); break; } } // If we didn't specified the adapter index, or if it didn't find it if ( monitorHandle == IntPtr.Zero ) { // Fill in anchor point. var windowAnchorPoint = new Point( left, top ); // Get the nearest monitor to this window. monitorHandle = ScreenHelper.GetHandle( windowAnchorPoint ); } // Get the target monitor info var monitorInfo = ScreenHelper.FromHandle( monitorHandle ); 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 = this._desiredWidth = width; this.height = this._desiredHeight = height; this.top = top; this.left = left; if ( fullScreen ) { dwStyleEx |= WindowsExtendedStyle.WS_EX_TOPMOST; dwStyle |= WindowStyles.WS_POPUP; this.top = monitorInfo.Bounds.Top; this.left = monitorInfo.Bounds.Left; } else { if ( parentHWnd != null ) { dwStyle |= WindowStyles.WS_CHILD; } else { if ( border == "none" ) { dwStyle |= WindowStyles.WS_POPUP; } else if ( border == "fixed" ) { dwStyle |= WindowStyles.WS_OVERLAPPED | WindowStyles.WS_BORDER | WindowStyles.WS_CAPTION | WindowStyles.WS_SYSMENU | WindowStyles.WS_MINIMIZEBOX; } else { dwStyle |= WindowStyles.WS_OVERLAPPEDWINDOW; } } AdjustWindow( width, height, dwStyle, out winWidth, out winHeight ); if ( !outerSize ) { // Calculate window dimensions required // to get the requested client area rc = new RECT( 0, 0, this.width, this.height ); AdjustWindowRect( ref rc, dwStyle, 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; } // Create our main window this._isExternal = false; var wnd = new DefaultForm( classStyle, dwStyleEx, title, dwStyle, this.left, this.top, winWidth, winHeight, parentHWnd ); wnd.RenderWindow = this; this._windowHandle = wnd; this._style = dwStyle; WindowEventMonitor.Instance.RegisterWindow( this ); } else { this._windowHandle = externalHWnd; this._isExternal = true; } // top and left represent outer window coordinates var rc2 = new System.Drawing.Rectangle( this._windowHandle.Location, this._windowHandle.Size ); this.top = rc2.Top; this.left = rc2.Left; // width and height represent interior drawable area rc2 = this._windowHandle.ClientRectangle; this.width = rc2.Right; this.height = rc2.Bottom; this.name = name; isDepthBuffered = depthBuffer; isFullScreen = fullScreen; this.colorDepth = colorDepth; LogManager.Instance.Write( "D3D9 : Created D3D9 Rendering Window '{0}' : {1}x{2}, {3}bpp", this.name, this.width, this.height, ColorDepth ); active = true; this._isClosed = false; }