SdlDotNet.Windows
From SDL.NET
| Table of contents |
Introduction
SDL.NET's windows assembly includes a SurfaceControl class that displays a Surface on a Winform.
Adding the SurfaceControl to Visual Studio 2005
- From the 'View' menu item, choose 'Toolbox'. The Toolbox containing Winforms controls will appear.
- Right click and choose 'Choose Items...'.
- Click 'Browse' and locate your SdlDotNet.dll.
- In the '.NET Framework Components' list, check newly added SurfaceControl.
- The toolbox should now contain a SurfaceControl icon.
Adding the SurfaceControl in a Winform Application
- Drag the control from the Toolbox to the Winform you are creating.
- You can adjust the properties via the property page as needed.
Using the SurfaceControl to Display SDL.NET Surfaces
You must add the SurfaceControl to the Winform.
private SdlDotNet.Windows.SurfaceControl surfaceControl;
You should instantiate a Surface object to draw to.
private Surface surf;
It would be a good idea to make the Surface the same size as the SurfaceControl.
surf = new Surface(this.surfaceControl.Width, this.surfaceControl.Height);
Manipulate the Surface object as you want by blitting Sprites or drawing primitive for example. Then update the Surface Control by blitting the Surface to it via a Tick Event
private void Events_Tick(object sender, SdlDotNet.TickEventArgs e)
{
surf.Fill(Color.Black);
surf.Blit(master);
this.UpdateForm();
}
public void UpdateForm()
{
this.surfaceControl.Blit(surf);
}
This event would be added to the SdlDotNet.Core.Events.Tick event as usual, in your Form's constructor:
SdlDotNet.Core.Events.Tick += new EventHandler<TickEventArgs>(Events_Tick);
Do not call SdlDotNet.Core.Events.Run() as you normally would. In order for your application to call tick events and remain functional in Windows, you will need to start a thread that calls the Tick event. This should be set up in your Form's Load event. Here is an example of such a function, taken from the http://cs-sdl.sourceforge.net/index.php/Category:Examples#CD_Player:
private void Form1_Load(object sender, System.EventArgs e)
{
Thread thread = new Thread(new ThreadStart(SdlDotNet.Core.Events.Run));
thread.IsBackground = true;
thread.Name = "SDL.NET";
thread.Priority = ThreadPriority.Normal;
thread.Start();
}
This should be bound to your Form's Load event. In Visual Studio, you can find this in the Events section of the Form's properties window.
--Manas 03:40, 20 Jun 2008 (PDT)----
To create a line on this surface -
private void button1_Click(object sender, EventArgs e)
{
SdlDotNet.Graphics.Primitives.Line ln = new SdlDotNet.Graphics.Primitives.Line(20, 20, 200, 50);
surf.Draw(ln,Color.Wheat);
this.UpdateForm();
}
See Also
- CD Player - An example of its use.
Categories: Tutorials | Examples | Stubs

