Skip to content

Commit

Permalink
updated examples, added custom_eventman example
Browse files Browse the repository at this point in the history
  • Loading branch information
AzuxirenLeadGuy committed Jun 4, 2024
1 parent e70fc89 commit b36fd67
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 15 deletions.
14 changes: 14 additions & 0 deletions examples/Examples.sln
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SFML.Window", "..\src\SFML.
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "netcore", "netcore\netcore.csproj", "{93B8425A-AC40-4486-96AF-20027B738C09}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "custom_eventman", "custom_eventman\custom_eventman.csproj", "{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -183,6 +185,18 @@ Global
{93B8425A-AC40-4486-96AF-20027B738C09}.Release|x64.Build.0 = Release|Any CPU
{93B8425A-AC40-4486-96AF-20027B738C09}.Release|x86.ActiveCfg = Release|Any CPU
{93B8425A-AC40-4486-96AF-20027B738C09}.Release|x86.Build.0 = Release|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x64.ActiveCfg = Debug|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x64.Build.0 = Debug|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x86.ActiveCfg = Debug|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Debug|x86.Build.0 = Debug|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|Any CPU.Build.0 = Release|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x64.ActiveCfg = Release|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x64.Build.0 = Release|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x86.ActiveCfg = Release|Any CPU
{03A24BD1-B960-4E4A-AF8A-22BA8DA9BAFC}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
54 changes: 54 additions & 0 deletions examples/custom_eventman/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using System.Collections.Generic;
using SFML.Graphics;
using SFML.Window;
namespace Program;

public readonly struct SimpleEventPasser : IEventMan
{
private readonly List<Event> _events;
public SimpleEventPasser() => _events = new();
public readonly void HandleEvent(Event eve)
{
switch (eve.Type)
{
case EventType.Closed:
case EventType.LostFocus:
case EventType.GainedFocus:
case EventType.KeyPressed:
case EventType.KeyReleased:
_events.Add(eve);
break;
default: // Filtering out all other events
break;
}
}
public readonly void PrepareFrame() => _events.Clear();
public IEnumerable<Event> ProcessEvents() => _events;
}
public static class Program
{
public static void Main()
{
var event_man = new SimpleEventPasser();
var window = new RenderWindow(
new(640, 480),
"Custom Event Manager example",
Styles.Default,
event_man
);
while (window.IsOpen)
{
window.Clear(Color.Black);
window.DispatchEvents();
window.Display();
foreach (var e in event_man.ProcessEvents())
{
System.Console.WriteLine(e.ToString());
if (e.Type == EventType.Closed)
{
window.Close();
}
}
}
}
}
14 changes: 14 additions & 0 deletions examples/custom_eventman/custom_eventman.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<Project Sdk="Microsoft.NET.Sdk">

<ItemGroup>
<ProjectReference Include="..\..\src\SFML.Net\SFML.Net.csproj" />
</ItemGroup>

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>disable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

</Project>
2 changes: 1 addition & 1 deletion examples/netcore/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ static void Main(string[] args)
var sound = new Sound(GenerateSineWave(frequency: 440.0, volume: .25, seconds: 1));

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

sound.Play();

Expand Down
7 changes: 4 additions & 3 deletions examples/opengl/OpenGL.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,10 @@ static void Main()
//GraphicsContext context = new GraphicsContext(new ContextHandle(IntPtr.Zero), null);

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

// Create a sprite for the background
var background = new Sprite(new Texture("resources/background.jpg"));
Expand Down
2 changes: 1 addition & 1 deletion examples/opengl/opengl.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>opengl</RootNamespace>
<AssemblyName>opengl</AssemblyName>
<Configurations>Debug;Release;_WINDOWS_;_LINUX_;_OSX_</Configurations>
Expand Down
5 changes: 3 additions & 2 deletions examples/shader/Shader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,9 @@ static void Main()
window.SetVerticalSyncEnabled(true);

// Setup event handlers
window.Closed += OnClosed;
window.KeyPressed += OnKeyPressed;
var handler = window.SfmlEventManager as SubscribeManager;
handler.Closed += OnClosed;
handler.KeyPressed += OnKeyPressed;

// Load the application font and pass it to the Effect class
var font = new Font("resources/sansation.ttf");
Expand Down
2 changes: 1 addition & 1 deletion examples/shader/shader.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>shader</RootNamespace>
<AssemblyName>shader</AssemblyName>
<Configurations>Debug;Release;_WINDOWS_;_LINUX_;_OSX_</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion examples/sound/sound.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>sound</RootNamespace>
<AssemblyName>sound</AssemblyName>
<Configurations>Debug;Release;_WINDOWS_;_LINUX_;_OSX_</Configurations>
Expand Down
2 changes: 1 addition & 1 deletion examples/sound_capture/sound_capture.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>sound_capture</RootNamespace>
<AssemblyName>sound_capture</AssemblyName>
<Configurations>Debug;Release;_WINDOWS_;_LINUX_;_OSX_</Configurations>
Expand Down
6 changes: 3 additions & 3 deletions examples/visualbasic/OpenGL.vb
Original file line number Diff line number Diff line change
Expand Up @@ -177,15 +177,15 @@ Module OpenGL
''' <summary>
''' Function called when the window is closed
''' </summary>
Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles window.Closed
Sub App_Closed(ByVal sender As Object, ByVal e As EventArgs) Handles window.SfmlEventManager.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 window.KeyPressed
Sub App_KeyPressed(ByVal sender As Object, ByVal e As KeyEventArgs) Handles window.SfmlEventManager.KeyPressed
Dim window = CType(sender, RenderWindow)
If e.Code = Keyboard.Key.Escape Then
window.Close()
Expand All @@ -195,7 +195,7 @@ Module OpenGL
''' <summary>
''' Function called when the window is resized
''' </summary>
Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles window.Resized
Sub App_Resized(ByVal sender As Object, ByVal e As SizeEventArgs) Handles window.SfmlEventManager.Resized
GL.Viewport(0, 0, e.Width, e.Height)
End Sub

Expand Down
2 changes: 1 addition & 1 deletion examples/window/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public void Run()
{
var mode = new SFML.Window.VideoMode(800, 600);
var window = new SFML.Graphics.RenderWindow(mode, "SFML works!");
window.KeyPressed += Window_KeyPressed;
(window.SfmlEventManager as SFML.Window.SubscribeManager).KeyPressed += Window_KeyPressed;

var circle = new SFML.Graphics.CircleShape(100f)
{
Expand Down
2 changes: 1 addition & 1 deletion examples/window/window.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net48</TargetFramework>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>window</RootNamespace>
<AssemblyName>window</AssemblyName>
<Configurations>Debug;Release;_WINDOWS_;_LINUX_;_OSX_</Configurations>
Expand Down

0 comments on commit b36fd67

Please sign in to comment.