/// <summary> /// Renders the element using the specified renderer. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="element">The element.</param> /// <param name="x">The X coordinate (in pixels) of the upper left corner of the region the element should be rendered to.</param> /// <param name="y">The Y coordinate (in pixels) of the upper left corner of the region the element should be rendered to.</param> /// <param name="width">The width (in pixels) of the region the element should be rendered to.</param> /// <param name="height">The height (in pixels) of the region the element should be rendered to.</param> public virtual void Render(UserInterfaceRenderer renderer, Element element, int x, int y, int width, int height) { Color4 color = new Color4(1.0f, 1.0f, 1.0f); renderer.RenderRectangle(x, y, width, height, color); renderer.RenderString(element.Label, x, y, new Color4(1.0f, 0.0f, 0.0f)); }
private void HandleResize(object sender, EventArgs e) { if (_form.WindowState == FormWindowState.Minimized) { return; } OnResourceUnload(); if (Context9 != null) { userInterfaceRenderer.Dispose(); Context9.PresentParameters.BackBufferWidth = 0; Context9.PresentParameters.BackBufferHeight = 0; Context9.Device.Reset(Context9.PresentParameters); userInterfaceRenderer = new UserInterfaceRenderer9(Context9.Device, _form.ClientSize.Width, _form.ClientSize.Height); } else if (Context10 != null) { userInterfaceRenderer.Dispose(); Context10.SwapChain.ResizeBuffers(1, WindowWidth, WindowHeight, Context10.SwapChain.Description.ModeDescription.Format, Context10.SwapChain.Description.Flags); userInterfaceRenderer = new UserInterfaceRenderer10(Context10.Device, _form.ClientSize.Width, _form.ClientSize.Height); } OnResourceLoad(); }
/// <summary> /// Renders the sample. /// </summary> private void Render() { if (deviceLost) { // This should only become true if we're using D3D9, so we can assume the // D3D9 context is valid at this point. if (Context9.Device.TestCooperativeLevel() == SlimDX.Direct3D9.ResultCode.DeviceNotReset) { Context9.Device.Reset(Context9.PresentParameters); deviceLost = false; userInterfaceRenderer = new UserInterfaceRenderer9(Context9.Device, WindowWidth, WindowHeight); OnResourceLoad(); } else { Thread.Sleep(100); return; } } frameAccumulator += FrameDelta; ++frameCount; if (frameAccumulator >= 1.0f) { framesPerSecond.Value = frameCount / frameAccumulator; frameAccumulator = 0.0f; frameCount = 0; } try { OnRenderBegin(); OnRender(); if (userInterfaceRenderer != null) { userInterfaceRenderer.Render(userInterface); } OnRenderEnd(); } catch (SlimDX.Direct3D9.Direct3D9Exception e) { if (e.ResultCode == SlimDX.Direct3D9.ResultCode.DeviceLost) { OnResourceUnload(); userInterfaceRenderer.Dispose(); deviceLost = true; } else { throw; } } }
/// <summary> /// Handles a key up event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param> private void HandleKeyUp(object sender, KeyEventArgs e) { if (e.Alt && e.KeyCode == Keys.Enter) { OnResourceUnload(); isFullScreen = !isFullScreen; if (Context9 != null) { userInterfaceRenderer.Dispose(); Context9.PresentParameters.BackBufferWidth = _configuration.WindowWidth; Context9.PresentParameters.BackBufferHeight = _configuration.WindowHeight; Context9.PresentParameters.Windowed = !isFullScreen; if (!isFullScreen) { _form.MaximizeBox = true; } Context9.Device.Reset(Context9.PresentParameters); userInterfaceRenderer = new UserInterfaceRenderer9(Context9.Device, _form.ClientSize.Width, _form.ClientSize.Height); } else if (Context10 != null) { userInterfaceRenderer.Dispose(); Context10.SwapChain.ResizeBuffers(1, WindowWidth, WindowHeight, Context10.SwapChain.Description.ModeDescription.Format, SwapChainFlags.AllowModeSwitch); Context10.SwapChain.SetFullScreenState(isFullScreen, null); userInterfaceRenderer = new UserInterfaceRenderer10(Context10.Device, WindowWidth, WindowHeight); } OnResourceLoad(); } }
/// <summary> /// Measures the element, returning the size (in pixels) it would occupy if /// rendered with the specified renderer. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="element">The element.</param> /// <returns>The size of the element (in pixels).</returns> public virtual Vector2 Measure(UserInterfaceRenderer renderer, Element element) { return(renderer.MeasureString(element.Label)); }
private void HandleResize( object sender, EventArgs e ) { if( _form.WindowState == FormWindowState.Minimized ) { return; } OnResourceUnload(); if( Context9 != null ) { userInterfaceRenderer.Dispose(); Context9.PresentParameters.BackBufferWidth = 0; Context9.PresentParameters.BackBufferHeight = 0; Context9.Device.Reset( Context9.PresentParameters ); userInterfaceRenderer = new UserInterfaceRenderer9( Context9.Device, _form.ClientSize.Width, _form.ClientSize.Height ); } else if( Context10 != null ) { userInterfaceRenderer.Dispose(); Context10.SwapChain.ResizeBuffers( 1, WindowWidth, WindowHeight, Context10.SwapChain.Description.ModeDescription.Format, Context10.SwapChain.Description.Flags ); userInterfaceRenderer = new UserInterfaceRenderer10( Context10.Device, _form.ClientSize.Width, _form.ClientSize.Height ); } OnResourceLoad(); }
/// <summary> /// Handles a key up event. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Forms.KeyEventArgs"/> instance containing the event data.</param> private void HandleKeyUp( object sender, KeyEventArgs e ) { if( e.Alt && e.KeyCode == Keys.Enter ) { OnResourceUnload(); isFullScreen = !isFullScreen; if( Context9 != null ) { userInterfaceRenderer.Dispose(); Context9.PresentParameters.BackBufferWidth = _configuration.WindowWidth; Context9.PresentParameters.BackBufferHeight = _configuration.WindowHeight; Context9.PresentParameters.Windowed = !isFullScreen; if( !isFullScreen ) _form.MaximizeBox = true; Context9.Device.Reset( Context9.PresentParameters ); userInterfaceRenderer = new UserInterfaceRenderer9( Context9.Device, _form.ClientSize.Width, _form.ClientSize.Height ); } else if( Context10 != null ) { userInterfaceRenderer.Dispose(); Context10.SwapChain.ResizeBuffers( 1, WindowWidth, WindowHeight, Context10.SwapChain.Description.ModeDescription.Format, SwapChainFlags.AllowModeSwitch ); Context10.SwapChain.SetFullScreenState( isFullScreen, null ); userInterfaceRenderer = new UserInterfaceRenderer10( Context10.Device, WindowWidth, WindowHeight ); } OnResourceLoad(); } }
/// <summary> /// Renders the sample. /// </summary> private void Render() { if( deviceLost ) { // This should only become true if we're using D3D9, so we can assume the // D3D9 context is valid at this point. if( Context9.Device.TestCooperativeLevel() == SlimDX.Direct3D9.ResultCode.DeviceNotReset ) { Context9.Device.Reset( Context9.PresentParameters ); deviceLost = false; userInterfaceRenderer = new UserInterfaceRenderer9( Context9.Device, WindowWidth, WindowHeight ); OnResourceLoad(); } else { Thread.Sleep( 100 ); return; } } frameAccumulator += FrameDelta; ++frameCount; if( frameAccumulator >= 1.0f ) { framesPerSecond.Value = frameCount / frameAccumulator; frameAccumulator = 0.0f; frameCount = 0; } try { OnRenderBegin(); OnRender(); if( userInterfaceRenderer != null ) { userInterfaceRenderer.Render( userInterface ); } OnRenderEnd(); } catch( SlimDX.Direct3D9.Direct3D9Exception e ) { if( e.ResultCode == SlimDX.Direct3D9.ResultCode.DeviceLost ) { OnResourceUnload(); userInterfaceRenderer.Dispose(); deviceLost = true; } else { throw; } } }
/// <summary> /// Renders the element using the specified renderer. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="element">The element.</param> /// <param name="x">The X coordinate (in pixels) of the upper left corner of the region the element should be rendered to.</param> /// <param name="y">The Y coordinate (in pixels) of the upper left corner of the region the element should be rendered to.</param> /// <param name="width">The width (in pixels) of the region the element should be rendered to.</param> /// <param name="height">The height (in pixels) of the region the element should be rendered to.</param> public virtual void Render(UserInterfaceRenderer renderer, Element element, int x, int y, int width, int height) { Color4 color = new Color4(1.0f, 1.0f, 1.0f); renderer.RenderRectangle(x, y, width, height, color); renderer.RenderString(element.Label, 0, 0, new Color4(1.0f, 0.0f, 0.0f)); }
/// <summary> /// Measures the element, returning the size (in pixels) it would occupy if /// rendered with the specified renderer. /// </summary> /// <param name="renderer">The renderer.</param> /// <param name="element">The element.</param> /// <returns>The size of the element (in pixels).</returns> public virtual Vector2 Measure(UserInterfaceRenderer renderer, Element element) { return renderer.MeasureString(element.Label); }