using SFML.Graphics;using SFML.Window;using System;using System.Threading;using System.Windows.Forms;namespace RenderControl
{ public partial class RenderControl
: UserControl
{ private RenderWindow m_Window
= null; private ContextSettings m_Context
; public RenderControl
(uint depth
= 0,
uint stencil
= 0,
uint antialiasing
= 0,
uint major
= 2,
uint minor
= 0) { InitializeComponent
(); this.m_Context = new ContextSettings
(depth, stencil, antialiasing, major, minor
); this.SizeChanged += new EventHandler
(RenderControl_SizeChanged
); } ~RenderControl
() { this.m_Window.Dispose(); } #region interface public void Create
() { Monitor
.Enter(this); if(this.m_Window != null) this.m_Window.Dispose(); this.m_Window = new RenderWindow
(this.Handle,
this.m_Context); this.m_Window.SetVerticalSyncEnabled(true); Monitor
.Exit(this); } public void Destroy
() { Monitor
.Enter(this); if (this.m_Window != null) { this.m_Window.Close(); this.m_Window.Dispose(); this.m_Window = null; } Monitor
.Exit(this); } public void DispatchEvents
() { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.DispatchEvents(); Monitor
.Exit(this); } public void SetActive
(bool active
= true) { Monitor
.Enter(this); if(this.m_Window != null) this.m_Window.SetActive(active
); Monitor
.Exit(this); } public void Clear
() { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Clear(Color
.Black); Monitor
.Exit(this); } public void Clear
(Color color
) { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Clear(color
); Monitor
.Exit(this); } public void Draw
(Drawable drawable
) { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Draw(drawable
); Monitor
.Exit(this); } public void Draw
(Drawable drawable, RenderStates states
) { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Draw(drawable, states
); Monitor
.Exit(this); } public void Draw
(Vertex
[] vertices, PrimitiveType type
) { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Draw(vertices, type
); Monitor
.Exit(this); } public void Draw
(Vertex
[] vertices, PrimitiveType type, RenderStates states
) { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Draw(vertices, type, states
); Monitor
.Exit(this); } public void Draw
(Vertex
[] vertices,
uint start,
uint count, PrimitiveType type
) { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Draw(vertices, start, count, type
); Monitor
.Exit(this); } public void Draw
(Vertex
[] vertices,
uint start,
uint count, PrimitiveType type, RenderStates states
) { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Draw(vertices, start, count, type, states
); Monitor
.Exit(this); } public void Display
() { Monitor
.Enter(this); if (this.m_Window != null) this.m_Window.Display(); this.Refresh(); Monitor
.Exit(this); } #endregion #region paint overrides protected override void OnPaint
(PaintEventArgs e
) { //don't call base method! //base.OnPaint(e); } protected override void OnPaintBackground
(PaintEventArgs e
) { //don't call base method! //base.OnPaintBackground(e); } #endregion void RenderControl_SizeChanged
(object sender, EventArgs e
) { Monitor
.Enter(this); //need to recreate view when the window changes if(this.m_Window != null) { this.m_Window.SetView(new SFML
.Graphics.View(new FloatRect
(0f, 0f,
this.Size.Width,
this.Size.Height))); } Monitor
.Exit(this); } }}