Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
71
dotnet/MainPage.html
Normal file
71
dotnet/MainPage.html
Normal file
|
@ -0,0 +1,71 @@
|
|||
<h2>Welcome</h2>
|
||||
<p>
|
||||
Welcome to the official SFML.Net documentation. Here you will find a detailed
|
||||
description of all the SFML.Net classes. <br/>
|
||||
If you are looking for tutorials, help or whatever, you can visit the official website
|
||||
at <a href="http://www.sfml-dev.org/">www.sfml-dev.org</a>.
|
||||
</p>
|
||||
|
||||
<h2>Short example</h2>
|
||||
<p>
|
||||
Here is a short example in C#, to show you how simple it is to use SFML.Net :
|
||||
</p>
|
||||
|
||||
<pre style="background-color:#F0F0F0">
|
||||
<span style="color:blue">using</span> System;
|
||||
<span style="color:blue">using</span> SFML.Audio;
|
||||
<span style="color:blue">using</span> SFML.Window;
|
||||
<span style="color:blue">using</span> SFML.Graphics;
|
||||
|
||||
<span style="color:blue">namespace</span> Example
|
||||
{
|
||||
<span style="color:blue">class</span> <span style="color:#2B91AF">Program</span>
|
||||
{
|
||||
<span style="color:blue">static void</span> OnClose(<span style="color:blue">object</span> sender, <span style="color:#2B91AF">EventArgs</span> e)
|
||||
{
|
||||
<span style="color:#008000">// Close the window when OnClose event is received</span>
|
||||
<span style="color:#2B91AF">RenderWindow</span> window = (<span style="color:#2B91AF">RenderWindow</span>)sender;
|
||||
window.Close();
|
||||
}
|
||||
|
||||
<span style="color:blue">static void</span> Main(<span style="color:blue">string</span>[] args)
|
||||
{
|
||||
<span style="color:#008000">// Create the main window</span>
|
||||
<span style="color:#2B91AF">RenderWindow</span> app = <span style="color:blue">new</span> <span style="color:#2B91AF">RenderWindow</span>(<span style="color:blue">new</span> <span style="color:#2B91AF">VideoMode</span>(800, 600), <span style="color:#A31515">"SFML window"</span>);
|
||||
app.Closed += <span style="color:blue">new</span> <span style="color:#2B91AF">EventHandler</span>(OnClose);
|
||||
|
||||
<span style="color:#008000">// Load a sprite to display</span>
|
||||
<span style="color:#2B91AF">Image</span> image = <span style="color:blue">new</span> <span style="color:#2B91AF">Image</span>(<span style="color:#A31515">"cute_image.jpg"</span>);
|
||||
<span style="color:#2B91AF">Sprite</span> sprite = <span style="color:blue">new</span> <span style="color:#2B91AF">Sprite</span>(image);
|
||||
|
||||
<span style="color:#008000">// Create a graphical string to display</span>
|
||||
<span style="color:#2B91AF">Font</span> arial = <span style="color:blue">new</span> <span style="color:#2B91AF">Font</span>(<span style="color:#A31515">"arial.ttf"</span>);
|
||||
<span style="color:#2B91AF">String2D</span> text = <span style="color:blue">new</span> <span style="color:#2B91AF">String2D</span>(<span style="color:#A31515">"Hello SFML.Net"</span>, arial);
|
||||
|
||||
<span style="color:#008000">// Load a music to play</span>
|
||||
<span style="color:#2B91AF">Music</span> music = <span style="color:blue">new</span> Music(<span style="color:#A31515">"nice_music.ogg"</span>);
|
||||
music.Play();
|
||||
|
||||
<span style="color:#008000">// Start the game loop</span>
|
||||
<span style="color:blue">while</span> (app.IsOpened())
|
||||
{
|
||||
<span style="color:#008000">// Process events</span>
|
||||
app.DispatchEvents();
|
||||
|
||||
<span style="color:#008000">// Clear screen</span>
|
||||
app.Clear();
|
||||
|
||||
<span style="color:#008000">// Draw the sprite</span>
|
||||
app.Draw(sprite);
|
||||
|
||||
<span style="color:#008000">// Draw the string</span>
|
||||
app.Draw(text);
|
||||
|
||||
<span style="color:#008000">// Update the window</span>
|
||||
app.Display();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</pre>
|
||||
|
35
dotnet/SFML.ndoc
Normal file
35
dotnet/SFML.ndoc
Normal file
|
@ -0,0 +1,35 @@
|
|||
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
|
||||
<project SchemaVersion="2.0">
|
||||
<assemblies>
|
||||
<assembly location=".\lib\sfmlnet-graphics.dll" documentation=".\lib\graphics-doc.xml" />
|
||||
<assembly location=".\lib\sfmlnet-window.dll" documentation=".\lib\window-doc.xml" />
|
||||
<assembly location=".\lib\sfmlnet-audio.dll" documentation=".\lib\audio-doc.xml" />
|
||||
</assemblies>
|
||||
<documenters>
|
||||
<documenter name="MSDN-Help2">
|
||||
<property name="PlugInNamespace" value="ms.vscc" />
|
||||
<property name="OutputDirectory" value=".\doc\" />
|
||||
<property name="HtmlHelpName" value="Documentation" />
|
||||
<property name="Title" value="An NDoc documented library" />
|
||||
</documenter>
|
||||
<documenter name="MSDN-CHM">
|
||||
<property name="RootPageFileName" value=".\MainPage.html" />
|
||||
<property name="OutputDirectory" value=".\doc\" />
|
||||
<property name="HtmlHelpName" value="SFML.Net" />
|
||||
<property name="Title" value="SFML.Net documentation" />
|
||||
<property name="IncrementalBuild" value="True" />
|
||||
<property name="DocumentExplicitInterfaceImplementations" value="True" />
|
||||
<property name="DocumentProtected" value="False" />
|
||||
<property name="CleanIntermediates" value="True" />
|
||||
</documenter>
|
||||
<documenter name="Intellisense">
|
||||
<property name="OutputDirectory" value=".\intellisense\" />
|
||||
<property name="DocumentProtected" value="False" />
|
||||
</documenter>
|
||||
<documenter name="MSDN-Web">
|
||||
<property name="OutputDirectory" value=".\doc\" />
|
||||
<property name="HtmlHelpName" value="Documentation" />
|
||||
<property name="Title" value="An NDoc documented library" />
|
||||
</documenter>
|
||||
</documenters>
|
||||
</project>
|
62
dotnet/build/vc2005/SFML.net.sln
Normal file
62
dotnet/build/vc2005/SFML.net.sln
Normal file
|
@ -0,0 +1,62 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 9.00
|
||||
# Visual C# Express 2005
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sfml-window", "..\..\src\Window\sfml-window.csproj", "{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sfml-graphics", "..\..\src\Graphics\sfml-graphics.csproj", "{46786269-57B9-48E7-AA4F-8F4D84609FE6}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sfml-audio", "..\..\src\Audio\sfml-audio.csproj", "{0B202C4D-A457-47FE-84A3-031DD878C6BE}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-opengl", "..\..\samples\opengl\sample-opengl.csproj", "{160AE11E-138A-4B77-9642-EA74F9A79B4D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-window", "..\..\samples\window\sample-window.csproj", "{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-postfx", "..\..\samples\post-fx\sample-postfx.csproj", "{9D4738F7-34EA-433A-A765-AF85A52A174D}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-sound", "..\..\samples\sound\sample-sound.csproj", "{16E177F3-A0FF-4091-8521-562E0EBAA3AB}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "sample-soundcapture", "..\..\samples\sound_capture\sample-soundcapture.csproj", "{F2F48990-F81E-41BA-AD01-168F6178C807}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{46786269-57B9-48E7-AA4F-8F4D84609FE6}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{46786269-57B9-48E7-AA4F-8F4D84609FE6}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{46786269-57B9-48E7-AA4F-8F4D84609FE6}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{46786269-57B9-48E7-AA4F-8F4D84609FE6}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{0B202C4D-A457-47FE-84A3-031DD878C6BE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{0B202C4D-A457-47FE-84A3-031DD878C6BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{0B202C4D-A457-47FE-84A3-031DD878C6BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{0B202C4D-A457-47FE-84A3-031DD878C6BE}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{160AE11E-138A-4B77-9642-EA74F9A79B4D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{160AE11E-138A-4B77-9642-EA74F9A79B4D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{160AE11E-138A-4B77-9642-EA74F9A79B4D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{160AE11E-138A-4B77-9642-EA74F9A79B4D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9D4738F7-34EA-433A-A765-AF85A52A174D}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{16E177F3-A0FF-4091-8521-562E0EBAA3AB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{16E177F3-A0FF-4091-8521-562E0EBAA3AB}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{16E177F3-A0FF-4091-8521-562E0EBAA3AB}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{16E177F3-A0FF-4091-8521-562E0EBAA3AB}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{F2F48990-F81E-41BA-AD01-168F6178C807}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{F2F48990-F81E-41BA-AD01-168F6178C807}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{F2F48990-F81E-41BA-AD01-168F6178C807}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{F2F48990-F81E-41BA-AD01-168F6178C807}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
BIN
dotnet/extlibs/csfml-audio.dll
Normal file
BIN
dotnet/extlibs/csfml-audio.dll
Normal file
Binary file not shown.
BIN
dotnet/extlibs/csfml-graphics.dll
Normal file
BIN
dotnet/extlibs/csfml-graphics.dll
Normal file
Binary file not shown.
BIN
dotnet/extlibs/csfml-window.dll
Normal file
BIN
dotnet/extlibs/csfml-window.dll
Normal file
Binary file not shown.
BIN
dotnet/extlibs/libsndfile-1.dll
Normal file
BIN
dotnet/extlibs/libsndfile-1.dll
Normal file
Binary file not shown.
BIN
dotnet/extlibs/openal32.dll
Normal file
BIN
dotnet/extlibs/openal32.dll
Normal file
Binary file not shown.
BIN
dotnet/samples/bin/datas/opengl/background.jpg
Normal file
BIN
dotnet/samples/bin/datas/opengl/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 130 KiB |
BIN
dotnet/samples/bin/datas/opengl/texture.jpg
Normal file
BIN
dotnet/samples/bin/datas/opengl/texture.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 5.8 KiB |
BIN
dotnet/samples/bin/datas/post-fx/background.jpg
Normal file
BIN
dotnet/samples/bin/datas/post-fx/background.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 154 KiB |
16
dotnet/samples/bin/datas/post-fx/blur.sfx
Normal file
16
dotnet/samples/bin/datas/post-fx/blur.sfx
Normal file
|
@ -0,0 +1,16 @@
|
|||
texture framebuffer
|
||||
float offset
|
||||
|
||||
effect
|
||||
{
|
||||
vec2 offx = vec2(offset, 0.0);
|
||||
vec2 offy = vec2(0.0, offset);
|
||||
|
||||
vec4 c0 = framebuffer(_in);
|
||||
vec4 c1 = framebuffer(_in - offy);
|
||||
vec4 c2 = framebuffer(_in + offy);
|
||||
vec4 c3 = framebuffer(_in - offx);
|
||||
vec4 c4 = framebuffer(_in + offx);
|
||||
|
||||
_out = c0 * 0.2 + c1 * 0.2 + c2 * 0.2 + c3 * 0.2 + c4 * 0.2;
|
||||
}
|
BIN
dotnet/samples/bin/datas/post-fx/cheeseburger.ttf
Normal file
BIN
dotnet/samples/bin/datas/post-fx/cheeseburger.ttf
Normal file
Binary file not shown.
10
dotnet/samples/bin/datas/post-fx/colorize.sfx
Normal file
10
dotnet/samples/bin/datas/post-fx/colorize.sfx
Normal file
|
@ -0,0 +1,10 @@
|
|||
texture framebuffer
|
||||
vec3 color
|
||||
|
||||
effect
|
||||
{
|
||||
vec4 pixel = framebuffer(_in);
|
||||
float gray = pixel.r * 0.39 + pixel.g * 0.50 + pixel.b * 0.11;
|
||||
|
||||
_out = vec4(gray * color, 1.0) * 0.6 + pixel * 0.4;
|
||||
}
|
12
dotnet/samples/bin/datas/post-fx/fisheye.sfx
Normal file
12
dotnet/samples/bin/datas/post-fx/fisheye.sfx
Normal file
|
@ -0,0 +1,12 @@
|
|||
texture framebuffer
|
||||
vec2 mouse
|
||||
|
||||
effect
|
||||
{
|
||||
float len = distance(_in, mouse) * 7.0;
|
||||
|
||||
if (len < 1.0)
|
||||
_out = framebuffer(_in + (_in - mouse) * len);
|
||||
else
|
||||
_out = framebuffer(_in);
|
||||
}
|
6
dotnet/samples/bin/datas/post-fx/nothing.sfx
Normal file
6
dotnet/samples/bin/datas/post-fx/nothing.sfx
Normal file
|
@ -0,0 +1,6 @@
|
|||
texture framebuffer
|
||||
|
||||
effect
|
||||
{
|
||||
_out = framebuffer(_in);
|
||||
}
|
BIN
dotnet/samples/bin/datas/post-fx/wave.jpg
Normal file
BIN
dotnet/samples/bin/datas/post-fx/wave.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 23 KiB |
12
dotnet/samples/bin/datas/post-fx/wave.sfx
Normal file
12
dotnet/samples/bin/datas/post-fx/wave.sfx
Normal file
|
@ -0,0 +1,12 @@
|
|||
texture framebuffer
|
||||
texture wave
|
||||
vec2 offset
|
||||
|
||||
effect
|
||||
{
|
||||
vec2 texoffset = wave(_in * offset).xy;
|
||||
texoffset -= vec2(0.5, 0.5);
|
||||
texoffset *= 0.05;
|
||||
|
||||
_out = framebuffer(_in + texoffset);
|
||||
}
|
BIN
dotnet/samples/bin/datas/sound/footsteps.wav
Normal file
BIN
dotnet/samples/bin/datas/sound/footsteps.wav
Normal file
Binary file not shown.
BIN
dotnet/samples/bin/datas/sound/lepidoptera.ogg
Normal file
BIN
dotnet/samples/bin/datas/sound/lepidoptera.ogg
Normal file
Binary file not shown.
161
dotnet/samples/opengl/OpenGL.cs
Normal file
161
dotnet/samples/opengl/OpenGL.cs
Normal file
|
@ -0,0 +1,161 @@
|
|||
using System;
|
||||
using SFML;
|
||||
using SFML.Graphics;
|
||||
using SFML.Window;
|
||||
using Tao.OpenGl;
|
||||
|
||||
namespace sample_opengl
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main()
|
||||
{
|
||||
// Create main window
|
||||
RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net OpenGL");
|
||||
App.PreserveOpenGLStates(true);
|
||||
|
||||
// Setup event handlers
|
||||
App.Closed += new EventHandler(OnClosed);
|
||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
App.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||
|
||||
// Create a sprite for the background
|
||||
Image BackgroundImage = new Image("datas/opengl/background.jpg");
|
||||
Sprite Background = new Sprite(BackgroundImage);
|
||||
|
||||
// Create a text to display
|
||||
String2D Text = new String2D("This is a rotating cube");
|
||||
Text.Position = new Vector2(250.0F, 300.0F);
|
||||
Text.Color = new Color(128, 0, 128);
|
||||
|
||||
// Load an OpenGL texture.
|
||||
// We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
|
||||
// but here we want more control on it (generate mipmaps, ...) so we create a new one
|
||||
int Texture = 0;
|
||||
using (Image TempImage = new Image("datas/opengl/texture.jpg"))
|
||||
{
|
||||
Gl.glGenTextures(1, out Texture);
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture);
|
||||
Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, (int)TempImage.Width, (int)TempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels);
|
||||
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR);
|
||||
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR);
|
||||
}
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
Gl.glEnable(Gl.GL_DEPTH_TEST);
|
||||
Gl.glDepthMask(Gl.GL_TRUE);
|
||||
Gl.glClearDepth(1.0F);
|
||||
|
||||
// Setup a perspective projection
|
||||
Gl.glMatrixMode(Gl.GL_PROJECTION);
|
||||
Gl.glLoadIdentity();
|
||||
Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);
|
||||
|
||||
// Bind our texture
|
||||
Gl.glEnable(Gl.GL_TEXTURE_2D);
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture);
|
||||
Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
float Time = 0.0F;
|
||||
|
||||
// Start game loop
|
||||
while (App.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
|
||||
// Draw background
|
||||
App.Draw(Background);
|
||||
|
||||
// Clear depth buffer
|
||||
Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Apply some transformations
|
||||
Time += App.GetFrameTime();
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||
Gl.glLoadIdentity();
|
||||
Gl.glTranslatef(0.0F, 0.0F, -200.0F);
|
||||
Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F);
|
||||
Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F);
|
||||
Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F);
|
||||
|
||||
// Draw a cube
|
||||
Gl.glBegin(Gl.GL_QUADS);
|
||||
|
||||
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, 50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, -50.0F);
|
||||
|
||||
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
|
||||
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
|
||||
Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, 50.0F, 50.0F);
|
||||
Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
|
||||
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(50.0F, -50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(50.0F, 50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 1); Gl.glVertex3f(50.0F, 50.0F, 50.0F);
|
||||
Gl.glTexCoord2f(1, 0); Gl.glVertex3f(50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
|
||||
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, -50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glTexCoord2f(0, 1); Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
|
||||
Gl.glTexCoord2f(0, 0); Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 0); Gl.glVertex3f( 50.0F, 50.0F, -50.0F);
|
||||
Gl.glTexCoord2f(1, 1); Gl.glVertex3f( 50.0F, 50.0F, 50.0F);
|
||||
|
||||
Gl.glEnd();
|
||||
|
||||
// Draw some text on top of our OpenGL object
|
||||
App.Draw(Text);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
}
|
||||
|
||||
// Don't forget to destroy our texture
|
||||
Gl.glDeleteTextures(1, ref Texture);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when the window is closed
|
||||
/// </summary>
|
||||
static void OnClosed(object sender, EventArgs e)
|
||||
{
|
||||
RenderWindow window = (RenderWindow)sender;
|
||||
window.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when a key is pressed
|
||||
/// </summary>
|
||||
static void OnKeyPressed(object sender, KeyEventArgs e)
|
||||
{
|
||||
RenderWindow window = (RenderWindow)sender;
|
||||
if (e.Code == KeyCode.Escape)
|
||||
window.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when the window is resized
|
||||
/// </summary>
|
||||
static void OnResized(object sender, SizeEventArgs e)
|
||||
{
|
||||
Gl.glViewport(0, 0, (int)e.Width, (int)e.Height);
|
||||
}
|
||||
}
|
||||
}
|
66
dotnet/samples/opengl/sample-opengl.csproj
Normal file
66
dotnet/samples/opengl/sample-opengl.csproj
Normal file
|
@ -0,0 +1,66 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{160AE11E-138A-4B77-9642-EA74F9A79B4D}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>sample_opengl</RootNamespace>
|
||||
<AssemblyName>opengl</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Graphics\sfml-graphics.csproj">
|
||||
<Project>{46786269-57B9-48E7-AA4F-8F4D84609FE6}</Project>
|
||||
<Name>sfml-graphics</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="OpenGL.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Tao.FreeGlut, Version=2.4.0.2, Culture=neutral, PublicKeyToken=6e602a6ad6c0d06d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.FreeGlut.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.OpenGl.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
168
dotnet/samples/post-fx/PostFx.cs
Normal file
168
dotnet/samples/post-fx/PostFx.cs
Normal file
|
@ -0,0 +1,168 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SFML;
|
||||
using SFML.Graphics;
|
||||
using SFML.Window;
|
||||
|
||||
namespace sample_postfx
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
private static Dictionary<string, PostFx> Effects;
|
||||
private static Dictionary<string, PostFx>.Enumerator CurrentEffect;
|
||||
private static String2D CurFXStr;
|
||||
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main()
|
||||
{
|
||||
// Create the main window
|
||||
RenderWindow App = new RenderWindow(new VideoMode(800, 600), "SFML.Net PostFX");
|
||||
|
||||
// Setup event handlers
|
||||
App.Closed += new EventHandler(OnClosed);
|
||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
|
||||
// Check that the system can use post effects
|
||||
if (PostFx.CanUsePostFX == false)
|
||||
{
|
||||
DisplayError(App);
|
||||
return;
|
||||
}
|
||||
|
||||
// Load a cute background image to display :)
|
||||
Sprite Background = new Sprite(new Image("datas/post-fx/background.jpg"));
|
||||
|
||||
// Load the text font
|
||||
Font Cheeseburger = new Font("datas/post-fx/cheeseburger.ttf");
|
||||
|
||||
// Load the image needed for the wave effect
|
||||
Image WaveImage = new Image("datas/post-fx/wave.jpg");
|
||||
|
||||
// Load all effects
|
||||
Effects = new Dictionary<string, PostFx>();
|
||||
Effects["nothing"] = new PostFx("datas/post-fx/nothing.sfx");
|
||||
Effects["blur"] = new PostFx("datas/post-fx/blur.sfx");
|
||||
Effects["colorize"] = new PostFx("datas/post-fx/colorize.sfx");
|
||||
Effects["fisheye"] = new PostFx("datas/post-fx/fisheye.sfx");
|
||||
Effects["wave"] = new PostFx("datas/post-fx/wave.sfx");
|
||||
CurrentEffect = Effects.GetEnumerator();
|
||||
CurrentEffect.MoveNext();
|
||||
|
||||
// Do specific initializations
|
||||
Effects["nothing"].SetTexture("framebuffer", null);
|
||||
Effects["blur"].SetTexture("framebuffer", null);
|
||||
Effects["blur"].SetParameter("offset", 0.0F);
|
||||
Effects["colorize"].SetTexture("framebuffer", null);
|
||||
Effects["colorize"].SetParameter("color", 1.0F, 1.0F, 1.0F);
|
||||
Effects["fisheye"].SetTexture("framebuffer", null);
|
||||
Effects["wave"].SetTexture("framebuffer", null);
|
||||
Effects["wave"].SetTexture("wave", WaveImage);
|
||||
|
||||
// Define a string for displaying current effect description
|
||||
CurFXStr = new String2D();
|
||||
CurFXStr.Text = "Current effect is \"" + CurrentEffect.Current.Key + "\"";
|
||||
CurFXStr.Font = Cheeseburger;
|
||||
CurFXStr.Position = new Vector2(20.0F, 0.0F);
|
||||
|
||||
// Define a string for displaying help
|
||||
String2D InfoStr = new String2D();
|
||||
InfoStr.Text = "Move your mouse to change the effect parameters\nPress numpad + to change effect\nWarning : some effects may not work\ndepending on your graphics card";
|
||||
InfoStr.Font = Cheeseburger;
|
||||
InfoStr.Position = new Vector2(20.0F, 460.0F);
|
||||
InfoStr.Color = new Color(200, 100, 150);
|
||||
|
||||
// Start the game loop
|
||||
while (App.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
|
||||
// Get the mouse position in the range [0, 1]
|
||||
float X = App.Input.GetMouseX() / (float)App.Width;
|
||||
float Y = App.Input.GetMouseY() / (float)App.Height;
|
||||
|
||||
// Update the current effect
|
||||
if (CurrentEffect.Current.Key == "blur") CurrentEffect.Current.Value.SetParameter("offset", X * Y * 0.1f);
|
||||
else if (CurrentEffect.Current.Key == "colorize") CurrentEffect.Current.Value.SetParameter("color", 0.3f, X, Y);
|
||||
else if (CurrentEffect.Current.Key == "fisheye") CurrentEffect.Current.Value.SetParameter("mouse", X, 1.0F - Y);
|
||||
else if (CurrentEffect.Current.Key == "wave") CurrentEffect.Current.Value.SetParameter("offset", X, Y);
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
|
||||
// Draw background and apply the post-fx
|
||||
App.Draw(Background);
|
||||
App.Draw(CurrentEffect.Current.Value);
|
||||
|
||||
// Draw interface strings
|
||||
App.Draw(CurFXStr);
|
||||
App.Draw(InfoStr);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fonction called when the post-effects are not supported ;
|
||||
/// Display an error message and wait until the user exits
|
||||
/// </summary>
|
||||
private static void DisplayError(RenderWindow App)
|
||||
{
|
||||
// Define a string for displaying the error message
|
||||
String2D ErrorStr = new String2D("Sorry, your system doesn't support post-effects");
|
||||
ErrorStr.Position = new Vector2(100.0F, 250.0F);
|
||||
ErrorStr.Color = new Color(200, 100, 150);
|
||||
|
||||
// Start the game loop
|
||||
while (App.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
|
||||
// Clear the window
|
||||
App.Clear();
|
||||
|
||||
// Draw the error message
|
||||
App.Draw(ErrorStr);
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when the window is closed
|
||||
/// </summary>
|
||||
static void OnClosed(object sender, EventArgs e)
|
||||
{
|
||||
RenderWindow window = (RenderWindow)sender;
|
||||
window.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when a key is pressed
|
||||
/// </summary>
|
||||
static void OnKeyPressed(object sender, KeyEventArgs e)
|
||||
{
|
||||
RenderWindow window = (RenderWindow)sender;
|
||||
if (e.Code == KeyCode.Escape)
|
||||
{
|
||||
// Close the window
|
||||
window.Close();
|
||||
}
|
||||
else if (e.Code == KeyCode.Add)
|
||||
{
|
||||
// Advance to the next effect
|
||||
if (CurrentEffect.MoveNext() == false)
|
||||
{
|
||||
CurrentEffect = Effects.GetEnumerator();
|
||||
CurrentEffect.MoveNext();
|
||||
}
|
||||
CurFXStr.Text = "Current effect is \"" + CurrentEffect.Current.Key + "\"";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
54
dotnet/samples/post-fx/sample-postfx.csproj
Normal file
54
dotnet/samples/post-fx/sample-postfx.csproj
Normal file
|
@ -0,0 +1,54 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9D4738F7-34EA-433A-A765-AF85A52A174D}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>sample_postfx</RootNamespace>
|
||||
<AssemblyName>post-fx</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Graphics\sfml-graphics.csproj">
|
||||
<Project>{46786269-57B9-48E7-AA4F-8F4D84609FE6}</Project>
|
||||
<Name>sfml-graphics</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="PostFx.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
82
dotnet/samples/sound/Sound.cs
Normal file
82
dotnet/samples/sound/Sound.cs
Normal file
|
@ -0,0 +1,82 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using SFML;
|
||||
using SFML.Audio;
|
||||
|
||||
namespace sample_sound
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Play a sound
|
||||
PlaySound();
|
||||
Console.Clear();
|
||||
|
||||
// Play a music
|
||||
PlayMusic();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play a sound
|
||||
/// </summary>
|
||||
private static void PlaySound()
|
||||
{
|
||||
// Load a sound buffer from a wav file
|
||||
SoundBuffer Buffer = new SoundBuffer("datas/sound/footsteps.wav");
|
||||
|
||||
// Display sound informations
|
||||
Console.WriteLine("footsteps.wav :");
|
||||
Console.WriteLine(" " + Buffer.Duration + " sec");
|
||||
Console.WriteLine(" " + Buffer.SampleRate + " samples / sec");
|
||||
Console.WriteLine(" " + Buffer.ChannelsCount + " channels");
|
||||
|
||||
// Create a sound instance and play it
|
||||
Sound Sound = new Sound(Buffer);
|
||||
Sound.Play();
|
||||
|
||||
// Loop while the sound is playing
|
||||
while (Sound.Status == SoundStatus.Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
Console.CursorLeft = 0;
|
||||
Console.Write("Playing... " + Sound.PlayingOffset + " sec ");
|
||||
|
||||
// Leave some CPU time for other processes
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Play a music
|
||||
/// </summary>
|
||||
private static void PlayMusic()
|
||||
{
|
||||
// Load an ogg music file
|
||||
Music Music = new Music("datas/sound/lepidoptera.ogg");
|
||||
|
||||
// Display music informations
|
||||
Console.WriteLine("lepidoptera.ogg :");
|
||||
Console.WriteLine(" " + Music.Duration + " sec");
|
||||
Console.WriteLine(" " + Music.SampleRate + " samples / sec");
|
||||
Console.WriteLine(" " + Music.ChannelsCount + " channels");
|
||||
|
||||
// Play it
|
||||
Music.Play();
|
||||
|
||||
// Loop while the music is playing
|
||||
while (Music.Status == SoundStatus.Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
Console.CursorLeft = 0;
|
||||
Console.Write("Playing... " + Music.PlayingOffset + " sec ");
|
||||
|
||||
// Leave some CPU time for other processes
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
56
dotnet/samples/sound/sample-sound.csproj
Normal file
56
dotnet/samples/sound/sample-sound.csproj
Normal file
|
@ -0,0 +1,56 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{16E177F3-A0FF-4091-8521-562E0EBAA3AB}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>sample_sound</RootNamespace>
|
||||
<AssemblyName>sound</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Audio\sfml-audio.csproj">
|
||||
<Project>{0B202C4D-A457-47FE-84A3-031DD878C6BE}</Project>
|
||||
<Name>sfml-audio</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Sound.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
83
dotnet/samples/sound_capture/SoundCapture.cs
Normal file
83
dotnet/samples/sound_capture/SoundCapture.cs
Normal file
|
@ -0,0 +1,83 @@
|
|||
using System;
|
||||
using System.Threading;
|
||||
using SFML;
|
||||
using SFML.Audio;
|
||||
|
||||
namespace sample_soundcapture
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main(string[] args)
|
||||
{
|
||||
// Check that the device can capture audio
|
||||
if (SoundRecorder.CanCapture == false)
|
||||
{
|
||||
Console.WriteLine("Sorry, audio capture is not supported by your system");
|
||||
return;
|
||||
}
|
||||
|
||||
// Choose the sample rate
|
||||
Console.WriteLine("Please choose the sample rate for sound capture (44100 is CD quality) : ");
|
||||
uint SampleRate = uint.Parse(Console.ReadLine());
|
||||
|
||||
// Wait for user input...
|
||||
Console.WriteLine("Press enter to start recording audio");
|
||||
Console.ReadLine();
|
||||
|
||||
// Here we'll use an integrated custom recorder, which saves the captured data into a SoundBuffer
|
||||
SoundBufferRecorder Recorder = new SoundBufferRecorder();
|
||||
|
||||
// Audio capture is done in a separate thread, so we can block the main thread while it is capturing
|
||||
Recorder.Start(SampleRate);
|
||||
Console.WriteLine("Recording... press enter to stop");
|
||||
Console.ReadLine();
|
||||
Recorder.Stop();
|
||||
|
||||
// Get the buffer containing the captured data
|
||||
SoundBuffer Buffer = Recorder.SoundBuffer;
|
||||
|
||||
// Display captured sound informations
|
||||
Console.WriteLine("Sound information :");
|
||||
Console.WriteLine(" " + Buffer.Duration + " seconds");
|
||||
Console.WriteLine(" " + Buffer.SampleRate + " samples / seconds");
|
||||
Console.WriteLine(" " + Buffer.ChannelsCount + " channels");
|
||||
|
||||
// Choose what to do with the recorded sound data
|
||||
Console.WriteLine("What do you want to do with captured sound (p = play, s = save) ? ");
|
||||
char Choice = char.Parse(Console.ReadLine());
|
||||
|
||||
if (Choice == 's')
|
||||
{
|
||||
// Choose the filename
|
||||
Console.WriteLine("Choose the file to create : ");
|
||||
string Filename = Console.ReadLine();
|
||||
|
||||
// Save the buffer
|
||||
Buffer.SaveToFile(Filename);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Create a sound instance and play it
|
||||
Sound Sound = new Sound(Buffer);
|
||||
Sound.Play();
|
||||
|
||||
// Wait until finished
|
||||
while (Sound.Status == SoundStatus.Playing)
|
||||
{
|
||||
// Display the playing position
|
||||
Console.CursorLeft = 0;
|
||||
Console.Write("Playing... " + Sound.PlayingOffset + " sec ");
|
||||
|
||||
// Leave some CPU time for other threads
|
||||
Thread.Sleep(100);
|
||||
}
|
||||
}
|
||||
|
||||
// Finished !
|
||||
Console.WriteLine("\nDone !");
|
||||
}
|
||||
}
|
||||
}
|
56
dotnet/samples/sound_capture/sample-soundcapture.csproj
Normal file
56
dotnet/samples/sound_capture/sample-soundcapture.csproj
Normal file
|
@ -0,0 +1,56 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{F2F48990-F81E-41BA-AD01-168F6178C807}</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>sample_soundcapture</RootNamespace>
|
||||
<AssemblyName>sound-capture</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Audio\sfml-audio.csproj">
|
||||
<Project>{0B202C4D-A457-47FE-84A3-031DD878C6BE}</Project>
|
||||
<Name>sfml-audio</Name>
|
||||
</ProjectReference>
|
||||
<ProjectReference Include="..\..\src\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="SoundCapture.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
13
dotnet/samples/visualbasic/My Project/Application.Designer.vb
generated
Normal file
13
dotnet/samples/visualbasic/My Project/Application.Designer.vb
generated
Normal file
|
@ -0,0 +1,13 @@
|
|||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' This code was generated by a tool.
|
||||
' Runtime Version:2.0.50727.3053
|
||||
'
|
||||
' Changes to this file may cause incorrect behavior and will be lost if
|
||||
' the code is regenerated.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
10
dotnet/samples/visualbasic/My Project/Application.myapp
Normal file
10
dotnet/samples/visualbasic/My Project/Application.myapp
Normal file
|
@ -0,0 +1,10 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<MyApplicationData xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
|
||||
<MySubMain>false</MySubMain>
|
||||
<SingleInstance>false</SingleInstance>
|
||||
<ShutdownMode>0</ShutdownMode>
|
||||
<EnableVisualStyles>true</EnableVisualStyles>
|
||||
<AuthenticationMode>0</AuthenticationMode>
|
||||
<ApplicationType>2</ApplicationType>
|
||||
<SaveMySettingsOnExit>true</SaveMySettingsOnExit>
|
||||
</MyApplicationData>
|
35
dotnet/samples/visualbasic/My Project/AssemblyInfo.vb
Normal file
35
dotnet/samples/visualbasic/My Project/AssemblyInfo.vb
Normal file
|
@ -0,0 +1,35 @@
|
|||
Imports System
|
||||
Imports System.Reflection
|
||||
Imports System.Runtime.InteropServices
|
||||
|
||||
' General Information about an assembly is controlled through the following
|
||||
' set of attributes. Change these attribute values to modify the information
|
||||
' associated with an assembly.
|
||||
|
||||
' Review the values of the assembly attributes
|
||||
|
||||
<Assembly: AssemblyTitle("visualbasic")>
|
||||
<Assembly: AssemblyDescription("")>
|
||||
<Assembly: AssemblyCompany("Wam")>
|
||||
<Assembly: AssemblyProduct("visualbasic")>
|
||||
<Assembly: AssemblyCopyright("Copyright © Wam 2008")>
|
||||
<Assembly: AssemblyTrademark("")>
|
||||
|
||||
<Assembly: ComVisible(False)>
|
||||
|
||||
'The following GUID is for the ID of the typelib if this project is exposed to COM
|
||||
<Assembly: Guid("6694830f-34ec-4c32-b1c8-895dbbf41593")>
|
||||
|
||||
' Version information for an assembly consists of the following four values:
|
||||
'
|
||||
' Major Version
|
||||
' Minor Version
|
||||
' Build Number
|
||||
' Revision
|
||||
'
|
||||
' You can specify all the values or you can default the Build and Revision Numbers
|
||||
' by using the '*' as shown below:
|
||||
' <Assembly: AssemblyVersion("1.0.*")>
|
||||
|
||||
<Assembly: AssemblyVersion("1.0.0.0")>
|
||||
<Assembly: AssemblyFileVersion("1.0.0.0")>
|
63
dotnet/samples/visualbasic/My Project/Resources.Designer.vb
generated
Normal file
63
dotnet/samples/visualbasic/My Project/Resources.Designer.vb
generated
Normal file
|
@ -0,0 +1,63 @@
|
|||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' This code was generated by a tool.
|
||||
' Runtime Version:2.0.50727.3053
|
||||
'
|
||||
' Changes to this file may cause incorrect behavior and will be lost if
|
||||
' the code is regenerated.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
Imports System
|
||||
|
||||
Namespace My.Resources
|
||||
|
||||
'This class was auto-generated by the StronglyTypedResourceBuilder
|
||||
'class via a tool like ResGen or Visual Studio.
|
||||
'To add or remove a member, edit your .ResX file then rerun ResGen
|
||||
'with the /str option, or rebuild your VS project.
|
||||
'''<summary>
|
||||
''' A strongly-typed resource class, for looking up localized strings, etc.
|
||||
'''</summary>
|
||||
<Global.System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0"), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.Microsoft.VisualBasic.HideModuleNameAttribute()> _
|
||||
Friend Module Resources
|
||||
|
||||
Private resourceMan As Global.System.Resources.ResourceManager
|
||||
|
||||
Private resourceCulture As Global.System.Globalization.CultureInfo
|
||||
|
||||
'''<summary>
|
||||
''' Returns the cached ResourceManager instance used by this class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend ReadOnly Property ResourceManager() As Global.System.Resources.ResourceManager
|
||||
Get
|
||||
If Object.ReferenceEquals(resourceMan, Nothing) Then
|
||||
Dim temp As Global.System.Resources.ResourceManager = New Global.System.Resources.ResourceManager("visualbasic.Resources", GetType(Resources).Assembly)
|
||||
resourceMan = temp
|
||||
End If
|
||||
Return resourceMan
|
||||
End Get
|
||||
End Property
|
||||
|
||||
'''<summary>
|
||||
''' Overrides the current thread's CurrentUICulture property for all
|
||||
''' resource lookups using this strongly typed resource class.
|
||||
'''</summary>
|
||||
<Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Friend Property Culture() As Global.System.Globalization.CultureInfo
|
||||
Get
|
||||
Return resourceCulture
|
||||
End Get
|
||||
Set
|
||||
resourceCulture = value
|
||||
End Set
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
117
dotnet/samples/visualbasic/My Project/Resources.resx
Normal file
117
dotnet/samples/visualbasic/My Project/Resources.resx
Normal file
|
@ -0,0 +1,117 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<root>
|
||||
<!--
|
||||
Microsoft ResX Schema
|
||||
|
||||
Version 2.0
|
||||
|
||||
The primary goals of this format is to allow a simple XML format
|
||||
that is mostly human readable. The generation and parsing of the
|
||||
various data types are done through the TypeConverter classes
|
||||
associated with the data types.
|
||||
|
||||
Example:
|
||||
|
||||
... ado.net/XML headers & schema ...
|
||||
<resheader name="resmimetype">text/microsoft-resx</resheader>
|
||||
<resheader name="version">2.0</resheader>
|
||||
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
|
||||
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
|
||||
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
|
||||
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
|
||||
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
|
||||
<value>[base64 mime encoded serialized .NET Framework object]</value>
|
||||
</data>
|
||||
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
|
||||
<comment>This is a comment</comment>
|
||||
</data>
|
||||
|
||||
There are any number of "resheader" rows that contain simple
|
||||
name/value pairs.
|
||||
|
||||
Each data row contains a name, and value. The row also contains a
|
||||
type or mimetype. Type corresponds to a .NET class that support
|
||||
text/value conversion through the TypeConverter architecture.
|
||||
Classes that don't support this are serialized and stored with the
|
||||
mimetype set.
|
||||
|
||||
The mimetype is used for serialized objects, and tells the
|
||||
ResXResourceReader how to depersist the object. This is currently not
|
||||
extensible. For a given mimetype the value must be set accordingly:
|
||||
|
||||
Note - application/x-microsoft.net.object.binary.base64 is the format
|
||||
that the ResXResourceWriter will generate, however the reader can
|
||||
read any of the formats listed below.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.binary.base64
|
||||
value : The object must be serialized with
|
||||
: System.Serialization.Formatters.Binary.BinaryFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.soap.base64
|
||||
value : The object must be serialized with
|
||||
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
|
||||
: and then encoded with base64 encoding.
|
||||
|
||||
mimetype: application/x-microsoft.net.object.bytearray.base64
|
||||
value : The object must be serialized into a byte array
|
||||
: using a System.ComponentModel.TypeConverter
|
||||
: and then encoded with base64 encoding.
|
||||
-->
|
||||
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
|
||||
<xsd:element name="root" msdata:IsDataSet="true">
|
||||
<xsd:complexType>
|
||||
<xsd:choice maxOccurs="unbounded">
|
||||
<xsd:element name="metadata">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
<xsd:attribute name="type" type="xsd:string" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="assembly">
|
||||
<xsd:complexType>
|
||||
<xsd:attribute name="alias" type="xsd:string" />
|
||||
<xsd:attribute name="name" type="xsd:string" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="data">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" msdata:Ordinal="1" />
|
||||
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
|
||||
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
<xsd:element name="resheader">
|
||||
<xsd:complexType>
|
||||
<xsd:sequence>
|
||||
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
|
||||
</xsd:sequence>
|
||||
<xsd:attribute name="name" type="xsd:string" use="required" />
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:choice>
|
||||
</xsd:complexType>
|
||||
</xsd:element>
|
||||
</xsd:schema>
|
||||
<resheader name="resmimetype">
|
||||
<value>text/microsoft-resx</value>
|
||||
</resheader>
|
||||
<resheader name="version">
|
||||
<value>2.0</value>
|
||||
</resheader>
|
||||
<resheader name="reader">
|
||||
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
</root>
|
73
dotnet/samples/visualbasic/My Project/Settings.Designer.vb
generated
Normal file
73
dotnet/samples/visualbasic/My Project/Settings.Designer.vb
generated
Normal file
|
@ -0,0 +1,73 @@
|
|||
'------------------------------------------------------------------------------
|
||||
' <auto-generated>
|
||||
' This code was generated by a tool.
|
||||
' Runtime Version:2.0.50727.3053
|
||||
'
|
||||
' Changes to this file may cause incorrect behavior and will be lost if
|
||||
' the code is regenerated.
|
||||
' </auto-generated>
|
||||
'------------------------------------------------------------------------------
|
||||
|
||||
Option Strict On
|
||||
Option Explicit On
|
||||
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute(), _
|
||||
Global.System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "9.0.0.0"), _
|
||||
Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Partial Friend NotInheritable Class MySettings
|
||||
Inherits Global.System.Configuration.ApplicationSettingsBase
|
||||
|
||||
Private Shared defaultInstance As MySettings = CType(Global.System.Configuration.ApplicationSettingsBase.Synchronized(New MySettings),MySettings)
|
||||
|
||||
#Region "My.Settings Auto-Save Functionality"
|
||||
#If _MyType = "WindowsForms" Then
|
||||
Private Shared addedHandler As Boolean
|
||||
|
||||
Private Shared addedHandlerLockObject As New Object
|
||||
|
||||
<Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), Global.System.ComponentModel.EditorBrowsableAttribute(Global.System.ComponentModel.EditorBrowsableState.Advanced)> _
|
||||
Private Shared Sub AutoSaveSettings(ByVal sender As Global.System.Object, ByVal e As Global.System.EventArgs)
|
||||
If My.Application.SaveMySettingsOnExit Then
|
||||
My.Settings.Save()
|
||||
End If
|
||||
End Sub
|
||||
#End If
|
||||
#End Region
|
||||
|
||||
Public Shared ReadOnly Property [Default]() As MySettings
|
||||
Get
|
||||
|
||||
#If _MyType = "WindowsForms" Then
|
||||
If Not addedHandler Then
|
||||
SyncLock addedHandlerLockObject
|
||||
If Not addedHandler Then
|
||||
AddHandler My.Application.Shutdown, AddressOf AutoSaveSettings
|
||||
addedHandler = True
|
||||
End If
|
||||
End SyncLock
|
||||
End If
|
||||
#End If
|
||||
Return defaultInstance
|
||||
End Get
|
||||
End Property
|
||||
End Class
|
||||
End Namespace
|
||||
|
||||
Namespace My
|
||||
|
||||
<Global.Microsoft.VisualBasic.HideModuleNameAttribute(), _
|
||||
Global.System.Diagnostics.DebuggerNonUserCodeAttribute(), _
|
||||
Global.System.Runtime.CompilerServices.CompilerGeneratedAttribute()> _
|
||||
Friend Module MySettingsProperty
|
||||
|
||||
<Global.System.ComponentModel.Design.HelpKeywordAttribute("My.Settings")> _
|
||||
Friend ReadOnly Property Settings() As Global.visualbasic.My.MySettings
|
||||
Get
|
||||
Return Global.visualbasic.My.MySettings.Default
|
||||
End Get
|
||||
End Property
|
||||
End Module
|
||||
End Namespace
|
7
dotnet/samples/visualbasic/My Project/Settings.settings
Normal file
7
dotnet/samples/visualbasic/My Project/Settings.settings
Normal file
|
@ -0,0 +1,7 @@
|
|||
<?xml version='1.0' encoding='utf-8'?>
|
||||
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)" UseMySettingsClassName="true">
|
||||
<Profiles>
|
||||
<Profile Name="(Default)" />
|
||||
</Profiles>
|
||||
<Settings />
|
||||
</SettingsFile>
|
177
dotnet/samples/visualbasic/OpenGL.vb
Normal file
177
dotnet/samples/visualbasic/OpenGL.vb
Normal file
|
@ -0,0 +1,177 @@
|
|||
Imports SFML
|
||||
Imports SFML.Window
|
||||
Imports SFML.Graphics
|
||||
Imports Tao.OpenGl
|
||||
Imports Tao.FreeGlut
|
||||
|
||||
|
||||
Module OpenGL
|
||||
|
||||
Dim WithEvents App As RenderWindow
|
||||
|
||||
''' <summary>
|
||||
''' Entry point of application
|
||||
''' </summary>
|
||||
Sub Main()
|
||||
|
||||
' Create main window
|
||||
App = New RenderWindow(New VideoMode(800, 600), "SFML.Net OpenGL (Visual Basic)")
|
||||
App.PreserveOpenGLStates(True)
|
||||
|
||||
' Create a sprite for the background
|
||||
Dim BackgroundImage = New Image("datas/opengl/background.jpg")
|
||||
Dim Background = New Sprite(BackgroundImage)
|
||||
|
||||
' Create a text to display
|
||||
Dim Text = New String2D("This is a rotating cube")
|
||||
Text.Position = New Vector2(250.0F, 300.0F)
|
||||
Text.Color = New Color(128, 0, 128)
|
||||
|
||||
' Load an OpenGL texture.
|
||||
' We could directly use a sf::Image as an OpenGL texture (with its Bind() member function),
|
||||
' but here we want more control on it (generate mipmaps, ...) so we create a new one
|
||||
Dim Texture = 0
|
||||
Using TempImage = New Image("datas/opengl/texture.jpg")
|
||||
Gl.glGenTextures(1, Texture)
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture)
|
||||
Glu.gluBuild2DMipmaps(Gl.GL_TEXTURE_2D, Gl.GL_RGBA, TempImage.Width, TempImage.Height, Gl.GL_RGBA, Gl.GL_UNSIGNED_BYTE, TempImage.Pixels)
|
||||
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MAG_FILTER, Gl.GL_LINEAR)
|
||||
Gl.glTexParameteri(Gl.GL_TEXTURE_2D, Gl.GL_TEXTURE_MIN_FILTER, Gl.GL_LINEAR_MIPMAP_LINEAR)
|
||||
End Using
|
||||
|
||||
' Enable Z-buffer read and write
|
||||
Gl.glEnable(Gl.GL_DEPTH_TEST)
|
||||
Gl.glDepthMask(Gl.GL_TRUE)
|
||||
Gl.glClearDepth(1.0F)
|
||||
|
||||
' Setup a perspective projection
|
||||
Gl.glMatrixMode(Gl.GL_PROJECTION)
|
||||
Gl.glLoadIdentity()
|
||||
Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F)
|
||||
|
||||
' Bind our texture
|
||||
Gl.glEnable(Gl.GL_TEXTURE_2D)
|
||||
Gl.glBindTexture(Gl.GL_TEXTURE_2D, Texture)
|
||||
Gl.glColor4f(1.0F, 1.0F, 1.0F, 1.0F)
|
||||
|
||||
Dim Time = 0.0F
|
||||
|
||||
' Start game loop
|
||||
While (App.IsOpened())
|
||||
|
||||
' Process events
|
||||
App.DispatchEvents()
|
||||
|
||||
' Draw background
|
||||
App.Draw(Background)
|
||||
|
||||
' Clear depth buffer
|
||||
Gl.glClear(Gl.GL_DEPTH_BUFFER_BIT)
|
||||
|
||||
' Apply some transformations
|
||||
Time += App.GetFrameTime()
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW)
|
||||
Gl.glLoadIdentity()
|
||||
Gl.glTranslatef(0.0F, 0.0F, -200.0F)
|
||||
Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F)
|
||||
Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F)
|
||||
Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F)
|
||||
|
||||
' Draw a cube
|
||||
Gl.glBegin(Gl.GL_QUADS)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, -50.0F)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, 50.0F)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F)
|
||||
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, 50.0F)
|
||||
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, -50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, -50.0F, 50.0F)
|
||||
|
||||
Gl.glTexCoord2f(0, 1)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F)
|
||||
Gl.glTexCoord2f(0, 0)
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 0)
|
||||
Gl.glVertex3f(50.0F, 50.0F, -50.0F)
|
||||
Gl.glTexCoord2f(1, 1)
|
||||
Gl.glVertex3f(50.0F, 50.0F, 50.0F)
|
||||
|
||||
Gl.glEnd()
|
||||
|
||||
' Draw some text on top of our OpenGL object
|
||||
App.Draw(Text)
|
||||
|
||||
' Finally, display the rendered frame on screen
|
||||
App.Display()
|
||||
|
||||
End While
|
||||
|
||||
' Don't forget to destroy our texture
|
||||
Gl.glDeleteTextures(1, Texture)
|
||||
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Function called when the window is closed
|
||||
''' </summary>
|
||||
Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles App.Closed
|
||||
Dim window = CType(sender, RenderWindow)
|
||||
window.Close()
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Function called when a key is pressed
|
||||
''' </summary>
|
||||
Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles App.KeyPressed
|
||||
Dim window = CType(sender, RenderWindow)
|
||||
If e.Code = KeyCode.Escape Then
|
||||
window.Close()
|
||||
End If
|
||||
End Sub
|
||||
|
||||
''' <summary>
|
||||
''' Function called when the window is resized
|
||||
''' </summary>
|
||||
Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles App.Resized
|
||||
Gl.glViewport(0, 0, e.Width, e.Height)
|
||||
End Sub
|
||||
|
||||
End Module
|
20
dotnet/samples/visualbasic/visualbasic.sln
Normal file
20
dotnet/samples/visualbasic/visualbasic.sln
Normal file
|
@ -0,0 +1,20 @@
|
|||
|
||||
Microsoft Visual Studio Solution File, Format Version 10.00
|
||||
# Visual Basic Express 2008
|
||||
Project("{F184B08F-C81C-45F6-A57F-5ABD9991F28F}") = "visualbasic", "visualbasic.vbproj", "{98552080-F688-46B4-A2FF-1AC7C50ECBE8}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||
Debug|Any CPU = Debug|Any CPU
|
||||
Release|Any CPU = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||
{98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{98552080-F688-46B4-A2FF-1AC7C50ECBE8}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
EndGlobal
|
121
dotnet/samples/visualbasic/visualbasic.vbproj
Normal file
121
dotnet/samples/visualbasic/visualbasic.vbproj
Normal file
|
@ -0,0 +1,121 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{98552080-F688-46B4-A2FF-1AC7C50ECBE8}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<StartupObject>visualbasic.OpenGL</StartupObject>
|
||||
<RootNamespace>visualbasic</RootNamespace>
|
||||
<AssemblyName>visualbasic</AssemblyName>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<MyType>WindowsFormsWithCustomSubMain</MyType>
|
||||
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
|
||||
<OptionExplicit>On</OptionExplicit>
|
||||
<OptionCompare>Binary</OptionCompare>
|
||||
<OptionStrict>Off</OptionStrict>
|
||||
<OptionInfer>On</OptionInfer>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<DefineDebug>true</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DocumentationFile>visualbasic.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<DefineDebug>false</DefineDebug>
|
||||
<DefineTrace>true</DefineTrace>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>bin\Release\</OutputPath>
|
||||
<DocumentationFile>visualbasic.xml</DocumentationFile>
|
||||
<NoWarn>42016,41999,42017,42018,42019,42032,42036,42020,42021,42022</NoWarn>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="sfmlnet-graphics, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\sfmlnet-graphics.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="sfmlnet-window, Version=0.0.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\lib\sfmlnet-window.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Data" />
|
||||
<Reference Include="System.Deployment" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Xml.Linq">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="System.Data.DataSetExtensions">
|
||||
<RequiredTargetFramework>3.5</RequiredTargetFramework>
|
||||
</Reference>
|
||||
<Reference Include="Tao.FreeGlut, Version=2.4.0.2, Culture=neutral, PublicKeyToken=6e602a6ad6c0d06d, processorArchitecture=MSIL" />
|
||||
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef, processorArchitecture=MSIL" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Import Include="Microsoft.VisualBasic" />
|
||||
<Import Include="System" />
|
||||
<Import Include="System.Collections" />
|
||||
<Import Include="System.Collections.Generic" />
|
||||
<Import Include="System.Data" />
|
||||
<Import Include="System.Diagnostics" />
|
||||
<Import Include="System.Linq" />
|
||||
<Import Include="System.Xml.Linq" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="OpenGL.vb" />
|
||||
<Compile Include="My Project\AssemblyInfo.vb" />
|
||||
<Compile Include="My Project\Application.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Application.myapp</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Resources.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DesignTime>True</DesignTime>
|
||||
<DependentUpon>Resources.resx</DependentUpon>
|
||||
</Compile>
|
||||
<Compile Include="My Project\Settings.Designer.vb">
|
||||
<AutoGen>True</AutoGen>
|
||||
<DependentUpon>Settings.settings</DependentUpon>
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
<Generator>VbMyResourcesResXFileCodeGenerator</Generator>
|
||||
<LastGenOutput>Resources.Designer.vb</LastGenOutput>
|
||||
<CustomToolNamespace>My.Resources</CustomToolNamespace>
|
||||
<SubType>Designer</SubType>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="My Project\Application.myapp">
|
||||
<Generator>MyApplicationCodeGenerator</Generator>
|
||||
<LastGenOutput>Application.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
<None Include="My Project\Settings.settings">
|
||||
<Generator>SettingsSingleFileGenerator</Generator>
|
||||
<CustomToolNamespace>My</CustomToolNamespace>
|
||||
<LastGenOutput>Settings.Designer.vb</LastGenOutput>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.VisualBasic.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
134
dotnet/samples/window/Window.cs
Normal file
134
dotnet/samples/window/Window.cs
Normal file
|
@ -0,0 +1,134 @@
|
|||
using System;
|
||||
using SFML;
|
||||
using SFML.Window;
|
||||
using Tao.OpenGl;
|
||||
|
||||
namespace sample_window
|
||||
{
|
||||
static class Program
|
||||
{
|
||||
/// <summary>
|
||||
/// The main entry point for the application.
|
||||
/// </summary>
|
||||
static void Main()
|
||||
{
|
||||
// Create the main window
|
||||
Window App = new Window(new VideoMode(640, 480, 32), "SFML.Net Window");
|
||||
|
||||
// Setup event handlers
|
||||
App.Closed += new EventHandler(OnClosed);
|
||||
App.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
|
||||
App.Resized += new EventHandler<SizeEventArgs>(OnResized);
|
||||
|
||||
// Set the color and depth clear values
|
||||
Gl.glClearDepth(1.0F);
|
||||
Gl.glClearColor(0.0F, 0.0F, 0.0F, 0.0F);
|
||||
|
||||
// Enable Z-buffer read and write
|
||||
Gl.glEnable(Gl.GL_DEPTH_TEST);
|
||||
Gl.glDepthMask(Gl.GL_TRUE);
|
||||
|
||||
// Setup a perspective projection
|
||||
Gl.glMatrixMode(Gl.GL_PROJECTION);
|
||||
Gl.glLoadIdentity();
|
||||
Glu.gluPerspective(90.0F, 1.0F, 1.0F, 500.0F);
|
||||
|
||||
float Time = 0.0F;
|
||||
|
||||
// Start the game loop
|
||||
while (App.IsOpened())
|
||||
{
|
||||
// Process events
|
||||
App.DispatchEvents();
|
||||
|
||||
// Set the active window before using OpenGL commands
|
||||
// It's useless here because the active window is always the same,
|
||||
// but don't forget it if you use multiple windows
|
||||
App.SetActive();
|
||||
|
||||
// Clear color and depth buffer
|
||||
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT | Gl.GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
// Apply some transformations
|
||||
Time += App.GetFrameTime();
|
||||
Gl.glMatrixMode(Gl.GL_MODELVIEW);
|
||||
Gl.glLoadIdentity();
|
||||
Gl.glTranslatef(0.0F, 0.0F, -200.0F);
|
||||
Gl.glRotatef(Time * 50, 1.0F, 0.0F, 0.0F);
|
||||
Gl.glRotatef(Time * 30, 0.0F, 1.0F, 0.0F);
|
||||
Gl.glRotatef(Time * 90, 0.0F, 0.0F, 1.0F);
|
||||
|
||||
// Draw a cube
|
||||
Gl.glBegin(Gl.GL_QUADS);
|
||||
|
||||
Gl.glColor3f(1.0F, 0.0F, 0.0F);
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
|
||||
Gl.glVertex3f( 50.0F, 50.0F, -50.0F);
|
||||
Gl.glVertex3f( 50.0F, -50.0F, -50.0F);
|
||||
|
||||
Gl.glColor3f(1.0F, 0.0F, 0.0F);
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
|
||||
Gl.glVertex3f( 50.0F, 50.0F, 50.0F);
|
||||
Gl.glVertex3f( 50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glColor3f(0.0F, 1.0F, 0.0F);
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glColor3f(0.0F, 1.0F, 0.0F);
|
||||
Gl.glVertex3f(50.0F, -50.0F, -50.0F);
|
||||
Gl.glVertex3f(50.0F, 50.0F, -50.0F);
|
||||
Gl.glVertex3f(50.0F, 50.0F, 50.0F);
|
||||
Gl.glVertex3f(50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glColor3f(0.0F, 0.0F, 1.0F);
|
||||
Gl.glVertex3f(-50.0F, -50.0F, 50.0F);
|
||||
Gl.glVertex3f(-50.0F, -50.0F, -50.0F);
|
||||
Gl.glVertex3f( 50.0F, -50.0F, -50.0F);
|
||||
Gl.glVertex3f( 50.0F, -50.0F, 50.0F);
|
||||
|
||||
Gl.glColor3f(0.0F, 0.0F, 1.0F);
|
||||
Gl.glVertex3f(-50.0F, 50.0F, 50.0F);
|
||||
Gl.glVertex3f(-50.0F, 50.0F, -50.0F);
|
||||
Gl.glVertex3f( 50.0F, 50.0F, -50.0F);
|
||||
Gl.glVertex3f( 50.0F, 50.0F, 50.0F);
|
||||
|
||||
Gl.glEnd();
|
||||
|
||||
// Finally, display the rendered frame on screen
|
||||
App.Display();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when the window is closed
|
||||
/// </summary>
|
||||
static void OnClosed(object sender, EventArgs e)
|
||||
{
|
||||
Window window = (Window)sender;
|
||||
window.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when a key is pressed
|
||||
/// </summary>
|
||||
static void OnKeyPressed(object sender, KeyEventArgs e)
|
||||
{
|
||||
Window window = (Window)sender;
|
||||
if (e.Code == KeyCode.Escape)
|
||||
window.Close();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Function called when the window is resized
|
||||
/// </summary>
|
||||
static void OnResized(object sender, SizeEventArgs e)
|
||||
{
|
||||
Gl.glViewport(0, 0, (int)e.Width, (int)e.Height);
|
||||
}
|
||||
}
|
||||
}
|
60
dotnet/samples/window/sample-window.csproj
Normal file
60
dotnet/samples/window/sample-window.csproj
Normal file
|
@ -0,0 +1,60 @@
|
|||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{C1FBB9AF-B69A-4D06-9BDC-EAC7606296FF}</ProjectGuid>
|
||||
<OutputType>WinExe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>sample_window</RootNamespace>
|
||||
<AssemblyName>window</AssemblyName>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\src\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Window.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Tao.FreeGlut, Version=2.4.0.2, Culture=neutral, PublicKeyToken=6e602a6ad6c0d06d, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.FreeGlut.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Tao.OpenGl, Version=2.1.0.12, Culture=neutral, PublicKeyToken=1ca010269a4501ef, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\..\..\..\..\Bibliothèques\TaoFramework\bin\Tao.OpenGl.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
73
dotnet/src/Audio/Listener.cs
Normal file
73
dotnet/src/Audio/Listener.cs
Normal file
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Listener is a global interface for defining the audio
|
||||
/// listener properties ; the audio listener is the point in
|
||||
/// the scene from where all the sounds are heard
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Listener
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Global volume of all sounds, in range [0 .. 100] (default is 100)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
static float GlobalVolume
|
||||
{
|
||||
get {return sfListener_GetGlobalVolume();}
|
||||
set {sfListener_SetGlobalVolume(value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the listener (default is (0, 0, 0))
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfListener_GetPosition(out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfListener_SetPosition(value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the target, ie. the point the listener is looking at
|
||||
/// (default is (0, 0, -1))
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
static Vector3 Target
|
||||
{
|
||||
get {Vector3 v; sfListener_GetTarget(out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfListener_SetTarget(value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_SetGlobalVolume(float Volume);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfListener_GetGlobalVolume();
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_SetPosition(float PosX, float PosY, float PosZ);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_GetPosition(out float PosX, out float PosY, out float PosZ);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_SetTarget(float TargetX, float TargetY, float TargetZ);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfListener_GetTarget(out float TargetX, out float TargetY, out float TargetZ);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
287
dotnet/src/Audio/Music.cs
Normal file
287
dotnet/src/Audio/Music.cs
Normal file
|
@ -0,0 +1,287 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Music defines a big sound played using streaming,
|
||||
/// so usually what we call a music :)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Music : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the music from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the music file to load</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Music(string filename) :
|
||||
base(sfMusic_CreateFromFile(filename))
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("music", filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the music from a file in a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Music(Stream stream) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
stream.Position = 0;
|
||||
byte[] StreamData = new byte[stream.Length];
|
||||
uint Read = (uint)stream.Read(StreamData, 0, StreamData.Length);
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* dataPtr = StreamData)
|
||||
{
|
||||
SetThis(sfMusic_CreateFromMemory((char*)dataPtr, Read));
|
||||
}
|
||||
}
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("music");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Play the music
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Play()
|
||||
{
|
||||
sfMusic_Play(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pause the music
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Pause()
|
||||
{
|
||||
sfMusic_Pause(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the music
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfMusic_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Samples rate, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfMusic_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Number of channels (1 = mono, 2 = stereo)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint ChannelsCount
|
||||
{
|
||||
get {return sfMusic_GetChannelsCount(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current status of the music (see SoundStatus enum)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStatus Status
|
||||
{
|
||||
get {return sfMusic_GetStatus(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Total duration of the music, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Duration
|
||||
{
|
||||
get {return sfMusic_GetDuration(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Loop state of the sound. Default value is false
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Loop
|
||||
{
|
||||
get {return sfMusic_GetLoop(This);}
|
||||
set {sfMusic_SetLoop(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pitch of the music. Default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Pitch
|
||||
{
|
||||
get {return sfMusic_GetPitch(This);}
|
||||
set {sfMusic_SetPitch(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Volume of the music, in range [0, 100]. Default value is 100
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Volume
|
||||
{
|
||||
get {return sfMusic_GetVolume(This);}
|
||||
set {sfMusic_SetVolume(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the music. Default value is (0, 0, 0)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfMusic_GetPosition(This, out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfMusic_SetPosition(This, value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Minimum distance of the music. Closer than this distance,
|
||||
/// the listener will hear the sound at its maximum volume.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float MinDistance
|
||||
{
|
||||
get {return sfMusic_GetMinDistance(This);}
|
||||
set {sfMusic_SetMinDistance(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Attenuation factor. The higher the attenuation, the
|
||||
/// more the sound will be attenuated with distance from listener.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Attenuation
|
||||
{
|
||||
get {return sfMusic_GetAttenuation(This);}
|
||||
set {sfMusic_SetAttenuation(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current playing position, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float PlayingOffset
|
||||
{
|
||||
get {return sfMusic_GetPlayingOffset(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfMusic_Destroy(This);
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio")]
|
||||
static extern IntPtr sfMusic_CreateFromFile(string Filename);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
unsafe static extern IntPtr sfMusic_CreateFromMemory(char* Data, uint SizeInBytes);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_Destroy(IntPtr MusicStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_Play(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_Pause(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_Stop(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern SoundStatus sfMusic_GetStatus(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfMusic_GetDuration(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern uint sfMusic_GetChannelsCount(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern uint sfMusic_GetSampleRate(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_SetPitch(IntPtr Music, float Pitch);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_SetLoop(IntPtr Music, bool Loop);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_SetVolume(IntPtr Music, float Volume);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_SetPosition(IntPtr Music, float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_SetMinDistance(IntPtr Music, float MinDistance);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_SetAttenuation(IntPtr Music, float Attenuation);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern bool sfMusic_GetLoop(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfMusic_GetPitch(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfMusic_GetVolume(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfMusic_GetPosition(IntPtr Music, out float X, out float Y, out float Z);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfMusic_GetMinDistance(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfMusic_GetAttenuation(IntPtr Music);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfMusic_GetPlayingOffset(IntPtr Music);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
270
dotnet/src/Audio/Sound.cs
Normal file
270
dotnet/src/Audio/Sound.cs
Normal file
|
@ -0,0 +1,270 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enumeration of all possible sound states
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public enum SoundStatus
|
||||
{
|
||||
/// <summary>Sound is not playing</summary>
|
||||
Stopped,
|
||||
|
||||
/// <summary>Sound is paused</summary>
|
||||
Paused,
|
||||
|
||||
/// <summary>Sound is playing</summary>
|
||||
Playing
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Sound defines the properties of a sound such as position,
|
||||
/// volume, pitch, etc.
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Sound : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor (invalid sound)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Sound() :
|
||||
base(sfSound_Create())
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound from a source buffer
|
||||
/// </summary>
|
||||
/// <param name="buffer">Sound buffer to play</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Sound(SoundBuffer buffer) :
|
||||
base(sfSound_Create())
|
||||
{
|
||||
SoundBuffer = buffer;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Play the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Play()
|
||||
{
|
||||
sfSound_Play(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pause the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Pause()
|
||||
{
|
||||
sfSound_Pause(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfSound_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Buffer containing the sound data to play through the sound
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer SoundBuffer
|
||||
{
|
||||
get {return myBuffer;}
|
||||
set {myBuffer = value; sfSound_SetBuffer(This, value != null ? value.This : IntPtr.Zero);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current status of the sound (see SoundStatus enum)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStatus Status
|
||||
{
|
||||
get {return sfSound_GetStatus(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Loop state of the sound. Default value is false
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Loop
|
||||
{
|
||||
get {return sfSound_GetLoop(This);}
|
||||
set {sfSound_SetLoop(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pitch of the sound. Default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Pitch
|
||||
{
|
||||
get {return sfSound_GetPitch(This);}
|
||||
set {sfSound_SetPitch(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Volume of the sound, in range [0, 100]. Default value is 100
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Volume
|
||||
{
|
||||
get {return sfSound_GetVolume(This);}
|
||||
set {sfSound_SetVolume(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current playing position of the sound, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float PlayingOffset
|
||||
{
|
||||
get {return sfSound_GetPlayingOffset(This);}
|
||||
set {sfSound_SetPlayingOffset(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the sound. Default value is (0, 0, 0)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfSound_GetPosition(This, out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfSound_SetPosition(This, value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Minimum distance of the sound. Closer than this distance,
|
||||
/// the listener will hear the sound at its maximum volume.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float MinDistance
|
||||
{
|
||||
get {return sfSound_GetMinDistance(This);}
|
||||
set {sfSound_SetMinDistance(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Attenuation factor. The higher the attenuation, the
|
||||
/// more the sound will be attenuated with distance from listener.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Attenuation
|
||||
{
|
||||
get {return sfSound_GetAttenuation(This);}
|
||||
set {sfSound_SetAttenuation(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSound_Destroy(This);
|
||||
}
|
||||
|
||||
private SoundBuffer myBuffer;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSound_Create();
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Destroy(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Play(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Pause(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_Stop(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetBuffer(IntPtr Sound, IntPtr Buffer);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSound_GetBuffer(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetLoop(IntPtr Sound, bool Loop);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSound_GetLoop(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern SoundStatus sfSound_GetStatus(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetPitch(IntPtr Sound, float Pitch);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetVolume(IntPtr Sound, float Volume);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetPosition(IntPtr Sound, float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetMinDistance(IntPtr Sound, float MinDistance);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetAttenuation(IntPtr Sound, float Attenuation);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_SetPlayingOffset(IntPtr Sound, float TimeOffset);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetPitch(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetVolume(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSound_GetPosition(IntPtr Sound, out float X, out float Y, out float Z);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetMinDistance(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetAttenuation(IntPtr Sound);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSound_GetPlayingOffset(IntPtr Sound);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
181
dotnet/src/Audio/SoundBuffer.cs
Normal file
181
dotnet/src/Audio/SoundBuffer.cs
Normal file
|
@ -0,0 +1,181 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// SoundBuffer is the low-level class for loading and manipulating
|
||||
/// sound buffers. A sound buffer holds audio data (samples)
|
||||
/// which can then be played by a Sound or saved to a file.
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class SoundBuffer : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound buffer from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the sound file to load</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer(string filename) :
|
||||
base(sfSoundBuffer_CreateFromFile(filename))
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("sound buffer", filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound buffer from a file in a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer(Stream stream) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
stream.Position = 0;
|
||||
byte[] StreamData = new byte[stream.Length];
|
||||
uint Read = (uint)stream.Read(StreamData, 0, StreamData.Length);
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* dataPtr = StreamData)
|
||||
{
|
||||
SetThis(sfSoundBuffer_CreateFromMemory((char*)dataPtr, Read));
|
||||
}
|
||||
}
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("sound buffer");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sound buffer from an array of samples
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples</param>
|
||||
/// <param name="channelsCount">Channels count</param>
|
||||
/// <param name="sampleRate">Sample rate</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer(short[] samples, uint channelsCount, uint sampleRate) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (short* SamplesPtr = samples)
|
||||
{
|
||||
SetThis(sfSoundBuffer_CreateFromSamples(SamplesPtr, (uint)samples.Length, channelsCount, sampleRate));
|
||||
}
|
||||
}
|
||||
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("sound buffer");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Save the sound buffer to an audio file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the sound file to write</param>
|
||||
/// <returns>True if saving has been successful</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool SaveToFile(string filename)
|
||||
{
|
||||
return sfSoundBuffer_SaveToFile(This, filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Samples rate, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfSoundBuffer_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Number of channels (1 = mono, 2 = stereo)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint ChannelsCount
|
||||
{
|
||||
get {return sfSoundBuffer_GetChannelsCount(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Total duration of the buffer, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Duration
|
||||
{
|
||||
get {return sfSoundBuffer_GetDuration(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Array of samples contained in the buffer
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public short[] Samples
|
||||
{
|
||||
get
|
||||
{
|
||||
short[] SamplesArray = new short[sfSoundBuffer_GetSamplesCount(This)];
|
||||
Marshal.Copy(sfSoundBuffer_GetSamples(This), SamplesArray, 0, SamplesArray.Length);
|
||||
return SamplesArray;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSoundBuffer_Destroy(This);
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSoundBuffer_CreateFromFile(string Filename);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfSoundBuffer_CreateFromMemory(char* Data, uint SizeInBytes);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfSoundBuffer_CreateFromSamples(short* Samples, uint SamplesCount, uint ChannelsCount, uint SampleRate);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSoundBuffer_Destroy(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfSoundBuffer_SaveToFile(IntPtr SoundBuffer, string Filename);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSoundBuffer_GetSamples(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundBuffer_GetSamplesCount(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundBuffer_GetSampleRate(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfSoundBuffer_GetChannelsCount(IntPtr SoundBuffer);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundBuffer_GetDuration(IntPtr SoundBuffer);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
70
dotnet/src/Audio/SoundBufferRecorder.cs
Normal file
70
dotnet/src/Audio/SoundBufferRecorder.cs
Normal file
|
@ -0,0 +1,70 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Specialized SoundRecorder which saves the captured
|
||||
/// audio data into a sound buffer
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class SoundBufferRecorder : SoundRecorder
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Sound buffer containing the recorded data (invalid until the capture stops)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundBuffer SoundBuffer
|
||||
{
|
||||
get
|
||||
{
|
||||
return mySoundBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when a new capture starts
|
||||
/// </summary>
|
||||
/// <returns>False to abort recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override bool OnStart()
|
||||
{
|
||||
mySamplesArray.Clear();
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Process a new chunk of recorded samples
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples to process</param>
|
||||
/// <returns>False to stop recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override bool OnProcessSamples(short[] samples)
|
||||
{
|
||||
mySamplesArray.AddRange(samples);
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when the current capture stops
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void OnStop()
|
||||
{
|
||||
mySoundBuffer = new SoundBuffer(mySamplesArray.ToArray(), 1, SampleRate);
|
||||
}
|
||||
|
||||
List<short> mySamplesArray = new List<short>();
|
||||
SoundBuffer mySoundBuffer = null;
|
||||
}
|
||||
}
|
||||
}
|
180
dotnet/src/Audio/SoundRecorder.cs
Normal file
180
dotnet/src/Audio/SoundRecorder.cs
Normal file
|
@ -0,0 +1,180 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// SoundRecorder is an interface for capturing sound data,
|
||||
/// it is meant to be used as a base class
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract class SoundRecorder : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundRecorder() :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
myStartCallback = new StartCallback(OnStart);
|
||||
myProcessCallback = new ProcessCallback(ProcessSamples);
|
||||
myStopCallback = new StopCallback(OnStop);
|
||||
|
||||
SetThis(sfSoundRecorder_Create(myStartCallback, myProcessCallback, myStopCallback, IntPtr.Zero));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Start the capture using default sample rate (44100 Hz)
|
||||
/// Warning : only one capture can happen at the same time
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Start()
|
||||
{
|
||||
Start(44100);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Start the capture.
|
||||
/// Warning : only one capture can happen at the same time
|
||||
/// </summary>
|
||||
/// <param name="sampleRate"> Sound frequency; the more samples, the higher the quality (44100 by default = CD quality)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Start(uint sampleRate)
|
||||
{
|
||||
sfSoundRecorder_Start(This, sampleRate);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the capture
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfSoundRecorder_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Sample rate of the recorder, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfSoundRecorder_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Tell if the system supports sound capture.
|
||||
/// If not, this class won't be usable
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static bool CanCapture
|
||||
{
|
||||
get {return sfSoundRecorder_CanCapture();}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when a new capture starts
|
||||
/// </summary>
|
||||
/// <returns>False to abort recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected virtual bool OnStart()
|
||||
{
|
||||
// Does nothing by default
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Process a new chunk of recorded samples
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples to process</param>
|
||||
/// <returns>False to stop recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected abstract bool OnProcessSamples(short[] samples);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when the current capture stops
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected virtual void OnStop()
|
||||
{
|
||||
// Does nothing by default
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSoundRecorder_Destroy(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Function called directly by the C library ; convert
|
||||
/// arguments and forward them to the internal virtual function
|
||||
/// </summary>
|
||||
/// <param name="samples">Pointer to the array of samples</param>
|
||||
/// <param name="nbSamples">Number of samples in the array</param>
|
||||
/// <param name="userData">User data -- unused</param>
|
||||
/// <returns>False to stop recording audio data, true to continue</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
private bool ProcessSamples(IntPtr samples, uint nbSamples, IntPtr userData)
|
||||
{
|
||||
short[] samplesArray = new short[nbSamples];
|
||||
Marshal.Copy(samples, samplesArray, 0, samplesArray.Length);
|
||||
|
||||
return OnProcessSamples(samplesArray);
|
||||
}
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool StartCallback();
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool ProcessCallback(IntPtr samples, uint nbSamples, IntPtr userData);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate void StopCallback();
|
||||
|
||||
private StartCallback myStartCallback;
|
||||
private ProcessCallback myProcessCallback;
|
||||
private StopCallback myStopCallback;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio")]
|
||||
static extern IntPtr sfSoundRecorder_Create(StartCallback OnStart, ProcessCallback OnProcess, StopCallback OnStop, IntPtr UserData);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundRecorder_Destroy(IntPtr SoundRecorder);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundRecorder_Start(IntPtr SoundRecorder, uint SampleRate);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundRecorder_Stop(IntPtr SoundRecorder);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern uint sfSoundRecorder_GetSampleRate(IntPtr SoundRecorder);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern bool sfSoundRecorder_CanCapture();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
343
dotnet/src/Audio/SoundStream.cs
Normal file
343
dotnet/src/Audio/SoundStream.cs
Normal file
|
@ -0,0 +1,343 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// SoundStream is a streamed sound, ie. samples are acquired
|
||||
/// while the sound is playing. Use it for big sounds that would
|
||||
/// require hundreds of MB in memory (see Music),
|
||||
/// or for streaming sound from the network
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract class SoundStream : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStream() :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Play the sound stream
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Play()
|
||||
{
|
||||
sfSoundStream_Play(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pause the sound stream
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Pause()
|
||||
{
|
||||
sfSoundStream_Pause(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Stop the sound stream
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Stop()
|
||||
{
|
||||
sfSoundStream_Stop(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Samples rate, in samples per second
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint SampleRate
|
||||
{
|
||||
get {return sfSoundStream_GetSampleRate(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Number of channels (1 = mono, 2 = stereo)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint ChannelsCount
|
||||
{
|
||||
get {return sfSoundStream_GetChannelsCount(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current status of the sound stream (see SoundStatus enum)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SoundStatus Status
|
||||
{
|
||||
get {return sfSoundStream_GetStatus(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Loop state of the sound stream. Default value is false
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Loop
|
||||
{
|
||||
get {return sfSoundStream_GetLoop(This);}
|
||||
set {sfSoundStream_SetLoop(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Pitch of the sound stream. Default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Pitch
|
||||
{
|
||||
get {return sfSoundStream_GetPitch(This);}
|
||||
set {sfSoundStream_SetPitch(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Volume of the sound stream, in range [0, 100]. Default value is 100
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Volume
|
||||
{
|
||||
get {return sfSoundStream_GetVolume(This);}
|
||||
set {sfSoundStream_SetVolume(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// 3D position of the sound stream. Default value is (0, 0, 0)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3 Position
|
||||
{
|
||||
get {Vector3 v; sfSoundStream_GetPosition(This, out v.X, out v.Y, out v.Z); return v;}
|
||||
set {sfSoundStream_SetPosition(This, value.X, value.Y, value.Z);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Minimum distance of the sound stream. Closer than this distance,
|
||||
/// the listener will hear the sound at its maximum volume.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float MinDistance
|
||||
{
|
||||
get {return sfSoundStream_GetMinDistance(This);}
|
||||
set {sfSoundStream_SetMinDistance(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Attenuation factor. The higher the attenuation, the
|
||||
/// more the sound will be attenuated with distance from listener.
|
||||
/// The default value is 1
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Attenuation
|
||||
{
|
||||
get {return sfSoundStream_GetAttenuation(This);}
|
||||
set {sfSoundStream_SetAttenuation(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current playing position, in seconds
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float PlayingOffset
|
||||
{
|
||||
get {return sfSoundStream_GetPlayingOffset(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Set the audio stream parameters, you must call it before Play()
|
||||
/// </summary>
|
||||
/// <param name="sampleRate">Number of channels</param>
|
||||
/// <param name="channelsCount">Sample rate, in samples per second</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected void Initialize(uint channelsCount, uint sampleRate)
|
||||
{
|
||||
myStartCallback = new StartCallbackType(Start);
|
||||
myGetDataCallback = new GetDataCallbackType(GetData);
|
||||
SetThis(sfSoundStream_Create(myStartCallback, myGetDataCallback, channelsCount, sampleRate, IntPtr.Zero));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Virtual function called when the stream restarts
|
||||
/// </summary>
|
||||
/// <returns>If false is returned, the playback is aborted</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected virtual bool OnStart()
|
||||
{
|
||||
// Does nothing by default
|
||||
return true;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Virtual function called each time new audio data is needed to feed the stream
|
||||
/// </summary>
|
||||
/// <param name="samples">Array of samples to fill for the stream</param>
|
||||
/// <returns>True to continue playback, false to stop</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected abstract bool OnGetData(out short[] samples);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSoundStream_Destroy(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Structure mapping the C library arguments passed to the data callback
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
private struct Chunk
|
||||
{
|
||||
unsafe public short* samplesPtr;
|
||||
public uint samplesCount;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called when the stream restarts
|
||||
/// </summary>
|
||||
/// <param name="userData">User data -- unused</param>
|
||||
/// <returns>If false is returned, the playback is aborted</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
private bool Start(IntPtr userData)
|
||||
{
|
||||
return OnStart();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Called each time new audio data is needed to feed the stream
|
||||
/// </summary>
|
||||
/// <param name="dataChunk">Data chunk to fill with new audio samples</param>
|
||||
/// <param name="userData">User data -- unused</param>
|
||||
/// <returns>True to continue playback, false to stop</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
private bool GetData(ref Chunk dataChunk, IntPtr userData)
|
||||
{
|
||||
if (OnGetData(out myTempBuffer))
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (short* samplesPtr = myTempBuffer)
|
||||
{
|
||||
dataChunk.samplesPtr = samplesPtr;
|
||||
dataChunk.samplesCount = (uint)myTempBuffer.Length;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool StartCallbackType(IntPtr UserData);
|
||||
|
||||
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
||||
private delegate bool GetDataCallbackType(ref Chunk dataChunk, IntPtr UserData);
|
||||
|
||||
private StartCallbackType myStartCallback;
|
||||
private GetDataCallbackType myGetDataCallback;
|
||||
private short[] myTempBuffer;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-audio")]
|
||||
static extern IntPtr sfSoundStream_Create(StartCallbackType OnStart, GetDataCallbackType OnGetData, uint ChannelsCount, uint SampleRate, IntPtr UserData);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_Destroy(IntPtr SoundStreamStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_Play(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_Pause(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_Stop(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern SoundStatus sfSoundStream_GetStatus(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern uint sfSoundStream_GetChannelsCount(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern uint sfSoundStream_GetSampleRate(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_SetLoop(IntPtr SoundStream, bool Loop);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_SetPitch(IntPtr SoundStream, float Pitch);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_SetVolume(IntPtr SoundStream, float Volume);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_SetPosition(IntPtr SoundStream, float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_SetMinDistance(IntPtr SoundStream, float MinDistance);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_SetAttenuation(IntPtr SoundStream, float Attenuation);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern bool sfSoundStream_GetLoop(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfSoundStream_GetPitch(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfSoundStream_GetVolume(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern void sfSoundStream_GetPosition(IntPtr SoundStream, out float X, out float Y, out float Z);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfSoundStream_GetMinDistance(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio")]
|
||||
static extern float sfSoundStream_GetAttenuation(IntPtr SoundStream);
|
||||
|
||||
[DllImport("csfml-audio"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSoundStream_GetPlayingOffset(IntPtr SoundStream);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
119
dotnet/src/Audio/Vector3.cs
Normal file
119
dotnet/src/Audio/Vector3.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Audio
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Vector3 is an utility class for manipulating 3 dimensional
|
||||
/// vectors with float components
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vector3
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the vector from its coordinates
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
/// <param name="z">Z coordinate</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector3(float x, float y, float z)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
Z = z;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator - overload ; returns the opposite of a vector
|
||||
/// </summary>
|
||||
/// <param name="v">Vector to negate</param>
|
||||
/// <returns>-v</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator -(Vector3 v)
|
||||
{
|
||||
return new Vector3(-v.X, -v.Y, -v.Z);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator - overload ; subtracts two vectors
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>v1 - v2</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator -(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return new Vector3(v1.X - v2.X, v1.Y - v2.X, v1.Z - v2.Z);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator + overload ; add two vectors
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>v1 + v2</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator +(Vector3 v1, Vector3 v2)
|
||||
{
|
||||
return new Vector3(v1.X + v2.X, v1.Y + v2.X, v1.Z + v2.Z);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator * overload ; multiply a vector by a scalar value
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <returns>v * x</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator *(Vector3 v, float x)
|
||||
{
|
||||
return new Vector3(v.X * x, v.Y * x, v.Z * x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator * overload ; multiply a scalar value by a vector
|
||||
/// </summary>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <returns>x * v</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator *(float x, Vector3 v)
|
||||
{
|
||||
return new Vector3(v.X * x, v.Y * x, v.Z * x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator / overload ; divide a vector by a scalar value
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <returns>v / x</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector3 operator /(Vector3 v, float x)
|
||||
{
|
||||
return new Vector3(v.X / x, v.Y / x, v.Z / x);
|
||||
}
|
||||
|
||||
/// <summary>X (horizontal) component of the vector</summary>
|
||||
public float X;
|
||||
|
||||
/// <summary>Y (vertical) component of the vector</summary>
|
||||
public float Y;
|
||||
|
||||
/// <summary>Z (depth) component of the vector</summary>
|
||||
public float Z;
|
||||
}
|
||||
}
|
||||
}
|
64
dotnet/src/Audio/sfml-audio.csproj
Normal file
64
dotnet/src/Audio/sfml-audio.csproj
Normal file
|
@ -0,0 +1,64 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{0B202C4D-A457-47FE-84A3-031DD878C6BE}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SFML.Audio</RootNamespace>
|
||||
<AssemblyName>sfmlnet-audio</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>bin\audio-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\lib\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>bin\audio-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Listener.cs" />
|
||||
<Compile Include="Music.cs" />
|
||||
<Compile Include="Sound.cs" />
|
||||
<Compile Include="SoundBuffer.cs" />
|
||||
<Compile Include="SoundBufferRecorder.cs" />
|
||||
<Compile Include="SoundRecorder.cs" />
|
||||
<Compile Include="SoundStream.cs" />
|
||||
<Compile Include="Vector3.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
95
dotnet/src/Graphics/Color.cs
Normal file
95
dotnet/src/Graphics/Color.cs
Normal file
|
@ -0,0 +1,95 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Utility class for manipulating 32-bits RGBA colors
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Color
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the color from its red, green and blue components
|
||||
/// </summary>
|
||||
/// <param name="red">Red component</param>
|
||||
/// <param name="green">Green component</param>
|
||||
/// <param name="blue">Blue component</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Color(byte red, byte green, byte blue) :
|
||||
this(red, green, blue, 255)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the color from its red, green, blue and alpha components
|
||||
/// </summary>
|
||||
/// <param name="red">Red component</param>
|
||||
/// <param name="green">Green component</param>
|
||||
/// <param name="blue">Blue component</param>
|
||||
/// <param name="alpha">Alpha (transparency) component</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Color(byte red, byte green, byte blue, byte alpha)
|
||||
{
|
||||
R = red;
|
||||
G = green;
|
||||
B = blue;
|
||||
A = alpha;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the color from another
|
||||
/// </summary>
|
||||
/// <param name="color">Color to copy</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Color(Color color) :
|
||||
this(color.R, color.G, color.B, color.A)
|
||||
{
|
||||
}
|
||||
|
||||
/// <summary>Red component of the color</summary>
|
||||
public byte R;
|
||||
|
||||
/// <summary>Green component of the color</summary>
|
||||
public byte G;
|
||||
|
||||
/// <summary>Blue component of the color</summary>
|
||||
public byte B;
|
||||
|
||||
/// <summary>Alpha (transparent) component of the color</summary>
|
||||
public byte A;
|
||||
|
||||
|
||||
/// <summary>Predefined black color</summary>
|
||||
public static readonly Color Black = new Color(0, 0, 0);
|
||||
|
||||
/// <summary>Predefined white color</summary>
|
||||
public static readonly Color White = new Color(255, 255, 255);
|
||||
|
||||
/// <summary>Predefined red color</summary>
|
||||
public static readonly Color Red = new Color(255, 0, 0);
|
||||
|
||||
/// <summary>Predefined green color</summary>
|
||||
public static readonly Color Green = new Color(0, 255, 0);
|
||||
|
||||
/// <summary>Predefined blue color</summary>
|
||||
public static readonly Color Blue = new Color(0, 0, 255);
|
||||
|
||||
/// <summary>Predefined yellow color</summary>
|
||||
public static readonly Color Yellow = new Color(255, 255, 0);
|
||||
|
||||
/// <summary>Predefined magenta color</summary>
|
||||
public static readonly Color Magenta = new Color(255, 0, 255);
|
||||
|
||||
/// <summary>Predefined cyan color</summary>
|
||||
public static readonly Color Cyan = new Color(0, 255, 255);
|
||||
}
|
||||
}
|
||||
}
|
80
dotnet/src/Graphics/Context.cs
Normal file
80
dotnet/src/Graphics/Context.cs
Normal file
|
@ -0,0 +1,80 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// This class defines
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
internal class Context : CriticalFinalizerObject
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Context()
|
||||
{
|
||||
myThis = sfContext_Create();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Finalizer
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
~Context()
|
||||
{
|
||||
sfContext_Destroy(myThis);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Activate or deactivate the context
|
||||
/// </summary>
|
||||
/// <param name="active">True to activate, false to deactivate</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetActive(bool active)
|
||||
{
|
||||
sfContext_SetActive(myThis, active);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Global helper context
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Context Global
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ourGlobalContext == null)
|
||||
ourGlobalContext = new Context();
|
||||
|
||||
return ourGlobalContext;
|
||||
}
|
||||
}
|
||||
|
||||
private static Context ourGlobalContext = null;
|
||||
|
||||
private IntPtr myThis = IntPtr.Zero;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfContext_Create();
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfContext_Destroy(IntPtr View);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfContext_SetActive(IntPtr View, bool Active);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
119
dotnet/src/Graphics/Drawable.cs
Normal file
119
dotnet/src/Graphics/Drawable.cs
Normal file
|
@ -0,0 +1,119 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enumerate the blending modes available for drawable objects
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public enum BlendMode
|
||||
{
|
||||
/// <summary>Pixel = Src * a + Dest * (1 - a)</summary>
|
||||
Alpha,
|
||||
|
||||
/// <summary>Pixel = Src + Dest</summary>
|
||||
Add,
|
||||
|
||||
/// <summary>Pixel = Src * Dest</summary>
|
||||
Multiply,
|
||||
|
||||
/// <summary>No blending</summary>
|
||||
None
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Abstract base class for every object that can be drawn
|
||||
/// into a render window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract class Drawable : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Position of the object on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract Vector2 Position {get; set;}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Rotation of the object, defined in degrees
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract float Rotation {get; set;}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Vertical and horizontal scale of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract Vector2 Scale {get; set;}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Center of the transformation of the object
|
||||
/// (center of translation, rotation and scale)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract Vector2 Center {get; set;}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Global color of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract Color Color {get; set;}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Blending mode of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract BlendMode BlendMode {get; set;}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from global coordinates into local coordinates
|
||||
/// (ie it applies the inverse of object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract Vector2 TransformToLocal(Vector2 point);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from local coordinates into global coordinates
|
||||
/// (ie it applies the object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract Vector2 TransformToGlobal(Vector2 point);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Render the object into the given render window
|
||||
/// </summary>
|
||||
/// <param name="window">Target window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
internal abstract void Render(RenderWindow window);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Internal constructor, for derived classes
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Pointer to the object in C library</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected Drawable(IntPtr thisPtr) :
|
||||
base(thisPtr)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
210
dotnet/src/Graphics/Font.cs
Normal file
210
dotnet/src/Graphics/Font.cs
Normal file
|
@ -0,0 +1,210 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Font is the low-level class for loading and
|
||||
/// manipulating character fonts. This class is meant to
|
||||
/// be used by String2D
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Font : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the font from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Font file to load</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Font(string filename) :
|
||||
this(filename, 30)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the font from a file, using custom size
|
||||
/// </summary>
|
||||
/// <param name="filename">Font file to load</param>
|
||||
/// <param name="charSize">Character size</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Font(string filename, uint charSize) :
|
||||
this(filename, charSize, "")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the font from a file, using custom size and characters set
|
||||
/// </summary>
|
||||
/// <param name="filename">Font file to load</param>
|
||||
/// <param name="charSize">Character size</param>
|
||||
/// <param name="charset">Set of characters to generate</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Font(string filename, uint charSize, string charset) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
IntPtr ptr;
|
||||
int size;
|
||||
if (Int32.TryParse(charset, out size))
|
||||
ptr = new IntPtr(&size);
|
||||
else
|
||||
ptr = IntPtr.Zero;
|
||||
|
||||
SetThis(sfFont_CreateFromFile(filename, charSize, ptr));
|
||||
}
|
||||
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("font", filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the font from a file in a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Font(Stream stream) :
|
||||
this(stream, 30)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the font from a file in a stream, using custom size
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
/// <param name="charSize">Character size</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Font(Stream stream, uint charSize) :
|
||||
this(stream, charSize, "")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the font from a file in a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
/// <param name="charSize">Character size</param>
|
||||
/// <param name="charset">Set of characters to generate</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Font(Stream stream, uint charSize, string charset) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
IntPtr ptr;
|
||||
int size;
|
||||
if (Int32.TryParse(charset, out size))
|
||||
ptr = new IntPtr(&size);
|
||||
else
|
||||
ptr = IntPtr.Zero;
|
||||
|
||||
stream.Position = 0;
|
||||
byte[] StreamData = new byte[stream.Length];
|
||||
uint Read = (uint)stream.Read(StreamData, 0, StreamData.Length);
|
||||
fixed (byte* dataPtr = StreamData)
|
||||
{
|
||||
SetThis(sfFont_CreateFromMemory((char*)dataPtr, Read, charSize, ptr));
|
||||
}
|
||||
}
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("font");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Base character size
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint CharacterSize
|
||||
{
|
||||
get { return sfFont_GetCharacterSize(This); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default built-in font
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Font DefaultFont
|
||||
{
|
||||
get
|
||||
{
|
||||
if (ourDefaultFont == null)
|
||||
ourDefaultFont = new Font(sfFont_GetDefaultFont());
|
||||
|
||||
return ourDefaultFont;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
if (this != ourDefaultFont)
|
||||
{
|
||||
if (!disposing)
|
||||
Context.Global.SetActive(true);
|
||||
|
||||
sfFont_Destroy(This);
|
||||
|
||||
if (!disposing)
|
||||
Context.Global.SetActive(false);
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Internal constructor
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Pointer to the object in C library</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
private Font(IntPtr thisPtr) :
|
||||
base(thisPtr)
|
||||
{
|
||||
}
|
||||
|
||||
private static Font ourDefaultFont = null;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfFont_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfFont_CreateFromFile(string Filename, uint CharSize, IntPtr Charset);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfFont_CreateFromMemory(char* Data, uint SizeInBytes, uint CharSize, IntPtr Charset);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfFont_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfFont_GetCharacterSize(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfFont_GetDefaultFont();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
385
dotnet/src/Graphics/Image.cs
Normal file
385
dotnet/src/Graphics/Image.cs
Normal file
|
@ -0,0 +1,385 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.IO;
|
||||
using System.Runtime.ConstrainedExecution;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Image is the low-level class for loading and
|
||||
/// manipulating images
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Image : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor (invalid image)
|
||||
/// </summary>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image() :
|
||||
base(sfImage_Create())
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("image");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the image with black color
|
||||
/// </summary>
|
||||
/// <param name="width">Image width</param>
|
||||
/// <param name="height">Image height</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image(uint width, uint height) :
|
||||
this(width, height, Color.Black)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the image from a single color
|
||||
/// </summary>
|
||||
/// <param name="width">Image width</param>
|
||||
/// <param name="height">Image height</param>
|
||||
/// <param name="color">Color to fill the image with</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image(uint width, uint height, Color color) :
|
||||
base(sfImage_CreateFromColor(width, height, color))
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("image");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the image from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the image file to load</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image(string filename) :
|
||||
base(sfImage_CreateFromFile(filename))
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("image", filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the image from a file in a stream
|
||||
/// </summary>
|
||||
/// <param name="stream">Stream containing the file contents</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image(Stream stream) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
stream.Position = 0;
|
||||
byte[] StreamData = new byte[stream.Length];
|
||||
uint Read = (uint)stream.Read(StreamData, 0, StreamData.Length);
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* dataPtr = StreamData)
|
||||
{
|
||||
SetThis(sfImage_CreateFromMemory((char*)dataPtr, Read));
|
||||
}
|
||||
}
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("image");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the image directly from an array of pixels
|
||||
/// </summary>
|
||||
/// <param name="pixels">2 dimensions array containing the pixels</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image(Color[,] pixels) :
|
||||
base(IntPtr.Zero)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (Color* PixelsPtr = pixels)
|
||||
{
|
||||
uint Width = (uint)pixels.GetLength(0);
|
||||
uint Height = (uint)pixels.GetLength(1);
|
||||
SetThis(sfImage_CreateFromPixels(Width, Height, PixelsPtr));
|
||||
}
|
||||
}
|
||||
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("image");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Save the contents of the image to a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the file to save (overwritten if already exist)</param>
|
||||
/// <returns>True if saving was successful</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool SaveToFile(string filename)
|
||||
{
|
||||
return sfImage_SaveToFile(This, filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a transparency mask from a specified colorkey
|
||||
/// </summary>
|
||||
/// <param name="color">Color to become transparent</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void CreateMaskFromColor(Color color)
|
||||
{
|
||||
CreateMaskFromColor(color, 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a transparency mask from a specified colorkey
|
||||
/// </summary>
|
||||
/// <param name="color">Color to become transparent</param>
|
||||
/// <param name="alpha">Alpha value to use for transparent pixels</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void CreateMaskFromColor(Color color, byte alpha)
|
||||
{
|
||||
sfImage_CreateMaskFromColor(This, color, alpha);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Copy pixels from another image onto this one.
|
||||
/// This function does a slow pixel copy and should only
|
||||
/// be used at initialization time
|
||||
/// </summary>
|
||||
/// <param name="source">Source image to copy</param>
|
||||
/// <param name="destX">X coordinate of the destination position</param>
|
||||
/// <param name="destY">Y coordinate of the destination position</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Copy(Image source, uint destX, uint destY)
|
||||
{
|
||||
sfImage_Copy(This, source.This, destX, destY, new IntRect(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Copy pixels from another image onto this one.
|
||||
/// This function does a slow pixel copy and should only
|
||||
/// be used at initialization time
|
||||
/// </summary>
|
||||
/// <param name="source">Source image to copy</param>
|
||||
/// <param name="destX">X coordinate of the destination position</param>
|
||||
/// <param name="destY">Y coordinate of the destination position</param>
|
||||
/// <param name="sourceRect">Sub-rectangle of the source image to copy</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Copy(Image source, uint destX, uint destY, IntRect sourceRect)
|
||||
{
|
||||
sfImage_Copy(This, source.This, destX, destY, sourceRect);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the image from the current contents of the
|
||||
/// given window
|
||||
/// </summary>
|
||||
/// <param name="window">Window to capture</param>
|
||||
/// <returns>True if copy has been successful</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool CopyScreen(RenderWindow window)
|
||||
{
|
||||
return CopyScreen(window, new IntRect(0, 0, 0, 0));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the image from the current contents of the
|
||||
/// given window
|
||||
/// </summary>
|
||||
/// <param name="window">Window to capture</param>
|
||||
/// <param name="sourceRect">Sub-rectangle of the screen to copy</param>
|
||||
/// <returns>True if copy has been successful</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool CopyScreen(RenderWindow window, IntRect sourceRect)
|
||||
{
|
||||
return sfImage_CopyScreen(This, window.This, sourceRect);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get a pixel from the image
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of pixel in the image</param>
|
||||
/// <param name="y">Y coordinate of pixel in the image</param>
|
||||
/// <returns>Color of pixel (x, y)</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Color GetPixel(uint x, uint y)
|
||||
{
|
||||
return sfImage_GetPixel(This, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the color of a pixel
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of pixel in the image</param>
|
||||
/// <param name="y">Y coordinate of pixel in the image</param>
|
||||
/// <param name="color">New color for pixel (x, y)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetPixel(uint x, uint y, Color color)
|
||||
{
|
||||
sfImage_SetPixel(This, x, y, color);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get a copy of the array of pixels (RGBA 8 bits integers components)
|
||||
/// Array size is Width x Height x 4
|
||||
/// </summary>
|
||||
/// <returns>Array of pixels</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public byte[] Pixels
|
||||
{
|
||||
get
|
||||
{
|
||||
byte[] PixelsPtr = new byte[Width * Height * 4];
|
||||
Marshal.Copy(sfImage_GetPixelsPtr(This), PixelsPtr, 0, PixelsPtr.Length);
|
||||
return PixelsPtr;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Bind the image for rendering
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Bind()
|
||||
{
|
||||
sfImage_Bind(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Control the smooth filter
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Smooth
|
||||
{
|
||||
get {return sfImage_IsSmooth(This);}
|
||||
set {sfImage_SetSmooth(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Width of the image, in pixels
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint Width
|
||||
{
|
||||
get {return sfImage_GetWidth(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Height of the image, in pixels
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint Height
|
||||
{
|
||||
get {return sfImage_GetHeight(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Internal constructor
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Pointer to the object in C library</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
internal Image(IntPtr thisPtr) :
|
||||
base(thisPtr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
if (!disposing)
|
||||
Context.Global.SetActive(true);
|
||||
|
||||
sfImage_Destroy(This);
|
||||
|
||||
if (!disposing)
|
||||
Context.Global.SetActive(false);
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfImage_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfImage_CreateFromColor(uint Width, uint Height, Color Col);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfImage_CreateFromPixels(uint Width, uint Height, Color* Pixels);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfImage_CreateFromFile(string Filename);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern IntPtr sfImage_CreateFromMemory(char* Data, uint Size);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfImage_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfImage_SaveToFile(IntPtr This, string Filename);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfImage_CreateMaskFromColor(IntPtr This, Color Col, byte Alpha);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfImage_CopyScreen(IntPtr This, IntPtr Window, IntRect SourceRect);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfImage_Copy(IntPtr This, IntPtr Source, uint DestX, uint DestY, IntRect SourceRect);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfImage_SetPixel(IntPtr This, uint X, uint Y, Color Col);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfImage_GetPixel(IntPtr This, uint X, uint Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfImage_GetPixelsPtr(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfImage_Bind(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfImage_SetSmooth(IntPtr This, bool Smooth);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfImage_GetWidth(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfImage_GetHeight(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfImage_IsSmooth(IntPtr This);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
193
dotnet/src/Graphics/PostFx.cs
Normal file
193
dotnet/src/Graphics/PostFx.cs
Normal file
|
@ -0,0 +1,193 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// PostFX is used to apply a post effect to a window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class PostFx : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor (invalid effect)
|
||||
/// </summary>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public PostFx() :
|
||||
base(sfPostFx_Create())
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("post-fx");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Load the effect from a file
|
||||
/// </summary>
|
||||
/// <param name="filename">Path of the effect file to load</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
public PostFx(string filename) :
|
||||
base(sfPostFX_CreateFromFile(filename))
|
||||
{
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("post-fx", filename);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Load the effect from a text in memory
|
||||
/// </summary>
|
||||
/// <param name="effect">String containing the effect code</param>
|
||||
/// <exception cref="LoadingFailedException" />
|
||||
////////////////////////////////////////////////////////////
|
||||
void LoadFromString(string effect)
|
||||
{
|
||||
SetThis(sfPostFX_CreateFromMemory(effect));
|
||||
|
||||
if (This == IntPtr.Zero)
|
||||
throw new LoadingFailedException("post-fx");
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change a 1-component parameter of the effect
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the parameter in the effect</param>
|
||||
/// <param name="x">Value of the parameter</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetParameter(string name, float x)
|
||||
{
|
||||
sfPostFX_SetParameter1(This, name, x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change a 2-component parameter of the effect
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the parameter in the effect</param>
|
||||
/// <param name="x">X component of the value</param>
|
||||
/// <param name="y">Y component of the value</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetParameter(string name, float x, float y)
|
||||
{
|
||||
sfPostFX_SetParameter2(This, name, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change a 3-component parameter of the effect
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the parameter in the effect</param>
|
||||
/// <param name="x">X component of the value</param>
|
||||
/// <param name="y">Y component of the value</param>
|
||||
/// <param name="z">Z component of the value</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetParameter(string name, float x, float y, float z)
|
||||
{
|
||||
sfPostFX_SetParameter3(This, name, x, y, z);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change a 4-component parameter of the effect
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the parameter in the effect</param>
|
||||
/// <param name="x">X component of the value</param>
|
||||
/// <param name="y">Y component of the value</param>
|
||||
/// <param name="z">Z component of the value</param>
|
||||
/// <param name="w">W component of the value</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetParameter(string name, float x, float y, float z, float w)
|
||||
{
|
||||
sfPostFX_SetParameter4(This, name, x, y, z, w);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Set a texture parameter
|
||||
/// </summary>
|
||||
/// <param name="name">Name of the texture in the effect</param>
|
||||
/// <param name="texture">Image to set (pass null to use the contents of the screen)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetTexture(string name, Image texture)
|
||||
{
|
||||
myTextures[name] = texture;
|
||||
sfPostFX_SetTexture(This, name, texture != null ? texture.This : IntPtr.Zero);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Tell whether or not the system supports post-effects
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static bool CanUsePostFX
|
||||
{
|
||||
get {return sfPostFX_CanUsePostFX();}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
if (!disposing)
|
||||
Context.Global.SetActive(true);
|
||||
|
||||
myTextures.Clear();
|
||||
sfPostFX_Destroy(This);
|
||||
|
||||
if (!disposing)
|
||||
Context.Global.SetActive(false);
|
||||
}
|
||||
|
||||
Dictionary<string, Image> myTextures = new Dictionary<string, Image>();
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfPostFx_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfPostFx_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfPostFX_CreateFromFile(string Filename);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfPostFX_CreateFromMemory(string Effect);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfPostFX_Destroy(IntPtr PostFX);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfPostFX_SetParameter1(IntPtr PostFX, string Name, float X);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfPostFX_SetParameter2(IntPtr PostFX, string Name, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfPostFX_SetParameter3(IntPtr PostFX, string Name, float X, float Y, float Z);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfPostFX_SetParameter4(IntPtr PostFX, string Name, float X, float Y, float Z, float W);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfPostFX_SetTexture(IntPtr PostFX, string Name, IntPtr Texture);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfPostFX_CanUsePostFX();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
274
dotnet/src/Graphics/Rect.cs
Normal file
274
dotnet/src/Graphics/Rect.cs
Normal file
|
@ -0,0 +1,274 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// IntRect is an utility class for manipulating 2D rectangles
|
||||
/// with integer coordinates
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct IntRect
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the rectangle from its coordinates
|
||||
/// </summary>
|
||||
/// <param name="left">Left coordinate of the rectangle</param>
|
||||
/// <param name="top">Top coordinate of the rectangle</param>
|
||||
/// <param name="right">Right coordinate of the rectangle</param>
|
||||
/// <param name="bottom">Bottom coordinate of the rectangle</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public IntRect(int left, int top, int right, int bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Width of the rectangle
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public int Width
|
||||
{
|
||||
get {return Right - Left;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Height of the rectangle
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public int Height
|
||||
{
|
||||
get {return Bottom - Top;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Move the whole rectangle by the given offset
|
||||
/// </summary>
|
||||
/// <param name="offsetX">Horizontal offset</param>
|
||||
/// <param name="offsetY">Vertical offset</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Offset(int offsetX, int offsetY)
|
||||
{
|
||||
Left += offsetX;
|
||||
Top += offsetY;
|
||||
Right += offsetX;
|
||||
Bottom += offsetY;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Check if a point is inside the rectangle's area
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of the point to test</param>
|
||||
/// <param name="y">Y coordinate of the point to test</param>
|
||||
/// <returns>True if the point is inside</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Contains(int x, int y)
|
||||
{
|
||||
return (x >= Left) && (x <= Right) && (y >= Top) && (y <= Bottom);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Check intersection between two rectangles
|
||||
/// </summary>
|
||||
/// <param name="rect"> Rectangle to test</param>
|
||||
/// <returns>True if rectangles overlap</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Intersects(IntRect rect)
|
||||
{
|
||||
return ((Math.Max(Left, rect.Left) < Math.Min(Right, rect.Right)) &&
|
||||
(Math.Max(Top, rect.Top) < Math.Min(Bottom, rect.Bottom)));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Check intersection between two rectangles
|
||||
/// </summary>
|
||||
/// <param name="rect"> Rectangle to test</param>
|
||||
/// <param name="overlap">Rectangle to be filled with overlapping rect</param>
|
||||
/// <returns>True if rectangles overlap</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Intersects(IntRect rect, out IntRect overlap)
|
||||
{
|
||||
IntRect Overlapping = new IntRect(Math.Max(Left, rect.Left),
|
||||
Math.Max(Top, rect.Top),
|
||||
Math.Min(Right, rect.Right),
|
||||
Math.Min(Bottom, rect.Bottom));
|
||||
|
||||
if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom))
|
||||
{
|
||||
overlap.Left = Overlapping.Left;
|
||||
overlap.Top = Overlapping.Top;
|
||||
overlap.Right = Overlapping.Right;
|
||||
overlap.Bottom = Overlapping.Bottom;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlap.Left = 0;
|
||||
overlap.Top = 0;
|
||||
overlap.Right = 0;
|
||||
overlap.Bottom = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Left coordinate of the rectangle</summary>
|
||||
public int Left;
|
||||
|
||||
/// <summary>Top coordinate of the rectangle</summary>
|
||||
public int Top;
|
||||
|
||||
/// <summary>Right coordinate of the rectangle</summary>
|
||||
public int Right;
|
||||
|
||||
/// <summary>Bottom coordinate of the rectangle</summary>
|
||||
public int Bottom;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// FloatRect is an utility class for manipulating 2D rectangles
|
||||
/// with float coordinates
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct FloatRect
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the rectangle from its coordinates
|
||||
/// </summary>
|
||||
/// <param name="left">Left coordinate of the rectangle</param>
|
||||
/// <param name="top">Top coordinate of the rectangle</param>
|
||||
/// <param name="right">Right coordinate of the rectangle</param>
|
||||
/// <param name="bottom">Bottom coordinate of the rectangle</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public FloatRect(float left, float top, float right, float bottom)
|
||||
{
|
||||
Left = left;
|
||||
Top = top;
|
||||
Right = right;
|
||||
Bottom = bottom;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Width of the rectangle
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Width
|
||||
{
|
||||
get {return Right - Left;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Height of the rectangle
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Height
|
||||
{
|
||||
get {return Bottom - Top;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Move the whole rectangle by the given offset
|
||||
/// </summary>
|
||||
/// <param name="offsetX">Horizontal offset</param>
|
||||
/// <param name="offsetY">Vertical offset</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Offset(float offsetX, float offsetY)
|
||||
{
|
||||
Left += offsetX;
|
||||
Top += offsetY;
|
||||
Right += offsetX;
|
||||
Bottom += offsetY;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Check if a point is inside the rectangle's area
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of the point to test</param>
|
||||
/// <param name="y">Y coordinate of the point to test</param>
|
||||
/// <returns>True if the point is inside</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Contains(float x, float y)
|
||||
{
|
||||
return (x >= Left) && (x <= Right) && (y >= Top) && (y <= Bottom);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Check intersection between two rectangles
|
||||
/// </summary>
|
||||
/// <param name="rect"> Rectangle to test</param>
|
||||
/// <returns>True if rectangles overlap</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Intersects(FloatRect rect)
|
||||
{
|
||||
return ((Math.Max(Left, rect.Left) < Math.Min(Right, rect.Right)) &&
|
||||
(Math.Max(Top, rect.Top) < Math.Min(Bottom, rect.Bottom)));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Check intersection between two rectangles
|
||||
/// </summary>
|
||||
/// <param name="rect"> Rectangle to test</param>
|
||||
/// <param name="overlap">Rectangle to be filled with overlapping rect</param>
|
||||
/// <returns>True if rectangles overlap</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool Intersects(FloatRect rect, out FloatRect overlap)
|
||||
{
|
||||
FloatRect Overlapping = new FloatRect(Math.Max(Left, rect.Left),
|
||||
Math.Max(Top, rect.Top),
|
||||
Math.Min(Right, rect.Right),
|
||||
Math.Min(Bottom, rect.Bottom));
|
||||
|
||||
if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom))
|
||||
{
|
||||
overlap.Left = Overlapping.Left;
|
||||
overlap.Top = Overlapping.Top;
|
||||
overlap.Right = Overlapping.Right;
|
||||
overlap.Bottom = Overlapping.Bottom;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
overlap.Left = 0;
|
||||
overlap.Top = 0;
|
||||
overlap.Right = 0;
|
||||
overlap.Bottom = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>Left coordinate of the rectangle</summary>
|
||||
public float Left;
|
||||
|
||||
/// <summary>Top coordinate of the rectangle</summary>
|
||||
public float Top;
|
||||
|
||||
/// <summary>Right coordinate of the rectangle</summary>
|
||||
public float Right;
|
||||
|
||||
/// <summary>Bottom coordinate of the rectangle</summary>
|
||||
public float Bottom;
|
||||
}
|
||||
}
|
||||
}
|
558
dotnet/src/Graphics/RenderWindow.cs
Normal file
558
dotnet/src/Graphics/RenderWindow.cs
Normal file
|
@ -0,0 +1,558 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
using SFML.Window;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Simple wrapper for Window that allows easy
|
||||
/// 2D rendering
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class RenderWindow : SFML.Window.Window
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window with default style and creation settings
|
||||
/// </summary>
|
||||
/// <param name="mode">Video mode to use</param>
|
||||
/// <param name="title">Title of the window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public RenderWindow(VideoMode mode, string title) :
|
||||
this(mode, title, Styles.Resize | Styles.Close, new WindowSettings(24, 8, 0))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window with default creation settings
|
||||
/// </summary>
|
||||
/// <param name="mode">Video mode to use</param>
|
||||
/// <param name="title">Title of the window</param>
|
||||
/// <param name="style">Window style (Resize | Close by default)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public RenderWindow(VideoMode mode, string title, Styles style) :
|
||||
this(mode, title, style, new WindowSettings(24, 8, 0))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window
|
||||
/// </summary>
|
||||
/// <param name="mode">Video mode to use</param>
|
||||
/// <param name="title">Title of the window</param>
|
||||
/// <param name="style">Window style (Resize | Close by default)</param>
|
||||
/// <param name="settings">Creation parameters</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public RenderWindow(VideoMode mode, string title, Styles style, WindowSettings settings) :
|
||||
base(sfRenderWindow_Create(mode, title, style, settings), 0)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window from an existing control with default creation settings
|
||||
/// </summary>
|
||||
/// <param name="handle">Platform-specific handle of the control</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public RenderWindow(IntPtr handle) :
|
||||
this(handle, new WindowSettings(24, 8, 0))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window from an existing control
|
||||
/// </summary>
|
||||
/// <param name="handle">Platform-specific handle of the control</param>
|
||||
/// <param name="settings">Creation parameters</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public RenderWindow(IntPtr handle, WindowSettings settings) :
|
||||
base(sfRenderWindow_CreateFromHandle(handle, settings), 0)
|
||||
{
|
||||
Initialize();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Tell whether or not the window is opened (ie. has been created).
|
||||
/// Note that a hidden window (Show(false))
|
||||
/// will still return true
|
||||
/// </summary>
|
||||
/// <returns>True if the window is opened</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override bool IsOpened()
|
||||
{
|
||||
return sfRenderWindow_IsOpened(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Close (destroy) the window.
|
||||
/// The Window instance remains valid and you can call
|
||||
/// Create to recreate the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void Close()
|
||||
{
|
||||
sfRenderWindow_Close(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Display the window on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void Display()
|
||||
{
|
||||
sfRenderWindow_Display(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Width of the rendering region of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override uint Width
|
||||
{
|
||||
get {return sfRenderWindow_GetWidth(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Height of the rendering region of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override uint Height
|
||||
{
|
||||
get {return sfRenderWindow_GetHeight(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Creation settings of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override WindowSettings Settings
|
||||
{
|
||||
get {return sfRenderWindow_GetSettings(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enable / disable vertical synchronization
|
||||
/// </summary>
|
||||
/// <param name="enable">True to enable v-sync, false to deactivate</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void UseVerticalSync(bool enable)
|
||||
{
|
||||
sfRenderWindow_UseVerticalSync(This, enable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Show or hide the mouse cursor
|
||||
/// </summary>
|
||||
/// <param name="show">True to show, false to hide</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void ShowMouseCursor(bool show)
|
||||
{
|
||||
sfRenderWindow_ShowMouseCursor(This, show);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the position of the mouse cursor
|
||||
/// </summary>
|
||||
/// <param name="x">Left coordinate of the cursor, relative to the window</param>
|
||||
/// <param name="y">Top coordinate of the cursor, relative to the window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void SetCursorPosition(uint x, uint y)
|
||||
{
|
||||
sfRenderWindow_SetCursorPosition(This, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the position of the window on screen.
|
||||
/// Only works for top-level windows
|
||||
/// </summary>
|
||||
/// <param name="x">Left position</param>
|
||||
/// <param name="y">Top position</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void SetPosition(int x, int y)
|
||||
{
|
||||
sfRenderWindow_SetPosition(This, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the size of the rendering region of the window
|
||||
/// </summary>
|
||||
/// <param name="width">New width</param>
|
||||
/// <param name="height">New height</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void SetSize(uint width, uint height)
|
||||
{
|
||||
sfRenderWindow_SetSize(This, width, height);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Show or hide the window
|
||||
/// </summary>
|
||||
/// <param name="show">True to show, false to hide</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void Show(bool show)
|
||||
{
|
||||
sfRenderWindow_Show(This, show);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enable or disable automatic key-repeat.
|
||||
/// Automatic key-repeat is enabled by default
|
||||
/// </summary>
|
||||
/// <param name="enable">True to enable, false to disable</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void EnableKeyRepeat(bool enable)
|
||||
{
|
||||
sfRenderWindow_EnableKeyRepeat(This, enable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the window's icon
|
||||
/// </summary>
|
||||
/// <param name="width">Icon's width, in pixels</param>
|
||||
/// <param name="height">Icon's height, in pixels</param>
|
||||
/// <param name="pixels">Array of pixels, format must be RGBA 32 bits</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void SetIcon(uint width, uint height, byte[] pixels)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* PixelsPtr = pixels)
|
||||
{
|
||||
sfRenderWindow_SetIcon(This, width, height, PixelsPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Activate of deactivate the window as the current target
|
||||
/// for rendering
|
||||
/// </summary>
|
||||
/// <param name="active">True to activate, false to deactivate (true by default)</param>
|
||||
/// <returns>True if operation was successful, false otherwise</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override bool SetActive(bool active)
|
||||
{
|
||||
return sfRenderWindow_SetActive(This, active);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Limit the framerate to a maximum fixed frequency
|
||||
/// </summary>
|
||||
/// <param name="limit">Framerate limit, in frames per seconds (use 0 to disable limit)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void SetFramerateLimit(uint limit)
|
||||
{
|
||||
sfRenderWindow_SetFramerateLimit(This, limit);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get time elapsed since last frame
|
||||
/// </summary>
|
||||
/// <returns>Time elapsed, in seconds</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override float GetFrameTime()
|
||||
{
|
||||
return sfRenderWindow_GetFrameTime(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the joystick threshold, ie. the value below which
|
||||
/// no move event will be generated
|
||||
/// </summary>
|
||||
/// <param name="threshold">New threshold, in range [0, 100]</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override void SetJoystickThreshold(float threshold)
|
||||
{
|
||||
sfRenderWindow_SetJoystickThreshold(This, threshold);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default view of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public View DefaultView
|
||||
{
|
||||
get {return myDefaultView;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Current view active in the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public View CurrentView
|
||||
{
|
||||
get {return myCurrentView;}
|
||||
set {myCurrentView = value; sfRenderWindow_SetView(This, value.This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Convert a point in window coordinates into view coordinates
|
||||
/// using the current view of the window
|
||||
/// </summary>
|
||||
/// <param name="windowX">X coordinate of the point to convert, relative to the window</param>
|
||||
/// <param name="windowY">Y coordinate of the point to convert, relative to the window</param>
|
||||
/// <returns>Converted point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2 ConvertCoords(uint windowX, uint windowY)
|
||||
{
|
||||
return ConvertCoords(windowX, windowY, myCurrentView);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Convert a point in window coordinates into view coordinates
|
||||
/// </summary>
|
||||
/// <param name="windowX">X coordinate of the point to convert, relative to the window</param>
|
||||
/// <param name="windowY">Y coordinate of the point to convert, relative to the window</param>
|
||||
/// <param name="targetView">Target view to convert the point to</param>
|
||||
/// <returns>Converted point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2 ConvertCoords(uint windowX, uint windowY, View targetView)
|
||||
{
|
||||
Vector2 Point;
|
||||
sfRenderWindow_ConvertCoords(This, windowX, windowY, out Point.X, out Point.Y, targetView.This);
|
||||
|
||||
return Point;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Tell SFML to preserve external OpenGL states, at the expense of
|
||||
/// more CPU charge. Use this function if you don't want SFML
|
||||
/// to mess up your own OpenGL states (if any).
|
||||
/// Don't enable state preservation if not needed, as it will allow
|
||||
/// SFML to do internal optimizations and improve performances.
|
||||
/// This parameter is false by default
|
||||
/// </summary>
|
||||
/// <param name="preserve">True to preserve OpenGL states, false to let SFML optimize</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void PreserveOpenGLStates(bool preserve)
|
||||
{
|
||||
sfRenderWindow_PreserveOpenGLStates(This, preserve);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Clear the entire window with black color
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Clear()
|
||||
{
|
||||
sfRenderWindow_Clear(This, Color.Black);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Clear the entire window with a single color
|
||||
/// </summary>
|
||||
/// <param name="color">Color to use to clear the window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Clear(Color color)
|
||||
{
|
||||
sfRenderWindow_Clear(This, color);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Save the content of the window to an image
|
||||
/// </summary>
|
||||
/// <returns>Image instance containing the contents of the screen</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image Capture()
|
||||
{
|
||||
return new Image(sfRenderWindow_Capture(This));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Draw something into the window
|
||||
/// </summary>
|
||||
/// <param name="objectToDraw">Object to draw</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Draw(Drawable objectToDraw)
|
||||
{
|
||||
objectToDraw.Render(this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Apply a post-fx to the window
|
||||
/// </summary>
|
||||
/// <param name="postFx">PostFx to apply</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Draw(PostFx postFx)
|
||||
{
|
||||
sfRenderWindow_DrawPostFX(This, postFx != null ? postFx.This : IntPtr.Zero);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Internal function to get the next event
|
||||
/// </summary>
|
||||
/// <param name="eventToFill">Variable to fill with the raw pointer to the event structure</param>
|
||||
/// <returns>True if there was an event, false otherwise</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override bool GetEvent(out Event eventToFill)
|
||||
{
|
||||
return sfRenderWindow_GetEvent(This, out eventToFill);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfRenderWindow_Destroy(This);
|
||||
|
||||
if (disposing)
|
||||
myDefaultView.Dispose();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Do common initializations
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
private void Initialize()
|
||||
{
|
||||
myInput = new Input(sfRenderWindow_GetInput(This));
|
||||
myDefaultView = new View(sfRenderWindow_GetDefaultView(This));
|
||||
myCurrentView = myDefaultView;
|
||||
GC.SuppressFinalize(myDefaultView);
|
||||
}
|
||||
|
||||
private View myCurrentView = null;
|
||||
private View myDefaultView = null;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfRenderWindow_Create(VideoMode Mode, string Title, Styles Style, WindowSettings Params);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfRenderWindow_CreateFromHandle(IntPtr Handle, WindowSettings Params);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfRenderWindow_GetInput(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfRenderWindow_IsOpened(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_Close(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfRenderWindow_GetEvent(IntPtr This, out Event Evt);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfRenderWindow_Capture(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_Clear(IntPtr This, Color ClearColor);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_Display(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfRenderWindow_GetWidth(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfRenderWindow_GetHeight(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern WindowSettings sfRenderWindow_GetSettings(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_UseVerticalSync(IntPtr This, bool Enable);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_ShowMouseCursor(IntPtr This, bool Show);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_SetCursorPosition(IntPtr This, uint X, uint Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_SetPosition(IntPtr This, int X, int Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_SetSize(IntPtr This, uint Width, uint Height);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_Show(IntPtr This, bool Show);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_EnableKeyRepeat(IntPtr This, bool Enable);
|
||||
|
||||
[DllImport("csfml-graphics")]
|
||||
unsafe static extern void sfRenderWindow_SetIcon(IntPtr This, uint Width, uint Height, byte* Pixels);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfRenderWindow_SetActive(IntPtr This, bool Active);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_SetFramerateLimit(IntPtr This, uint Limit);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfRenderWindow_GetFrameTime(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_SetJoystickThreshold(IntPtr This, float Threshold);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_SetView(IntPtr This, IntPtr View);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfRenderWindow_GetView(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfRenderWindow_GetDefaultView(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_ConvertCoords(IntPtr This, uint WindowX, uint WindowY, out float ViewX, out float ViewY, IntPtr TargetView);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_PreserveOpenGLStates(IntPtr This, bool Preserve);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_DrawPostFX(IntPtr This, IntPtr PostFx);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
505
dotnet/src/Graphics/Shape.cs
Normal file
505
dotnet/src/Graphics/Shape.cs
Normal file
|
@ -0,0 +1,505 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Shape defines a drawable convex shape ; it also defines
|
||||
/// helper functions to draw simple shapes like
|
||||
/// lines, rectangles, circles, etc.
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Shape : Drawable
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Shape() :
|
||||
base(sfShape_Create())
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Position of the object on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Position
|
||||
{
|
||||
get { return new Vector2(sfShape_GetX(This), sfShape_GetY(This)); }
|
||||
set { sfShape_SetPosition(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Rotation of the object, defined in degrees
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override float Rotation
|
||||
{
|
||||
get { return sfShape_GetRotation(This); }
|
||||
set { sfShape_SetRotation(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Vertical and horizontal scale of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Scale
|
||||
{
|
||||
get { return new Vector2(sfShape_GetScaleX(This), sfShape_GetScaleY(This)); }
|
||||
set { sfShape_SetScale(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Center of the transformation of the object
|
||||
/// (center of translation, rotation and scale)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Center
|
||||
{
|
||||
get { return new Vector2(sfShape_GetCenterX(This), sfShape_GetCenterY(This)); }
|
||||
set { sfShape_SetCenter(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Global color of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Color Color
|
||||
{
|
||||
get { return sfShape_GetColor(This); }
|
||||
set { sfShape_SetColor(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Blending mode of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override BlendMode BlendMode
|
||||
{
|
||||
get { return sfShape_GetBlendMode(This); }
|
||||
set { sfShape_SetBlendMode(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from global coordinates into local coordinates
|
||||
/// (ie it applies the inverse of object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 TransformToLocal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfShape_TransformToLocal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from local coordinates into global coordinates
|
||||
/// (ie it applies the object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 TransformToGlobal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfShape_TransformToGlobal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Add a point to the shape
|
||||
/// </summary>
|
||||
/// <param name="position">Position of the point</param>
|
||||
/// <param name="color">Color of the point</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void AddPoint(Vector2 position, Color color)
|
||||
{
|
||||
AddPoint(position, color, Color.Black);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Add a point to the shape
|
||||
/// </summary>
|
||||
/// <param name="position">Position of the point</param>
|
||||
/// <param name="color">Color of the point</param>
|
||||
/// <param name="outlineColor">Outline color of the point</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void AddPoint(Vector2 position, Color color, Color outlineColor)
|
||||
{
|
||||
sfShape_AddPoint(This, position.X, position.Y, color, outlineColor);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enable or disable filling the shape.
|
||||
/// Fill is enabled by default
|
||||
/// </summary>
|
||||
/// <param name="enable">True to enable, false to disable</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void EnableFill(bool enable)
|
||||
{
|
||||
sfShape_EnableFill(This, enable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enable or disable drawing the shape outline.
|
||||
/// Outline is enabled by default
|
||||
/// </summary>
|
||||
/// <param name="enable">True to enable, false to disable</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void EnableOutline(bool enable)
|
||||
{
|
||||
sfShape_EnableOutline(This, enable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Width of the shape outline
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float OutlineWidth
|
||||
{
|
||||
get {return sfShape_GetOutlineWidth(This);}
|
||||
set {sfShape_SetOutlineWidth(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Totla number of points of the shape
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public uint NbPoints
|
||||
{
|
||||
get {return sfShape_GetNbPoints(This);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Set the position of a point
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the point, in range [0, NbPoints - 1]</param>
|
||||
/// <param name="position">New position of the index-th point</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetPointPosition(uint index, Vector2 position)
|
||||
{
|
||||
sfShape_SetPointPosition(This, index, position.X, position.Y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the position of a point
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the point, in range [0, NbPoints - 1]</param>
|
||||
/// <returns>Position of the index-th point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2 GetPointPosition(uint index)
|
||||
{
|
||||
Vector2 Pos;
|
||||
sfShape_GetPointPosition(This, index, out Pos.X, out Pos.Y);
|
||||
|
||||
return Pos;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Set the color of a point
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the point, in range [0, NbPoints - 1]</param>
|
||||
/// <param name="color">New color of the index-th point</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetPointColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointColor(This, index, color);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the color of a point
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the point, in range [0, NbPoints - 1]</param>
|
||||
/// <returns>Color of the index-th point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Color GetPointColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointColor(This, index);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Set the outline color of a point
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the point, in range [0, NbPoints - 1]</param>
|
||||
/// <param name="color">New outline color of the index-th point</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetPointOutlineColor(uint index, Color color)
|
||||
{
|
||||
sfShape_SetPointOutlineColor(This, index, color);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the outline color of a point
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the point, in range [0, NbPoints - 1]</param>
|
||||
/// <returns>Outline color of the index-th point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Color GetPointOutlineColor(uint index)
|
||||
{
|
||||
return sfShape_GetPointOutlineColor(This, index);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a shape made of a single line
|
||||
/// </summary>
|
||||
/// <param name="p1">Position of the first point</param>
|
||||
/// <param name="p2">Position of the second point</param>
|
||||
/// <param name="thickness">Line thickness</param>
|
||||
/// <param name="color">Color used to draw the line</param>
|
||||
/// <returns>New line shape built with the given parameters</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Shape Line(Vector2 p1, Vector2 p2, float thickness, Color color)
|
||||
{
|
||||
return Line(p1, p2, thickness, color, 0, Color.White);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a shape made of a single line
|
||||
/// </summary>
|
||||
/// <param name="p1">Position of the first point</param>
|
||||
/// <param name="p2">Position of the second point</param>
|
||||
/// <param name="thickness">Line thickness</param>
|
||||
/// <param name="color">Color used to draw the line</param>
|
||||
/// <param name="outline">Outline width</param>
|
||||
/// <param name="outlineColor">Color used to draw the outline</param>
|
||||
/// <returns>New line shape built with the given parameters</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Shape Line(Vector2 p1, Vector2 p2, float thickness, Color color, float outline, Color outlineColor)
|
||||
{
|
||||
return new Shape(sfShape_CreateLine(p1.X, p1.Y, p2.X, p2.Y, thickness, color, outline, outlineColor));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a shape made of a single rectangle
|
||||
/// </summary>
|
||||
/// <param name="p1">Position of the top-left corner</param>
|
||||
/// <param name="p2">Position of the bottom-right corner</param>
|
||||
/// <param name="color">Color used to fill the rectangle</param>
|
||||
/// <returns>New rectangle shape built with the given parameters</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Shape Rectangle(Vector2 p1, Vector2 p2, Color color)
|
||||
{
|
||||
return Rectangle(p1, p2, color, 0, Color.White);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a shape made of a single rectangle
|
||||
/// </summary>
|
||||
/// <param name="p1">Position of the top-left corner</param>
|
||||
/// <param name="p2">Position of the bottom-right corner</param>
|
||||
/// <param name="color">Color used to fill the rectangle</param>
|
||||
/// <param name="outline">Outline width</param>
|
||||
/// <param name="outlineColor">Color used to draw the outline</param>
|
||||
/// <returns>New rectangle shape built with the given parameters</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Shape Rectangle(Vector2 p1, Vector2 p2, Color color, float outline, Color outlineColor)
|
||||
{
|
||||
return new Shape(sfShape_CreateRectangle(p1.X, p1.Y, p2.X, p2.Y, color, outline, outlineColor));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a shape made of a single circle
|
||||
/// </summary>
|
||||
/// <param name="center">Position of the center</param>
|
||||
/// <param name="radius">Radius of the circle</param>
|
||||
/// <param name="color">Color used to fill the circle</param>
|
||||
/// <returns>New circle shape built with the given parameters</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Shape Circle(Vector2 center, float radius, Color color)
|
||||
{
|
||||
return Circle(center, radius, color, 0, Color.White);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a shape made of a single circle
|
||||
/// </summary>
|
||||
/// <param name="center">Position of the center</param>
|
||||
/// <param name="radius">Radius of the circle</param>
|
||||
/// <param name="color">Color used to fill the circle</param>
|
||||
/// <param name="outline">Outline width</param>
|
||||
/// <param name="outlineColor">Color used to draw the outline</param>
|
||||
/// <returns>New circle shape built with the given parameters</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Shape Circle(Vector2 center, float radius, Color color, float outline, Color outlineColor)
|
||||
{
|
||||
return new Shape(sfShape_CreateCircle(center.X, center.Y, radius, color, outline, outlineColor));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Render the object into the given render window
|
||||
/// </summary>
|
||||
/// <param name="window">Target window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
internal override void Render(RenderWindow window)
|
||||
{
|
||||
sfRenderWindow_DrawShape(window.This, This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfShape_Destroy(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Internal constructor
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Pointer to the internal object in C library</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
private Shape(IntPtr thisPtr) :
|
||||
base(thisPtr)
|
||||
{
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfShape_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetPosition(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetRotation(IntPtr This, float Rotation);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetRotation(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetScale(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetScaleX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetScaleY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetCenter(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetCenterX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetCenterY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetColor(IntPtr This, Color Color);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfShape_GetColor(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetBlendMode(IntPtr This, BlendMode Mode);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern BlendMode sfShape_GetBlendMode(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfShape_TransformToLocal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfShape_TransformToGlobal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_DrawShape(IntPtr This, IntPtr Shape);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfShape_CreateLine(float P1X, float P1Y, float P2X, float P2Y, float Thickness, Color Col, float Outline, Color OutlineCol);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfShape_CreateRectangle(float P1X, float P1Y, float P2X, float P2Y, Color Col, float Outline, Color OutlineCol);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfShape_CreateCircle(float X, float Y, float Radius, Color Col, float Outline, Color OutlineCol);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_AddPoint(IntPtr This, float X, float Y, Color Col, Color OutlineCol);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_EnableFill(IntPtr This, bool Enable);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_EnableOutline(IntPtr This, bool Enable);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetOutlineWidth(IntPtr This, float Width);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfShape_GetOutlineWidth(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfShape_GetNbPoints(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetPointPosition(IntPtr This, uint Index, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_GetPointPosition(IntPtr This, uint Index, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetPointColor(IntPtr This, uint Index, Color Col);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfShape_GetPointColor(IntPtr This, uint Index);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfShape_SetPointOutlineColor(IntPtr This, uint Index, Color Col);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfShape_GetPointOutlineColor(IntPtr This, uint Index);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
332
dotnet/src/Graphics/Sprite.cs
Normal file
332
dotnet/src/Graphics/Sprite.cs
Normal file
|
@ -0,0 +1,332 @@
|
|||
using System;
|
||||
using System.Security;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// This class defines a sprite : texture, transformations,
|
||||
/// color, and draw on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Sprite : Drawable
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Sprite() :
|
||||
base(sfSprite_Create())
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the sprite from a source image
|
||||
/// </summary>
|
||||
/// <param name="image">Source image to assign to the sprite</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Sprite(Image image) :
|
||||
base(sfSprite_Create())
|
||||
{
|
||||
Image = image;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Position of the object on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Position
|
||||
{
|
||||
get { return new Vector2(sfSprite_GetX(This), sfSprite_GetY(This)); }
|
||||
set { sfSprite_SetPosition(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Rotation of the object, defined in degrees
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override float Rotation
|
||||
{
|
||||
get { return sfSprite_GetRotation(This); }
|
||||
set { sfSprite_SetRotation(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Vertical and horizontal scale of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Scale
|
||||
{
|
||||
get { return new Vector2(sfSprite_GetScaleX(This), sfSprite_GetScaleY(This)); }
|
||||
set { sfSprite_SetScale(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Center of the transformation of the object
|
||||
/// (center of translation, rotation and scale)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Center
|
||||
{
|
||||
get { return new Vector2(sfSprite_GetCenterX(This), sfSprite_GetCenterY(This)); }
|
||||
set { sfSprite_SetCenter(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Global color of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Color Color
|
||||
{
|
||||
get { return sfSprite_GetColor(This); }
|
||||
set { sfSprite_SetColor(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Blending mode of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override BlendMode BlendMode
|
||||
{
|
||||
get { return sfSprite_GetBlendMode(This); }
|
||||
set { sfSprite_SetBlendMode(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from global coordinates into local coordinates
|
||||
/// (ie it applies the inverse of object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 TransformToLocal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfSprite_TransformToLocal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from local coordinates into global coordinates
|
||||
/// (ie it applies the object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 TransformToGlobal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfSprite_TransformToGlobal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Width of the sprite
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Width
|
||||
{
|
||||
get { return sfSprite_GetWidth(This); }
|
||||
set { sfSprite_Resize(This, value, this.Height); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Height of the sprite
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Height
|
||||
{
|
||||
get { return sfSprite_GetHeight(This); }
|
||||
set { sfSprite_Resize(This, this.Width, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Source images displayed by the sprite
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Image Image
|
||||
{
|
||||
get { return myImage; }
|
||||
set { myImage = value; sfSprite_SetImage(This, value != null ? value.This : IntPtr.Zero); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Sub-rectangle of the source image displayed by the sprite
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public IntRect SubRect
|
||||
{
|
||||
get { return sfSprite_GetSubRect(This); }
|
||||
set { sfSprite_SetSubRect(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Flip the sprite horizontically
|
||||
/// </summary>
|
||||
/// <param name="flipped">True to flip, false to canel flip</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void FlipX(bool flipped)
|
||||
{
|
||||
sfSprite_FlipX(This, flipped);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Flip the sprite vertically
|
||||
/// </summary>
|
||||
/// <param name="flipped">True to flip, false to canel flip</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void FlipY(bool flipped)
|
||||
{
|
||||
sfSprite_FlipY(This, flipped);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the color of a given pixel in the sprite
|
||||
/// (point is in local coordinates)
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate of the pixel to get</param>
|
||||
/// <param name="y">Y coordinate of the pixel to get</param>
|
||||
/// <returns>Color of pixel (x, y)</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Color GetPixel(uint x, uint y)
|
||||
{
|
||||
return sfSprite_GetPixel(This, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Render the object into the given render window
|
||||
/// </summary>
|
||||
/// <param name="window">Target window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
internal override void Render(RenderWindow window)
|
||||
{
|
||||
sfRenderWindow_DrawSprite(window.This, This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfSprite_Destroy(This);
|
||||
}
|
||||
|
||||
private Image myImage = null;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfSprite_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetPosition(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetRotation(IntPtr This, float Rotation);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetRotation(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetScale(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetScaleX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetScaleY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetCenter(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetCenterX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetCenterY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetColor(IntPtr This, Color Color);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfSprite_GetColor(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetBlendMode(IntPtr This, BlendMode Mode);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern BlendMode sfSprite_GetBlendMode(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfSprite_TransformToLocal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfSprite_TransformToGlobal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_DrawSprite(IntPtr This, IntPtr Sprite);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_Resize(IntPtr This, float Width, float Height);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetWidth(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfSprite_GetHeight(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetImage(IntPtr This, IntPtr Image);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_SetSubRect(IntPtr This, IntRect Rect);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntRect sfSprite_GetSubRect(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_FlipX(IntPtr This, bool Flipped);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfSprite_FlipY(IntPtr This, bool Flipped);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfSprite_GetPixel(IntPtr This, uint X, uint Y);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
380
dotnet/src/Graphics/String2D.cs
Normal file
380
dotnet/src/Graphics/String2D.cs
Normal file
|
@ -0,0 +1,380 @@
|
|||
using System;
|
||||
using System.Security;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// This class defines a graphical 2D text, that can be drawn on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class String2D : Drawable
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enumerate the string drawing styles
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[Flags]
|
||||
public enum Styles
|
||||
{
|
||||
/// <summary>Regular characters, no style</summary>
|
||||
Regular = 0,
|
||||
|
||||
/// <summary> Characters are bold</summary>
|
||||
Bold = 1 << 0,
|
||||
|
||||
/// <summary>Characters are in italic</summary>
|
||||
Italic = 1 << 1,
|
||||
|
||||
/// <summary>Characters are underlined</summary>
|
||||
Underlined = 1 << 2
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D() :
|
||||
this("")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the string from a text
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D(string text) :
|
||||
this(text, Font.DefaultFont)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the string from a text and a font
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="font">Font to use</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D(string text, Font font) :
|
||||
this(text, font, 30)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the string from a text, font and size
|
||||
/// </summary>
|
||||
/// <param name="text">Text to display</param>
|
||||
/// <param name="font">Font to use</param>
|
||||
/// <param name="size">Base characters size</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public String2D(string text, Font font, uint size) :
|
||||
base(sfString_Create())
|
||||
{
|
||||
Text = text;
|
||||
Font = font;
|
||||
Size = size;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Position of the object on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Position
|
||||
{
|
||||
get { return new Vector2(sfString_GetX(This), sfString_GetY(This)); }
|
||||
set { sfString_SetPosition(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Rotation of the object, defined in degrees
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override float Rotation
|
||||
{
|
||||
get { return sfString_GetRotation(This); }
|
||||
set { sfString_SetRotation(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Vertical and horizontal scale of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Scale
|
||||
{
|
||||
get { return new Vector2(sfString_GetScaleX(This), sfString_GetScaleY(This)); }
|
||||
set { sfString_SetScale(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Center of the transformation of the object
|
||||
/// (center of translation, rotation and scale)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 Center
|
||||
{
|
||||
get { return new Vector2(sfString_GetCenterX(This), sfString_GetCenterY(This)); }
|
||||
set { sfString_SetCenter(This, value.X, value.Y); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Global color of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Color Color
|
||||
{
|
||||
get { return sfString_GetColor(This); }
|
||||
set { sfString_SetColor(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Blending mode of the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override BlendMode BlendMode
|
||||
{
|
||||
get { return sfString_GetBlendMode(This); }
|
||||
set { sfString_SetBlendMode(This, value); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from global coordinates into local coordinates
|
||||
/// (ie it applies the inverse of object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 TransformToLocal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfString_TransformToLocal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Transform a point from local coordinates into global coordinates
|
||||
/// (ie it applies the object's center, translation, rotation and scale to the point)
|
||||
/// </summary>
|
||||
/// <param name="point">Point to transform</param>
|
||||
/// <returns>Transformed point</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public override Vector2 TransformToGlobal(Vector2 point)
|
||||
{
|
||||
Vector2 Transformed;
|
||||
sfString_TransformToGlobal(This, point.X, point.Y, out Transformed.X, out Transformed.Y);
|
||||
|
||||
return Transformed;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Text displayed
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public string Text
|
||||
{
|
||||
// TODO : use unicode functions
|
||||
// (convert from UTF-16 to UTF-32, and find how to marshal System.String as sfUint32*...)
|
||||
get {return sfString_GetText(This);}
|
||||
set {sfString_SetText(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Font used to display the text
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Font Font
|
||||
{
|
||||
get {return myFont;}
|
||||
set {myFont = value; sfString_SetFont(This, value != null ? value.This : IntPtr.Zero);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Base size of characters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float Size
|
||||
{
|
||||
get {return sfString_GetSize(This);}
|
||||
set {sfString_SetSize(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Style of the text (see Styles enum)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Styles Style
|
||||
{
|
||||
get {return sfString_GetStyle(This);}
|
||||
set {sfString_SetStyle(This, value);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the string rectangle on screen
|
||||
/// </summary>
|
||||
/// <returns>String rectangle in global coordinates (doesn't include rotation)</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public FloatRect GetRect()
|
||||
{
|
||||
return sfString_GetRect(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Return the visual position of the Index-th character of the string,
|
||||
/// in coordinates relative to the string
|
||||
/// (note : translation, center, rotation and scale are not applied)
|
||||
/// </summary>
|
||||
/// <param name="index">Index of the character</param>
|
||||
/// <returns>Position of the Index-th character (end of string if Index is out of range)</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2 GetCharacterPos(uint index)
|
||||
{
|
||||
Vector2 Pos;
|
||||
sfString_GetCharacterPos(This, index, out Pos.X, out Pos.Y);
|
||||
|
||||
return Pos;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Render the object into the given render window
|
||||
/// </summary>
|
||||
/// <param name="window">Target window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
internal override void Render(RenderWindow window)
|
||||
{
|
||||
sfRenderWindow_DrawString(window.This, This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfString_Destroy(This);
|
||||
}
|
||||
|
||||
private Font myFont = Font.DefaultFont;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfString_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetPosition(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetRotation(IntPtr This, float Rotation);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetRotation(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetScale(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetScaleX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetScaleY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetCenter(IntPtr This, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetCenterX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetCenterY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetColor(IntPtr This, Color Color);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Color sfString_GetColor(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetBlendMode(IntPtr This, BlendMode Mode);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern BlendMode sfString_GetBlendMode(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfString_TransformToLocal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Vector2 sfString_TransformToGlobal(IntPtr This, float PointX, float PointY, out float X, out float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfRenderWindow_DrawString(IntPtr This, IntPtr String);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetWidth(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetHeight(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetText(IntPtr This, string Text);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetFont(IntPtr This, IntPtr Font);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetSize(IntPtr This, float Size);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_SetStyle(IntPtr This, Styles Style);
|
||||
|
||||
[DllImport("csfml-graphics", CharSet = CharSet.Ansi), SuppressUnmanagedCodeSecurity]
|
||||
static extern string sfString_GetText(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfString_GetSize(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern Styles sfString_GetStyle(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern FloatRect sfString_GetRect(IntPtr This);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfString_GetCharacterPos(IntPtr This, uint Index, out float X, out float Y);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
114
dotnet/src/Graphics/Vector2.cs
Normal file
114
dotnet/src/Graphics/Vector2.cs
Normal file
|
@ -0,0 +1,114 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Vector2 is an utility class for manipulating 2 dimensional
|
||||
/// vectors with float components
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct Vector2
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the vector from its coordinates
|
||||
/// </summary>
|
||||
/// <param name="x">X coordinate</param>
|
||||
/// <param name="y">Y coordinate</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2(float x, float y)
|
||||
{
|
||||
X = x;
|
||||
Y = y;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator - overload ; returns the opposite of a vector
|
||||
/// </summary>
|
||||
/// <param name="v">Vector to negate</param>
|
||||
/// <returns>-v</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector2 operator -(Vector2 v)
|
||||
{
|
||||
return new Vector2(-v.X, -v.Y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator - overload ; subtracts two vectors
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>v1 - v2</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector2 operator -(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return new Vector2(v1.X - v2.X, v1.Y - v2.Y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator + overload ; add two vectors
|
||||
/// </summary>
|
||||
/// <param name="v1">First vector</param>
|
||||
/// <param name="v2">Second vector</param>
|
||||
/// <returns>v1 + v2</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector2 operator +(Vector2 v1, Vector2 v2)
|
||||
{
|
||||
return new Vector2(v1.X + v2.X, v1.Y + v2.Y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator * overload ; multiply a vector by a scalar value
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <returns>v * x</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector2 operator *(Vector2 v, float x)
|
||||
{
|
||||
return new Vector2(v.X * x, v.Y * x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator * overload ; multiply a scalar value by a vector
|
||||
/// </summary>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <returns>x * v</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector2 operator *(float x, Vector2 v)
|
||||
{
|
||||
return new Vector2(v.X * x, v.Y * x);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Operator / overload ; divide a vector by a scalar value
|
||||
/// </summary>
|
||||
/// <param name="v">Vector</param>
|
||||
/// <param name="x">Scalar value</param>
|
||||
/// <returns>v / x</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public static Vector2 operator /(Vector2 v, float x)
|
||||
{
|
||||
return new Vector2(v.X / x, v.Y / x);
|
||||
}
|
||||
|
||||
/// <summary>X (horizontal) component of the vector</summary>
|
||||
public float X;
|
||||
|
||||
/// <summary>Y (vertical) component of the vector</summary>
|
||||
public float Y;
|
||||
}
|
||||
}
|
||||
}
|
183
dotnet/src/Graphics/View.cs
Normal file
183
dotnet/src/Graphics/View.cs
Normal file
|
@ -0,0 +1,183 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Graphics
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// This class defines a view (position, size, etc.) ;
|
||||
/// you can consider it as a 2D camera
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class View : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create a default view (1000x1000, centered on origin)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public View() :
|
||||
base(sfView_Create())
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the view from a rectangle
|
||||
/// </summary>
|
||||
/// <param name="viewRect">Rectangle defining the position and size of the view</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public View(FloatRect viewRect) :
|
||||
base(sfView_CreateFromRect(viewRect))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the view from its center and half-size
|
||||
/// </summary>
|
||||
/// <param name="center">Center of the view</param>
|
||||
/// <param name="halfSize">Half-size of the view (from center to corner)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public View(Vector2 center, Vector2 halfSize) :
|
||||
base(sfView_Create())
|
||||
{
|
||||
this.Center = center;
|
||||
this.HalfSize = halfSize;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Center of the view
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2 Center
|
||||
{
|
||||
get {return new Vector2(sfView_GetCenterX(This), sfView_GetCenterY(This));}
|
||||
set {sfView_SetCenter(This, value.X, value.Y);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Half-size of the view
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Vector2 HalfSize
|
||||
{
|
||||
get {return new Vector2(sfView_GetHalfSizeX(This), sfView_GetHalfSizeY(This));}
|
||||
set {sfView_SetHalfSize(This, value.X, value.Y);}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Rebuild the view from a rectangle
|
||||
/// </summary>
|
||||
/// <param name="viewRect">Rectangle defining the position and size of the view</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void SetFromRect(FloatRect viewRect)
|
||||
{
|
||||
sfView_SetFromRect(This, viewRect);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the rectangle defining the view
|
||||
/// </summary>
|
||||
/// <returns>Rectangle of the view</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public FloatRect GetRect()
|
||||
{
|
||||
return sfView_GetRect(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Move the view
|
||||
/// </summary>
|
||||
/// <param name="offset">Offset to move the view</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Move(Vector2 offset)
|
||||
{
|
||||
sfView_Move(This, offset.X, offset.Y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Resize the view rectangle to simulate a zoom / unzoom effect
|
||||
/// </summary>
|
||||
/// <param name="factor">Zoom factor to apply, relative to the current zoom</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Zoom(float factor)
|
||||
{
|
||||
sfView_Zoom(This, factor);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Internal constructor for other classes which need to manipulate raw views
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Direct pointer to the view object in the C library</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
internal View(IntPtr thisPtr) :
|
||||
base(thisPtr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfView_Destroy(This);
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfView_Create();
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfView_CreateFromRect(FloatRect Rect);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfView_Destroy(IntPtr View);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfView_SetCenter(IntPtr View, float X, float Y);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfView_SetHalfSize(IntPtr View, float HalfWidth, float HalfHeight);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfView_SetFromRect(IntPtr View, FloatRect ViewRect);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfView_GetCenterX(IntPtr View);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfView_GetCenterY(IntPtr View);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfView_GetHalfSizeX(IntPtr View);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfView_GetHalfSizeY(IntPtr View);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern FloatRect sfView_GetRect(IntPtr View);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfView_Move(IntPtr View, float OffsetX, float OffsetY);
|
||||
|
||||
[DllImport("csfml-graphics"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfView_Zoom(IntPtr View, float Factor);
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
72
dotnet/src/Graphics/sfml-graphics.csproj
Normal file
72
dotnet/src/Graphics/sfml-graphics.csproj
Normal file
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{46786269-57B9-48E7-AA4F-8F4D84609FE6}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SFML.Graphics</RootNamespace>
|
||||
<AssemblyName>sfmlnet-graphics</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>bin\graphics-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\lib\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>bin\graphics-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Color.cs" />
|
||||
<Compile Include="Context.cs" />
|
||||
<Compile Include="Drawable.cs" />
|
||||
<Compile Include="Font.cs" />
|
||||
<Compile Include="Image.cs" />
|
||||
<Compile Include="PostFx.cs" />
|
||||
<Compile Include="Rect.cs" />
|
||||
<Compile Include="RenderWindow.cs" />
|
||||
<Compile Include="Shape.cs" />
|
||||
<Compile Include="Sprite.cs" />
|
||||
<Compile Include="String2D.cs" />
|
||||
<Compile Include="Vector2.cs" />
|
||||
<Compile Include="View.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Window\sfml-window.csproj">
|
||||
<Project>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</Project>
|
||||
<Name>sfml-window</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
389
dotnet/src/Window/Event.cs
Normal file
389
dotnet/src/Window/Event.cs
Normal file
|
@ -0,0 +1,389 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Window
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Definition of key codes for keyboard events
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public enum KeyCode
|
||||
{
|
||||
A = 'a',
|
||||
B = 'b',
|
||||
C = 'c',
|
||||
D = 'd',
|
||||
E = 'e',
|
||||
F = 'f',
|
||||
G = 'g',
|
||||
H = 'h',
|
||||
I = 'i',
|
||||
J = 'j',
|
||||
K = 'k',
|
||||
L = 'l',
|
||||
M = 'm',
|
||||
N = 'n',
|
||||
O = 'o',
|
||||
P = 'p',
|
||||
Q = 'q',
|
||||
R = 'r',
|
||||
S = 's',
|
||||
T = 't',
|
||||
U = 'u',
|
||||
V = 'v',
|
||||
W = 'w',
|
||||
X = 'x',
|
||||
Y = 'y',
|
||||
Z = 'z',
|
||||
Num0 = '0',
|
||||
Num1 = '1',
|
||||
Num2 = '2',
|
||||
Num3 = '3',
|
||||
Num4 = '4',
|
||||
Num5 = '5',
|
||||
Num6 = '6',
|
||||
Num7 = '7',
|
||||
Num8 = '8',
|
||||
Num9 = '9',
|
||||
Escape = 256,
|
||||
LControl,
|
||||
LShift,
|
||||
LAlt,
|
||||
LSystem, // OS specific key (left side) : windows (Win and Linux), apple (MacOS), ...
|
||||
RControl,
|
||||
RShift,
|
||||
RAlt,
|
||||
RSystem, // OS specific key (right side) : windows (Win and Linux), apple (MacOS), ...
|
||||
Menu,
|
||||
LBracket, // [
|
||||
RBracket, // ]
|
||||
SemiColon, // ;
|
||||
Comma, // ,
|
||||
Period, // .
|
||||
Quote, // '
|
||||
Slash, // /
|
||||
BackSlash,
|
||||
Tilde, // ~
|
||||
Equal, // =
|
||||
Dash, // -
|
||||
Space,
|
||||
Return,
|
||||
Back,
|
||||
Tab,
|
||||
PageUp,
|
||||
PageDown,
|
||||
End,
|
||||
Home,
|
||||
Insert,
|
||||
Delete,
|
||||
Add, // +
|
||||
Subtract, // -
|
||||
Multiply, // *
|
||||
Divide, // /
|
||||
Left, // Left arrow
|
||||
Right, // Right arrow
|
||||
Up, // Up arrow
|
||||
Down, // Down arrow
|
||||
Numpad0,
|
||||
Numpad1,
|
||||
Numpad2,
|
||||
Numpad3,
|
||||
Numpad4,
|
||||
Numpad5,
|
||||
Numpad6,
|
||||
Numpad7,
|
||||
Numpad8,
|
||||
Numpad9,
|
||||
F1,
|
||||
F2,
|
||||
F3,
|
||||
F4,
|
||||
F5,
|
||||
F6,
|
||||
F7,
|
||||
F8,
|
||||
F9,
|
||||
F10,
|
||||
F11,
|
||||
F12,
|
||||
F13,
|
||||
F14,
|
||||
F15,
|
||||
Pause
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Definition of button codes for mouse events
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public enum MouseButton
|
||||
{
|
||||
/// <summary>Left mouse button</summary>
|
||||
Left,
|
||||
|
||||
/// <summary>Right mouse button</summary>
|
||||
Right,
|
||||
|
||||
/// <summary>Center (wheel) mouse button</summary>
|
||||
Middle,
|
||||
|
||||
/// <summary>First extra button</summary>
|
||||
XButton1,
|
||||
|
||||
/// <summary>Second extra button</summary>
|
||||
XButton2
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Definition of joystick axis for joystick events
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public enum JoyAxis
|
||||
{
|
||||
/// <summary>X axis</summary>
|
||||
AxisX,
|
||||
|
||||
/// <summary>Y axis</summary>
|
||||
AxisY,
|
||||
|
||||
/// <summary>Z axis</summary>
|
||||
AxisZ,
|
||||
|
||||
/// <summary>R axis</summary>
|
||||
AxisR,
|
||||
|
||||
/// <summary>U axis</summary>
|
||||
AxisU,
|
||||
|
||||
/// <summary>V axis</summary>
|
||||
AxisV,
|
||||
|
||||
/// <summary>Point of view</summary>
|
||||
AxisPOV
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enumeration of the different types of events
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public enum EventType
|
||||
{
|
||||
/// <summary>Event triggered when a window is manually closed</summary>
|
||||
Closed,
|
||||
|
||||
/// <summary>Event triggered when a window is resized</summary>
|
||||
Resized,
|
||||
|
||||
/// <summary>Event triggered when a window loses the focus</summary>
|
||||
LostFocus,
|
||||
|
||||
/// <summary>Event triggered when a window gains the focus</summary>
|
||||
GainedFocus,
|
||||
|
||||
/// <summary>Event triggered when a valid character is entered</summary>
|
||||
TextEntered,
|
||||
|
||||
/// <summary>Event triggered when a keyboard key is pressed</summary>
|
||||
KeyPressed,
|
||||
|
||||
/// <summary>Event triggered when a keyboard key is released</summary>
|
||||
KeyReleased,
|
||||
|
||||
/// <summary>Event triggered when the mouse wheel is scrolled</summary>
|
||||
MouseWheelMoved,
|
||||
|
||||
/// <summary>Event triggered when a mouse button is pressed</summary>
|
||||
MouseButtonPressed,
|
||||
|
||||
/// <summary>Event triggered when a mouse button is released</summary>
|
||||
MouseButtonReleased,
|
||||
|
||||
/// <summary>Event triggered when the mouse moves within the area of a window</summary>
|
||||
MouseMoved,
|
||||
|
||||
/// <summary>Event triggered when the mouse enters the area of a window</summary>
|
||||
MouseEntered,
|
||||
|
||||
/// <summary>Event triggered when the mouse leaves the area of a window</summary>
|
||||
MouseLeft,
|
||||
|
||||
/// <summary>Event triggered when a joystick button is pressed</summary>
|
||||
JoyButtonPressed,
|
||||
|
||||
/// <summary>Event triggered when a joystick button is released</summary>
|
||||
JoyButtonReleased,
|
||||
|
||||
/// <summary>Event triggered when a joystick axis moves</summary>
|
||||
JoyMoved
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Keyboard event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct KeyEvent
|
||||
{
|
||||
/// <summary>Code of the key (see KeyCode enum)</summary>
|
||||
public KeyCode Code;
|
||||
|
||||
/// <summary>Is the Alt modifier pressed?</summary>
|
||||
public bool Alt;
|
||||
|
||||
/// <summary>Is the Control modifier pressed?</summary>
|
||||
public bool Control;
|
||||
|
||||
/// <summary>Is the Shift modifier pressed?</summary>
|
||||
public bool Shift;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Text event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct TextEvent
|
||||
{
|
||||
/// <summary>UTF-32 value of the character</summary>
|
||||
public uint Unicode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Mouse move event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct MouseMoveEvent
|
||||
{
|
||||
/// <summary>X coordinate of the mouse cursor</summary>
|
||||
public int X;
|
||||
|
||||
/// <summary>Y coordinate of the mouse cursor</summary>
|
||||
public int Y;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Mouse buttons event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct MouseButtonEvent
|
||||
{
|
||||
/// <summary>Code of the button (see MouseButton enum)</summary>
|
||||
public MouseButton Button;
|
||||
|
||||
/// <summary>X coordinate of the mouse cursor</summary>
|
||||
public int X;
|
||||
|
||||
/// <summary>Y coordinate of the mouse cursor</summary>
|
||||
public int Y;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Mouse wheel event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct MouseWheelEvent
|
||||
{
|
||||
/// <summary>Scroll amount</summary>
|
||||
public int Delta;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Joystick axis move event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct JoyMoveEvent
|
||||
{
|
||||
/// <summary>Index of the joystick which triggered the event</summary>
|
||||
public uint JoystickId;
|
||||
|
||||
/// <summary>Joystick axis (see JoyAxis enum)</summary>
|
||||
public JoyAxis Axis;
|
||||
|
||||
/// <summary>Current position of the axis</summary>
|
||||
public float Position;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Joystick buttons event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct JoyButtonEvent
|
||||
{
|
||||
/// <summary>Index of the joystick which triggered the event</summary>
|
||||
public uint JoystickId;
|
||||
|
||||
/// <summary>Index of the button</summary>
|
||||
public uint Button;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Size event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public struct SizeEvent
|
||||
{
|
||||
/// <summary>New width of the window</summary>
|
||||
public uint Width;
|
||||
|
||||
/// <summary>New height of the window</summary>
|
||||
public uint Height;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Event defines a system event and its parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Explicit, Size = 20)]
|
||||
public struct Event
|
||||
{
|
||||
/// <summary>Type of event (see EventType enum)</summary>
|
||||
[FieldOffset(0)]
|
||||
public EventType Type;
|
||||
|
||||
/// <summary>Arguments for key events (KeyPressed, KeyReleased)</summary>
|
||||
[FieldOffset(4)]
|
||||
public KeyEvent Key;
|
||||
|
||||
/// <summary>Arguments for text events (TextEntered)</summary>
|
||||
[FieldOffset(4)]
|
||||
public TextEvent Text;
|
||||
|
||||
/// <summary>Arguments for mouse move events (MouseMoved)</summary>
|
||||
[FieldOffset(4)]
|
||||
public MouseMoveEvent MouseMove;
|
||||
|
||||
/// <summary>Arguments for mouse button events (MouseButtonPressed, MouseButtonReleased)</summary>
|
||||
[FieldOffset(4)]
|
||||
public MouseButtonEvent MouseButton;
|
||||
|
||||
/// <summary>Arguments for mouse wheel events (MouseWheelMoved)</summary>
|
||||
[FieldOffset(4)]
|
||||
public MouseWheelEvent MouseWheel;
|
||||
|
||||
/// <summary>Arguments for joystick axis events (JoyMoved)</summary>
|
||||
[FieldOffset(4)]
|
||||
public JoyMoveEvent JoyMove;
|
||||
|
||||
/// <summary>Arguments for joystick button events (JoyButtonPressed, JoyButtonReleased)</summary>
|
||||
[FieldOffset(4)]
|
||||
public JoyButtonEvent JoyButton;
|
||||
|
||||
/// <summary>Arguments for size events (Resized)</summary>
|
||||
[FieldOffset(4)]
|
||||
public SizeEvent Size;
|
||||
}
|
||||
}
|
||||
}
|
223
dotnet/src/Window/EventArgs.cs
Normal file
223
dotnet/src/Window/EventArgs.cs
Normal file
|
@ -0,0 +1,223 @@
|
|||
using System;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Window
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Keyboard event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class KeyEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the key arguments from a key event
|
||||
/// </summary>
|
||||
/// <param name="e">Key event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public KeyEventArgs(KeyEvent e)
|
||||
{
|
||||
Code = e.Code;
|
||||
Alt = e.Alt;
|
||||
Control = e.Control;
|
||||
Shift = e.Shift;
|
||||
}
|
||||
|
||||
/// <summary>Code of the key (see KeyCode enum)</summary>
|
||||
public KeyCode Code;
|
||||
|
||||
/// <summary>Is the Alt modifier pressed?</summary>
|
||||
public bool Alt;
|
||||
|
||||
/// <summary>Is the Control modifier pressed?</summary>
|
||||
public bool Control;
|
||||
|
||||
/// <summary>Is the Shift modifier pressed?</summary>
|
||||
public bool Shift;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Text event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class TextEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the text arguments from a text event
|
||||
/// </summary>
|
||||
/// <param name="e">Text event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public TextEventArgs(TextEvent e)
|
||||
{
|
||||
Unicode = Char.ConvertFromUtf32((int)e.Unicode);
|
||||
}
|
||||
|
||||
/// <summary>UTF-16 value of the character</summary>
|
||||
public string Unicode;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Mouse move event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class MouseMoveEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the mouse move arguments from a mouse move event
|
||||
/// </summary>
|
||||
/// <param name="e">Mouse move event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public MouseMoveEventArgs(MouseMoveEvent e)
|
||||
{
|
||||
X = e.X;
|
||||
Y = e.Y;
|
||||
}
|
||||
|
||||
/// <summary>X coordinate of the mouse cursor</summary>
|
||||
public int X;
|
||||
|
||||
/// <summary>Y coordinate of the mouse cursor</summary>
|
||||
public int Y;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Mouse buttons event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class MouseButtonEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the mouse button arguments from a mouse button event
|
||||
/// </summary>
|
||||
/// <param name="e">Mouse button event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public MouseButtonEventArgs(MouseButtonEvent e)
|
||||
{
|
||||
Button = e.Button;
|
||||
X = e.X;
|
||||
Y = e.Y;
|
||||
}
|
||||
|
||||
/// <summary>Code of the button (see MouseButton enum)</summary>
|
||||
public MouseButton Button;
|
||||
|
||||
/// <summary>X coordinate of the mouse cursor</summary>
|
||||
public int X;
|
||||
|
||||
/// <summary>Y coordinate of the mouse cursor</summary>
|
||||
public int Y;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Mouse wheel event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class MouseWheelEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the mouse wheel arguments from a mouse wheel event
|
||||
/// </summary>
|
||||
/// <param name="e">Mouse wheel event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public MouseWheelEventArgs(MouseWheelEvent e)
|
||||
{
|
||||
Delta = e.Delta;
|
||||
}
|
||||
|
||||
/// <summary>Scroll amount</summary>
|
||||
public int Delta;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Joystick axis move event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class JoyMoveEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the joystick move arguments from a joystick move event
|
||||
/// </summary>
|
||||
/// <param name="e">Joystick move event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public JoyMoveEventArgs(JoyMoveEvent e)
|
||||
{
|
||||
JoystickId = e.JoystickId;
|
||||
Axis = e.Axis;
|
||||
Position = e.Position;
|
||||
}
|
||||
|
||||
/// <summary>Index of the joystick which triggered the event</summary>
|
||||
public uint JoystickId;
|
||||
|
||||
/// <summary>Joystick axis (see JoyAxis enum)</summary>
|
||||
public JoyAxis Axis;
|
||||
|
||||
/// <summary>Current position of the axis</summary>
|
||||
public float Position;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Joystick buttons event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class JoyButtonEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the joystick button arguments from a joystick button event
|
||||
/// </summary>
|
||||
/// <param name="e">Joystick button event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public JoyButtonEventArgs(JoyButtonEvent e)
|
||||
{
|
||||
JoystickId = e.JoystickId;
|
||||
Button = e.Button;
|
||||
}
|
||||
|
||||
/// <summary>Index of the joystick which triggered the event</summary>
|
||||
public uint JoystickId;
|
||||
|
||||
/// <summary>Index of the button</summary>
|
||||
public uint Button;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Size event parameters
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class SizeEventArgs : EventArgs
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the size arguments from a size event
|
||||
/// </summary>
|
||||
/// <param name="e">Size event</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public SizeEventArgs(SizeEvent e)
|
||||
{
|
||||
Width = e.Width;
|
||||
Height = e.Height;
|
||||
}
|
||||
|
||||
/// <summary>New width of the window</summary>
|
||||
public uint Width;
|
||||
|
||||
/// <summary>New height of the window</summary>
|
||||
public uint Height;
|
||||
}
|
||||
}
|
||||
}
|
133
dotnet/src/Window/Input.cs
Normal file
133
dotnet/src/Window/Input.cs
Normal file
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Window
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Input handles real-time input from keyboard and mouse.
|
||||
/// Use it instead of events to handle continuous moves and more
|
||||
/// game-friendly inputs
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Input : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the state of a key
|
||||
/// </summary>
|
||||
/// <param name="key">Key to check</param>
|
||||
/// <returns>True if key is down, false if key is up</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool IsKeyDown(KeyCode key)
|
||||
{
|
||||
return sfInput_IsKeyDown(This, key);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the state of a mouse button
|
||||
/// </summary>
|
||||
/// <param name="button">Button to check</param>
|
||||
/// <returns>True if button is down, false if button is up</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool IsMouseButtonDown(MouseButton button)
|
||||
{
|
||||
return sfInput_IsMouseButtonDown(This, button);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the state of a joystick button
|
||||
/// </summary>
|
||||
/// <param name="joystickId">Identifier of the joystick to check (0 or 1)</param>
|
||||
/// <param name="button">Button to check</param>
|
||||
/// <returns>True if button is down, false if button is up</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public bool IsJoystickButtonDown(uint joystickId, uint button)
|
||||
{
|
||||
return sfInput_IsJoystickButtonDown(This, joystickId, button);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the mouse X position
|
||||
/// </summary>
|
||||
/// <returns>Current mouse left position, relative to owner window</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public int GetMouseX()
|
||||
{
|
||||
return sfInput_GetMouseX(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get the mouse Y position
|
||||
/// </summary>
|
||||
/// <returns>Current mouse top position, relative to owner window</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public int GetMouseY()
|
||||
{
|
||||
return sfInput_GetMouseY(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get a joystick axis position
|
||||
/// </summary>
|
||||
/// <param name="joystickId">Identifier of the joystick to check (0 or 1)</param>
|
||||
/// <param name="axis">Axis to get</param>
|
||||
/// <returns>Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public float GetJoystickAxis(uint joystickId, JoyAxis axis)
|
||||
{
|
||||
return sfInput_GetJoystickAxis(This, joystickId, axis);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// For internal use only, construct the instance from a direct pointer to the internal object
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Internal pointer to the input object</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Input(IntPtr thisPtr) :
|
||||
base(thisPtr)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
// Nothing to do here, Input instances are owned by the C library
|
||||
}
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfInput_IsKeyDown(IntPtr This, KeyCode Key);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfInput_IsMouseButtonDown(IntPtr This, MouseButton Button);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfInput_IsJoystickButtonDown(IntPtr This, uint JoyId, uint Button);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern int sfInput_GetMouseX(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern int sfInput_GetMouseY(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfInput_GetJoystickAxis(IntPtr This, uint JoyId, JoyAxis Axis);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
84
dotnet/src/Window/LoadingFailedException.cs
Normal file
84
dotnet/src/Window/LoadingFailedException.cs
Normal file
|
@ -0,0 +1,84 @@
|
|||
using System;
|
||||
using System.Runtime.Serialization;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Exception thrown by SFML whenever loading a resource fails
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[Serializable]
|
||||
public class LoadingFailedException : Exception
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Default constructor (unknown error)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public LoadingFailedException() :
|
||||
base("Failed to load a resource")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Failure to load a resource from memory
|
||||
/// </summary>
|
||||
/// <param name="resourceName">Name of the resource</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public LoadingFailedException(string resourceName) :
|
||||
base("Failed to load " + resourceName + " from memory")
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Failure to load a resource from memory
|
||||
/// </summary>
|
||||
/// <param name="resourceName">Name of the resource</param>
|
||||
/// <param name="innerException">Exception which is the cause ofthe current exception</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public LoadingFailedException(string resourceName, Exception innerException) :
|
||||
base("Failed to load " + resourceName + " from memory", innerException)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Failure to load a resource from a file
|
||||
/// </summary>
|
||||
/// <param name="resourceName">Name of the resource</param>
|
||||
/// <param name="filename">Path of the file</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public LoadingFailedException(string resourceName, string filename) :
|
||||
base("Failed to load " + resourceName + " from file " + filename)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Failure to load a resource from a file
|
||||
/// </summary>
|
||||
/// <param name="resourceName">Name of the resource</param>
|
||||
/// <param name="filename">Path of the file</param>
|
||||
/// <param name="innerException">Exception which is the cause ofthe current exception</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public LoadingFailedException(string resourceName, string filename, Exception innerException) :
|
||||
base("Failed to load " + resourceName + " from file " + filename, innerException)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Initialize an instance of the exception with serialized data
|
||||
/// </summary>
|
||||
/// <param name="info">Serialized data</param>
|
||||
/// <param name="context">Contextual informations</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public LoadingFailedException(SerializationInfo info, StreamingContext context) :
|
||||
base(info, context)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
93
dotnet/src/Window/ObjectBase.cs
Normal file
93
dotnet/src/Window/ObjectBase.cs
Normal file
|
@ -0,0 +1,93 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// The ObjectBase class is an abstract base for every
|
||||
/// SFML object. It's meant for internal use only
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public abstract class ObjectBase : IDisposable
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the object from a pointer to the C library object
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Internal pointer to the object in the C libraries</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public ObjectBase(IntPtr thisPtr)
|
||||
{
|
||||
myThis = thisPtr;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Dispose the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
~ObjectBase()
|
||||
{
|
||||
Dispose(false);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Access to the internal pointer of the object.
|
||||
/// For internal use only
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public IntPtr This
|
||||
{
|
||||
get {return myThis;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Explicitely dispose the object
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void Dispose()
|
||||
{
|
||||
Dispose(true);
|
||||
GC.SuppressFinalize(this);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Destroy the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
private void Dispose(bool disposing)
|
||||
{
|
||||
if (myThis != IntPtr.Zero)
|
||||
{
|
||||
Destroy(disposing);
|
||||
myThis = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Destroy the object (implementation is left to each derived class)
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected abstract void Destroy(bool disposing);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Set the pointer to the internal object. For internal use only
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Pointer to the internal object in C library</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected void SetThis(IntPtr thisPtr)
|
||||
{
|
||||
myThis = thisPtr;
|
||||
}
|
||||
|
||||
private IntPtr myThis = IntPtr.Zero;
|
||||
}
|
||||
}
|
55
dotnet/src/Window/VideoMode.cs
Normal file
55
dotnet/src/Window/VideoMode.cs
Normal file
|
@ -0,0 +1,55 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Window
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// VideoMode defines a video mode (width, height, bpp, frequency)
|
||||
/// and provides static functions for getting modes supported
|
||||
/// by the display device
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct VideoMode
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the video mode with its width and height
|
||||
/// </summary>
|
||||
/// <param name="width">Video mode width</param>
|
||||
/// <param name="height">Video mode height</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public VideoMode(uint width, uint height) :
|
||||
this(width, height, 32)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the video mode with its width, height and depth
|
||||
/// </summary>
|
||||
/// <param name="width">Video mode width</param>
|
||||
/// <param name="height">Video mode height</param>
|
||||
/// <param name="bpp">Video mode depth (bits per pixel)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public VideoMode(uint width, uint height, uint bpp)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
BitsPerPixel = bpp;
|
||||
}
|
||||
|
||||
/// <summary>Video mode width, in pixels</summary>
|
||||
public uint Width;
|
||||
|
||||
/// <summary>Video mode height, in pixels</summary>
|
||||
public uint Height;
|
||||
|
||||
/// <summary>Video mode depth, in bits per pixel</summary>
|
||||
public uint BitsPerPixel;
|
||||
}
|
||||
}
|
||||
}
|
613
dotnet/src/Window/Window.cs
Normal file
613
dotnet/src/Window/Window.cs
Normal file
|
@ -0,0 +1,613 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Collections.Generic;
|
||||
using System.Security;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Window
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enumeration of window creation styles
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[Flags]
|
||||
public enum Styles
|
||||
{
|
||||
/// <summary>No border / title bar (this flag and all others are mutually exclusive)</summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>Title bar + fixed border</summary>
|
||||
Titlebar = 1 << 0,
|
||||
|
||||
/// <summary>Titlebar + resizable border + maximize button</summary>
|
||||
Resize = 1 << 1,
|
||||
|
||||
/// <summary>Titlebar + close button</summary>
|
||||
Close = 1 << 2,
|
||||
|
||||
/// <summary>Fullscreen mode (this flag and all others are mutually exclusive))</summary>
|
||||
Fullscreen = 1 << 3
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Window is a rendering window ; it can create a new window
|
||||
/// or connect to an existing one
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public class Window : ObjectBase
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window with default style and creation settings
|
||||
/// </summary>
|
||||
/// <param name="mode">Video mode to use</param>
|
||||
/// <param name="title">Title of the window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Window(VideoMode mode, string title) :
|
||||
this(mode, title, Styles.Resize | Styles.Close, new WindowSettings(24, 8, 0))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window with default creation settings
|
||||
/// </summary>
|
||||
/// <param name="mode">Video mode to use</param>
|
||||
/// <param name="title">Title of the window</param>
|
||||
/// <param name="style">Window style (Resize | Close by default)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Window(VideoMode mode, string title, Styles style) :
|
||||
this(mode, title, style, new WindowSettings(24, 8, 0))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window
|
||||
/// </summary>
|
||||
/// <param name="mode">Video mode to use</param>
|
||||
/// <param name="title">Title of the window</param>
|
||||
/// <param name="style">Window style (Resize | Close by default)</param>
|
||||
/// <param name="settings">Creation parameters</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Window(VideoMode mode, string title, Styles style, WindowSettings settings) :
|
||||
base(sfWindow_Create(mode, title, style, settings))
|
||||
{
|
||||
myInput = new Input(sfWindow_GetInput(This));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window from an existing control with default creation settings
|
||||
/// </summary>
|
||||
/// <param name="handle">Platform-specific handle of the control</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Window(IntPtr handle) :
|
||||
this(handle, new WindowSettings(24, 8, 0))
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Create the window from an existing control
|
||||
/// </summary>
|
||||
/// <param name="Handle">Platform-specific handle of the control</param>
|
||||
/// <param name="settings">Creation parameters</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Window(IntPtr Handle, WindowSettings settings) :
|
||||
base(sfWindow_CreateFromHandle(Handle, settings))
|
||||
{
|
||||
myInput = new Input(sfWindow_GetInput(This));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Return the list of window's events which happened since last call
|
||||
/// </summary>
|
||||
/// <returns>Array of events</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Event[] Events
|
||||
{
|
||||
get
|
||||
{
|
||||
Event Evt;
|
||||
List<Event> Evts = new List<Event>();
|
||||
while (GetEvent(out Evt))
|
||||
Evts.Add(Evt);
|
||||
|
||||
return Evts.ToArray();
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Input manager of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public Input Input
|
||||
{
|
||||
get {return myInput;}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Tell whether or not the window is opened (ie. has been created).
|
||||
/// Note that a hidden window (Show(false))
|
||||
/// will still return true
|
||||
/// </summary>
|
||||
/// <returns>True if the window is opened</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual bool IsOpened()
|
||||
{
|
||||
return sfWindow_IsOpened(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Close (destroy) the window.
|
||||
/// The Window instance remains valid and you can call
|
||||
/// Create to recreate the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void Close()
|
||||
{
|
||||
sfWindow_Close(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Display the window on screen
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void Display()
|
||||
{
|
||||
sfWindow_Display(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Width of the rendering region of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual uint Width
|
||||
{
|
||||
get { return sfWindow_GetWidth(This); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Height of the rendering region of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual uint Height
|
||||
{
|
||||
get { return sfWindow_GetHeight(This); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Creation settings of the window
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual WindowSettings Settings
|
||||
{
|
||||
get { return sfWindow_GetSettings(This); }
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enable / disable vertical synchronization
|
||||
/// </summary>
|
||||
/// <param name="enable">True to enable v-sync, false to deactivate</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void UseVerticalSync(bool enable)
|
||||
{
|
||||
sfWindow_UseVerticalSync(This, enable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Show or hide the mouse cursor
|
||||
/// </summary>
|
||||
/// <param name="show">True to show, false to hide</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void ShowMouseCursor(bool show)
|
||||
{
|
||||
sfWindow_ShowMouseCursor(This, show);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the position of the mouse cursor
|
||||
/// </summary>
|
||||
/// <param name="x">Left coordinate of the cursor, relative to the window</param>
|
||||
/// <param name="y">Top coordinate of the cursor, relative to the window</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void SetCursorPosition(uint x, uint y)
|
||||
{
|
||||
sfWindow_SetCursorPosition(This, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the position of the window on screen.
|
||||
/// Only works for top-level windows
|
||||
/// </summary>
|
||||
/// <param name="x">Left position</param>
|
||||
/// <param name="y">Top position</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void SetPosition(int x, int y)
|
||||
{
|
||||
sfWindow_SetPosition(This, x, y);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the size of the rendering region of the window
|
||||
/// </summary>
|
||||
/// <param name="width">New width</param>
|
||||
/// <param name="height">New height</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void SetSize(uint width, uint height)
|
||||
{
|
||||
sfWindow_SetSize(This, width, height);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Show or hide the window
|
||||
/// </summary>
|
||||
/// <param name="show">True to show, false to hide</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void Show(bool show)
|
||||
{
|
||||
sfWindow_Show(This, show);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Enable or disable automatic key-repeat.
|
||||
/// Automatic key-repeat is enabled by default
|
||||
/// </summary>
|
||||
/// <param name="enable">True to enable, false to disable</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void EnableKeyRepeat(bool enable)
|
||||
{
|
||||
sfWindow_EnableKeyRepeat(This, enable);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the window's icon
|
||||
/// </summary>
|
||||
/// <param name="width">Icon's width, in pixels</param>
|
||||
/// <param name="height">Icon's height, in pixels</param>
|
||||
/// <param name="pixels">Array of pixels, format must be RGBA 32 bits</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void SetIcon(uint width, uint height, byte[] pixels)
|
||||
{
|
||||
unsafe
|
||||
{
|
||||
fixed (byte* PixelsPtr = pixels)
|
||||
{
|
||||
sfWindow_SetIcon(This, width, height, PixelsPtr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Activate the window as the current target
|
||||
/// for rendering
|
||||
/// </summary>
|
||||
/// <returns>True if operation was successful, false otherwise</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual bool SetActive()
|
||||
{
|
||||
return SetActive(true);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Activate of deactivate the window as the current target
|
||||
/// for rendering
|
||||
/// </summary>
|
||||
/// <param name="active">True to activate, false to deactivate (true by default)</param>
|
||||
/// <returns>True if operation was successful, false otherwise</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual bool SetActive(bool active)
|
||||
{
|
||||
return sfWindow_SetActive(This, active);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Limit the framerate to a maximum fixed frequency
|
||||
/// </summary>
|
||||
/// <param name="limit">Framerate limit, in frames per seconds (use 0 to disable limit)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void SetFramerateLimit(uint limit)
|
||||
{
|
||||
sfWindow_SetFramerateLimit(This, limit);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Get time elapsed since last frame
|
||||
/// </summary>
|
||||
/// <returns>Time elapsed, in seconds</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual float GetFrameTime()
|
||||
{
|
||||
return sfWindow_GetFrameTime(This);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Change the joystick threshold, ie. the value below which
|
||||
/// no move event will be generated
|
||||
/// </summary>
|
||||
/// <param name="threshold">New threshold, in range [0, 100]</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public virtual void SetJoystickThreshold(float threshold)
|
||||
{
|
||||
sfWindow_SetJoystickThreshold(This, threshold);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Call the event handlers for each pending event.
|
||||
/// Use of this function is exclusive with the Events property (use one or the other)
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
public void DispatchEvents()
|
||||
{
|
||||
foreach (Event e in Events)
|
||||
{
|
||||
switch (e.Type)
|
||||
{
|
||||
case EventType.Closed :
|
||||
if (Closed != null)
|
||||
Closed(this, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case EventType.GainedFocus :
|
||||
if (GainedFocus != null)
|
||||
GainedFocus(this, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case EventType.JoyButtonPressed :
|
||||
if (JoyButtonPressed != null)
|
||||
JoyButtonPressed(this, new JoyButtonEventArgs(e.JoyButton));
|
||||
break;
|
||||
|
||||
case EventType.JoyButtonReleased :
|
||||
if (JoyButtonReleased != null)
|
||||
JoyButtonReleased(this, new JoyButtonEventArgs(e.JoyButton));
|
||||
break;
|
||||
|
||||
case EventType.JoyMoved :
|
||||
if (JoyMoved != null)
|
||||
JoyMoved(this, new JoyMoveEventArgs(e.JoyMove));
|
||||
break;
|
||||
|
||||
case EventType.KeyPressed :
|
||||
if (KeyPressed != null)
|
||||
KeyPressed(this, new KeyEventArgs(e.Key));
|
||||
break;
|
||||
|
||||
case EventType.KeyReleased :
|
||||
if (KeyReleased != null)
|
||||
KeyReleased(this, new KeyEventArgs(e.Key));
|
||||
break;
|
||||
|
||||
case EventType.LostFocus :
|
||||
if (LostFocus != null)
|
||||
LostFocus(this, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case EventType.MouseButtonPressed :
|
||||
if (MouseButtonPressed != null)
|
||||
MouseButtonPressed(this, new MouseButtonEventArgs(e.MouseButton));
|
||||
break;
|
||||
|
||||
case EventType.MouseButtonReleased :
|
||||
if (MouseButtonReleased != null)
|
||||
MouseButtonReleased(this, new MouseButtonEventArgs(e.MouseButton));
|
||||
break;
|
||||
|
||||
case EventType.MouseEntered :
|
||||
if (MouseEntered != null)
|
||||
MouseEntered(this, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case EventType.MouseLeft :
|
||||
if (MouseLeft != null)
|
||||
MouseLeft(this, EventArgs.Empty);
|
||||
break;
|
||||
|
||||
case EventType.MouseMoved :
|
||||
if (MouseMoved != null)
|
||||
MouseMoved(this, new MouseMoveEventArgs(e.MouseMove));
|
||||
break;
|
||||
|
||||
case EventType.MouseWheelMoved :
|
||||
if (MouseWheelMoved != null)
|
||||
MouseWheelMoved(this, new MouseWheelEventArgs(e.MouseWheel));
|
||||
break;
|
||||
|
||||
case EventType.Resized :
|
||||
if (Resized != null)
|
||||
Resized(this, new SizeEventArgs(e.Size));
|
||||
break;
|
||||
|
||||
case EventType.TextEntered :
|
||||
if (TextEntered != null)
|
||||
TextEntered(this, new TextEventArgs(e.Text));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Constructor for derived classes
|
||||
/// </summary>
|
||||
/// <param name="thisPtr">Pointer to the internal object</param>
|
||||
/// <param name="dummy">Internal hack :)</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected Window(IntPtr thisPtr, int dummy) :
|
||||
base(thisPtr)
|
||||
{
|
||||
// TODO : find a cleaner way of separating this constructor from Window(IntPtr handle)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Internal function to get the next event
|
||||
/// </summary>
|
||||
/// <param name="eventToFill">Variable to fill with the raw pointer to the event structure</param>
|
||||
/// <returns>True if there was an event, false otherwise</returns>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected virtual bool GetEvent(out Event eventToFill)
|
||||
{
|
||||
return sfWindow_GetEvent(This, out eventToFill);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Handle the destruction of the object
|
||||
/// </summary>
|
||||
/// <param name="disposing">Is the GC disposing the object, or is it an explicit call ?</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
protected override void Destroy(bool disposing)
|
||||
{
|
||||
sfWindow_Destroy(This);
|
||||
}
|
||||
|
||||
/// <summary>Event handler for the Closed event</summary>
|
||||
public event EventHandler Closed = null;
|
||||
|
||||
/// <summary>Event handler for the Resized event</summary>
|
||||
public event EventHandler<SizeEventArgs> Resized = null;
|
||||
|
||||
/// <summary>Event handler for the LostFocus event</summary>
|
||||
public event EventHandler LostFocus = null;
|
||||
|
||||
/// <summary>Event handler for the GainedFocus event</summary>
|
||||
public event EventHandler GainedFocus = null;
|
||||
|
||||
/// <summary>Event handler for the TextEntered event</summary>
|
||||
public event EventHandler<TextEventArgs> TextEntered = null;
|
||||
|
||||
/// <summary>Event handler for the KeyPressed event</summary>
|
||||
public event EventHandler<KeyEventArgs> KeyPressed = null;
|
||||
|
||||
/// <summary>Event handler for the KeyReleased event</summary>
|
||||
public event EventHandler<KeyEventArgs> KeyReleased = null;
|
||||
|
||||
/// <summary>Event handler for the MouseWheelMoved event</summary>
|
||||
public event EventHandler<MouseWheelEventArgs> MouseWheelMoved = null;
|
||||
|
||||
/// <summary>Event handler for the MouseButtonPressed event</summary>
|
||||
public event EventHandler<MouseButtonEventArgs> MouseButtonPressed = null;
|
||||
|
||||
/// <summary>Event handler for the MouseButtonReleased event</summary>
|
||||
public event EventHandler<MouseButtonEventArgs> MouseButtonReleased = null;
|
||||
|
||||
/// <summary>Event handler for the MouseMoved event</summary>
|
||||
public event EventHandler<MouseMoveEventArgs> MouseMoved = null;
|
||||
|
||||
/// <summary>Event handler for the MouseEntered event</summary>
|
||||
public event EventHandler MouseEntered = null;
|
||||
|
||||
/// <summary>Event handler for the MouseLeft event</summary>
|
||||
public event EventHandler MouseLeft = null;
|
||||
|
||||
/// <summary>Event handler for the JoyButtonPressed event</summary>
|
||||
public event EventHandler<JoyButtonEventArgs> JoyButtonPressed = null;
|
||||
|
||||
/// <summary>Event handler for the JoyButtonReleased event</summary>
|
||||
public event EventHandler<JoyButtonEventArgs> JoyButtonReleased = null;
|
||||
|
||||
/// <summary>Event handler for the JoyMoved event</summary>
|
||||
public event EventHandler<JoyMoveEventArgs> JoyMoved = null;
|
||||
|
||||
protected Input myInput = null;
|
||||
|
||||
#region Imports
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfWindow_Create(VideoMode Mode, string Title, Styles Style, WindowSettings Params);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfWindow_CreateFromHandle(IntPtr Handle, WindowSettings Params);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_Destroy(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern IntPtr sfWindow_GetInput(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfWindow_IsOpened(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_Close(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfWindow_GetEvent(IntPtr This, out Event Evt);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_Display(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfWindow_GetWidth(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern uint sfWindow_GetHeight(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern WindowSettings sfWindow_GetSettings(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_UseVerticalSync(IntPtr This, bool Enable);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_ShowMouseCursor(IntPtr This, bool Show);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_SetCursorPosition(IntPtr This, uint X, uint Y);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_SetPosition(IntPtr This, int X, int Y);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_SetSize(IntPtr This, uint Width, uint Height);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_Show(IntPtr This, bool Show);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_EnableKeyRepeat(IntPtr This, bool Enable);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
unsafe static extern void sfWindow_SetIcon(IntPtr This, uint Width, uint Height, byte* Pixels);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern bool sfWindow_SetActive(IntPtr This, bool Active);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_SetFramerateLimit(IntPtr This, uint Limit);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern float sfWindow_GetFrameTime(IntPtr This);
|
||||
|
||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||
static extern void sfWindow_SetJoystickThreshold(IntPtr This, float Threshold);
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
53
dotnet/src/Window/WindowSettings.cs
Normal file
53
dotnet/src/Window/WindowSettings.cs
Normal file
|
@ -0,0 +1,53 @@
|
|||
using System;
|
||||
using System.Runtime.InteropServices;
|
||||
|
||||
namespace SFML
|
||||
{
|
||||
namespace Window
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Structure defining the creation settings of windows
|
||||
/// </summary>
|
||||
////////////////////////////////////////////////////////////
|
||||
[StructLayout(LayoutKind.Sequential)]
|
||||
public struct WindowSettings
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the settings from depth / stencil bits
|
||||
/// </summary>
|
||||
/// <param name="depthBits">Depth buffer bits</param>
|
||||
/// <param name="stencilBits">Stencil buffer bits</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public WindowSettings(uint depthBits, uint stencilBits) :
|
||||
this(depthBits, stencilBits, 0)
|
||||
{
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// <summary>
|
||||
/// Construct the settings from depth / stencil bits and antialiasing level
|
||||
/// </summary>
|
||||
/// <param name="depthBits">Depth buffer bits</param>
|
||||
/// <param name="stencilBits">Stencil buffer bits</param>
|
||||
/// <param name="antialiasingLevel">Antialiasing level</param>
|
||||
////////////////////////////////////////////////////////////
|
||||
public WindowSettings(uint depthBits, uint stencilBits, uint antialiasingLevel)
|
||||
{
|
||||
DepthBits = depthBits;
|
||||
StencilBits = stencilBits;
|
||||
AntialiasingLevel = antialiasingLevel;
|
||||
}
|
||||
|
||||
/// <summary>Depth buffer bits (0 is disabled)</summary>
|
||||
public uint DepthBits;
|
||||
|
||||
/// <summary>Stencil buffer bits (0 is disabled)</summary>
|
||||
public uint StencilBits;
|
||||
|
||||
/// <summary>Antialiasing level (0 is disabled)</summary>
|
||||
public uint AntialiasingLevel;
|
||||
}
|
||||
}
|
||||
}
|
58
dotnet/src/Window/sfml-window.csproj
Normal file
58
dotnet/src/Window/sfml-window.csproj
Normal file
|
@ -0,0 +1,58 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>8.0.50727</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{D17DE83D-A592-461F-8AF2-53F9E22E1D0F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SFML.Window</RootNamespace>
|
||||
<AssemblyName>sfmlnet-window</AssemblyName>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>bin\Debug\</OutputPath>
|
||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>bin\window-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\..\lib\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<DocumentationFile>bin\window-doc.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
<ItemGroup>
|
||||
<Compile Include="Event.cs" />
|
||||
<Compile Include="EventArgs.cs" />
|
||||
<Compile Include="Input.cs" />
|
||||
<Compile Include="LoadingFailedException.cs" />
|
||||
<Compile Include="ObjectBase.cs" />
|
||||
<Compile Include="VideoMode.cs" />
|
||||
<Compile Include="Window.cs" />
|
||||
<Compile Include="WindowSettings.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="Properties\" />
|
||||
</ItemGroup>
|
||||
</Project>
|
Loading…
Add table
Add a link
Reference in a new issue