Skip to content

Commit f554c10

Browse files
updated examples, add new example
1 parent e70fc89 commit f554c10

File tree

8 files changed

+94
-10
lines changed

8 files changed

+94
-10
lines changed

examples/Examples.sln

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.Window", "..\src\SFML.
2929
EndProject
3030
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "netcore", "netcore\netcore.csproj", "{93B8425A-AC40-4486-96AF-20027B738C09}"
3131
EndProject
32+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "custom_eventman", "custom_eventman\custom_eventman.csproj", "{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}"
33+
EndProject
3234
Global
3335
GlobalSection(SolutionConfigurationPlatforms) = preSolution
3436
Debug|Any CPU = Debug|Any CPU
@@ -183,6 +185,18 @@ Global
183185
{93B8425A-AC40-4486-96AF-20027B738C09}.Release|x64.Build.0 = Release|Any CPU
184186
{93B8425A-AC40-4486-96AF-20027B738C09}.Release|x86.ActiveCfg = Release|Any CPU
185187
{93B8425A-AC40-4486-96AF-20027B738C09}.Release|x86.Build.0 = Release|Any CPU
188+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
189+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
190+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x64.ActiveCfg = Debug|Any CPU
191+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x64.Build.0 = Debug|Any CPU
192+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x86.ActiveCfg = Debug|Any CPU
193+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x86.Build.0 = Debug|Any CPU
194+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
195+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|Any CPU.Build.0 = Release|Any CPU
196+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x64.ActiveCfg = Release|Any CPU
197+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x64.Build.0 = Release|Any CPU
198+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x86.ActiveCfg = Release|Any CPU
199+
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x86.Build.0 = Release|Any CPU
186200
EndGlobalSection
187201
GlobalSection(SolutionProperties) = preSolution
188202
HideSolutionNode = FALSE

examples/custom_eventman/Program.cs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
using System.Collections.Generic;
2+
using SFML.Graphics;
3+
using SFML.Window;
4+
namespace Program;
5+
6+
public struct SimpleEventPasser : IEventMan
7+
{
8+
private readonly List<Event> _events;
9+
public SimpleEventPasser() => _events = new();
10+
public void HandleEvent(Event eve)
11+
{
12+
switch (eve.Type)
13+
{
14+
case EventType.Closed:
15+
case EventType.LostFocus:
16+
case EventType.GainedFocus:
17+
case EventType.KeyPressed:
18+
case EventType.KeyReleased:
19+
_events.Add(eve);
20+
break;
21+
default: // Filtering out all other events
22+
break;
23+
}
24+
}
25+
public void PrepareFrame() => _events.Clear();
26+
public IEnumerable<Event> ProcessEvents() => _events;
27+
}
28+
public static class Program
29+
{
30+
public static void Main()
31+
{
32+
var event_man = new SimpleEventPasser();
33+
var window = new RenderWindow(
34+
new(640, 480),
35+
"Custom Event Manager example",
36+
Styles.Default,
37+
event_man
38+
);
39+
while (window.IsOpen)
40+
{
41+
window.Clear(Color.Black);
42+
window.DispatchEvents();
43+
window.Display();
44+
foreach (var e in event_man.ProcessEvents())
45+
{
46+
System.Console.WriteLine(e.ToString());
47+
if (e.Type == EventType.Closed)
48+
{
49+
window.Close();
50+
}
51+
}
52+
}
53+
}
54+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<ItemGroup>
4+
<ProjectReference Include="..\..\src\SFML.Net\SFML.Net.csproj" />
5+
</ItemGroup>
6+
7+
<PropertyGroup>
8+
<OutputType>Exe</OutputType>
9+
<TargetFramework>net6.0</TargetFramework>
10+
<ImplicitUsings>disable</ImplicitUsings>
11+
<Nullable>enable</Nullable>
12+
</PropertyGroup>
13+
14+
</Project>

examples/netcore/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ static void Main(string[] args)
1818
var sound = new Sound(GenerateSineWave(frequency: 440.0, volume: .25, seconds: 1));
1919

2020
var window = new RenderWindow(new VideoMode(800, 600), "SFML running in .NET Core");
21-
window.Closed += (_, __) => window.Close();
21+
(window.SfmlEventManager as SubscribeManager).Closed += (_, __) => window.Close();
2222

2323
sound.Play();
2424

examples/opengl/OpenGL.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ static void Main()
3131
//GraphicsContext context = new GraphicsContext(new ContextHandle(IntPtr.Zero), null);
3232

3333
// Setup event handlers
34-
window.Closed += new EventHandler(OnClosed);
35-
window.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
36-
window.Resized += new EventHandler<SizeEventArgs>(OnResized);
34+
var handler = window.SfmlEventManager as SubscribeManager;
35+
handler.Closed += new EventHandler(OnClosed);
36+
handler.KeyPressed += new EventHandler<KeyEventArgs>(OnKeyPressed);
37+
handler.Resized += new EventHandler<SizeEventArgs>(OnResized);
3738

3839
// Create a sprite for the background
3940
var background = new Sprite(new Texture("resources/background.jpg"));

examples/shader/Shader.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,8 +280,9 @@ static void Main()
280280
window.SetVerticalSyncEnabled(true);
281281

282282
// Setup event handlers
283-
window.Closed += OnClosed;
284-
window.KeyPressed += OnKeyPressed;
283+
var handler = window.SfmlEventManager as SubscribeManager;
284+
handler.Closed += OnClosed;
285+
handler.KeyPressed += OnKeyPressed;
285286

286287
// Load the application font and pass it to the Effect class
287288
var font = new Font("resources/sansation.ttf");

examples/visualbasic/OpenGL.vb

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,15 @@ Module OpenGL
177177
''' <summary>
178178
''' Function called when the window is closed
179179
''' </summary>
180-
Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles window.Closed
180+
Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles window.SfmlEventManager.Closed
181181
Dim window = CType(sender, RenderWindow)
182182
window.Close()
183183
End Sub
184184

185185
''' <summary>
186186
''' Function called when a key is pressed
187187
''' </summary>
188-
Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles window.KeyPressed
188+
Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles window.SfmlEventManager.KeyPressed
189189
Dim window = CType(sender, RenderWindow)
190190
If e.Code = Keyboard.Key.Escape Then
191191
window.Close()
@@ -195,7 +195,7 @@ Module OpenGL
195195
''' <summary>
196196
''' Function called when the window is resized
197197
''' </summary>
198-
Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles window.Resized
198+
Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles window.SfmlEventManager.Resized
199199
GL.Viewport(0, 0, e.Width, e.Height)
200200
End Sub
201201

examples/window/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public void Run()
2020
{
2121
var mode = new SFML.Window.VideoMode(800, 600);
2222
var window = new SFML.Graphics.RenderWindow(mode, "SFML works!");
23-
window.KeyPressed += Window_KeyPressed;
23+
(window.SfmlEventManager as SFML.Window.SubscribeManager).KeyPressed += Window_KeyPressed;
2424

2525
var circle = new SFML.Graphics.CircleShape(100f)
2626
{

0 commit comments

Comments
 (0)