diff --git a/src/Bliss.Test/Game.cs b/src/Bliss.Test/Game.cs
index dff5697..ca250f7 100644
--- a/src/Bliss.Test/Game.cs
+++ b/src/Bliss.Test/Game.cs
@@ -1,12 +1,6 @@
-using System.Numerics;
using Bliss.CSharp;
-using Bliss.CSharp.Colors;
using Bliss.CSharp.Interact;
-using Bliss.CSharp.Interact.Gamepads;
-using Bliss.CSharp.Interact.Mice;
using Bliss.CSharp.Logging;
-using Bliss.CSharp.Rendering;
-using Bliss.CSharp.Textures;
using Bliss.CSharp.Windowing;
using Veldrid;
using Veldrid.Sdl2;
@@ -20,9 +14,7 @@ public class Game : Disposable {
public Window Window { get; private set; }
public GraphicsDevice GraphicsDevice { get; private set; }
-
public CommandList CommandList { get; private set; }
- public Graphics Graphics { get; private set; }
private double _fixedFrameRate;
@@ -60,16 +52,13 @@ public void Run() {
Logger.Info("Initialize command list...");
this.CommandList = this.GraphicsDevice.ResourceFactory.CreateCommandList();
- Logger.Info("Initialize graphics...");
- this.Graphics = new Graphics(this.GraphicsDevice, this.CommandList);
-
Logger.Info("Initialize input...");
Input.Init(this.Window);
this.Init();
Logger.Info("Start main loops...");
- while (Window.Exists) {
+ while (this.Window.Exists) {
if (this.GetTargetFps() != 0 && Time.Timer.Elapsed.TotalSeconds <= this._fixedFrameRate) {
continue;
}
@@ -87,11 +76,7 @@ public void Run() {
this._fixedUpdateTimer -= this._fixedUpdateTimeStep;
}
- //this.Graphics.BeginDrawing();
- //this.Graphics.ClearBackground(0, Color.DarkGray);
- this.Draw(this.Graphics);
- //this.Graphics.EndDrawing();
-
+ this.Draw(this.GraphicsDevice, this.CommandList);
Input.End();
}
@@ -101,68 +86,13 @@ public void Run() {
protected virtual void Init() { }
- protected virtual void Update() {
- /*if (Input.IsMouseButtonPressed(MouseButton.Right)) {
- Logger.Error("Right mouse button is pressed!");
- }
-
- if (Input.IsMouseButtonDown(MouseButton.Left)) {
- Logger.Error("Left mouse button is down!");
- }
-
- if (Input.IsMouseButtonReleased(MouseButton.Right)) {
- Logger.Error("Right mouse button is released!");
- }
-
- if (Input.IsMouseMoving(out Vector2 pos)) {
- Logger.Error("Mouse moves: " + pos);
- }
-
- if (Input.IsMouseScrolling(out float wheelDelta)) {
- Logger.Error("Mouse is scrolling: " + wheelDelta);
- }
-
- if (Input.IsKeyDown(Key.A)) {
- Logger.Error("Key A is down");
- }
-
- if (Input.IsKeyPressed(Key.D)) {
- Logger.Error("Key D is pressed");
- }
-
- if (Input.IsKeyReleased(Key.D)) {
- Logger.Error("Key D is released");
- }*/
-
- //if (Input.IsGamepadAvailable(0)) {
- // //Logger.Warn(Input.GetGamepadName(0));
- // Input.GetGamepadName(0);
- //}
-
- if (Input.IsGamepadAvailable(0)) {
- if (Input.IsGamepadButtonPressed(0, GamepadButton.A)) {
- Input.SetGamepadRumble(0, 0xFFFF, 0xFFFF, 1000);
- }
- }
-
- if (Input.IsGamepadAvailable(1)) {
- if (Input.IsGamepadButtonPressed(1, GamepadButton.A)) {
- Input.SetGamepadRumble(1, 0xFFFF, 0xFFFF, 1000);
- }
- }
-
- if (Input.IsFileDragDropped(out string path)) {
- Logger.Warn(path);
- }
- }
+ protected virtual void Update() { }
protected virtual void AfterUpdate() { }
protected virtual void FixedUpdate() { }
- protected virtual void Draw(Graphics graphics) {
-
- }
+ protected virtual void Draw(GraphicsDevice graphicsDevice, CommandList commandList) { }
protected virtual void OnClose() { }
diff --git a/src/Bliss/CSharp/Colors/Color.cs b/src/Bliss/CSharp/Colors/Color.cs
index 2605a9a..fc7803c 100644
--- a/src/Bliss/CSharp/Colors/Color.cs
+++ b/src/Bliss/CSharp/Colors/Color.cs
@@ -97,7 +97,7 @@ public Color(byte r, byte g, byte b, byte a) {
/// Converts the color to an RgbaFloat value.
///
/// A new instance of the RgbaFloat struct representing the color.
- public readonly RgbaFloat ToRgbaFloat() {
+ public RgbaFloat ToRgbaFloat() {
return new RgbaFloat(this.R / 255.0F, this.G / 255.0F, this.B / 255.0F, this.A / 255.0F);
}
diff --git a/src/Bliss/CSharp/Disposable.cs b/src/Bliss/CSharp/Disposable.cs
index d47bdc0..82f9cd7 100644
--- a/src/Bliss/CSharp/Disposable.cs
+++ b/src/Bliss/CSharp/Disposable.cs
@@ -4,6 +4,10 @@ namespace Bliss.CSharp;
public abstract class Disposable : IDisposable {
+ ///
+ /// Indicates whether the object has been disposed.
+ ///
+ /// True if the object has been disposed; otherwise, false.
public bool HasDisposed { get; private set; }
///
diff --git a/src/Bliss/CSharp/Geometry/Box/BoundingBox.cs b/src/Bliss/CSharp/Geometry/Box/BoundingBox.cs
new file mode 100644
index 0000000..3dc9503
--- /dev/null
+++ b/src/Bliss/CSharp/Geometry/Box/BoundingBox.cs
@@ -0,0 +1,26 @@
+using System.Numerics;
+
+namespace Bliss.CSharp.Geometry.Box;
+
+public struct BoundingBox {
+
+ ///
+ /// Minimum box-corner.
+ ///
+ public Vector3 Min;
+
+ ///
+ /// Maximum box-corner.
+ ///
+ public Vector3 Max;
+
+ ///
+ /// Initializes a new instance of the struct with the specified minimum and maximum vectors.
+ ///
+ /// The minimum vector defining one corner of the bounding box.
+ /// The maximum vector defining the opposite corner of the bounding box.
+ public BoundingBox(Vector3 min, Vector3 max) {
+ this.Min = min;
+ this.Max = max;
+ }
+}
\ No newline at end of file
diff --git a/src/Bliss/CSharp/Geometry/Box/OrientedBoundingBox.cs b/src/Bliss/CSharp/Geometry/Box/OrientedBoundingBox.cs
new file mode 100644
index 0000000..191d4ae
--- /dev/null
+++ b/src/Bliss/CSharp/Geometry/Box/OrientedBoundingBox.cs
@@ -0,0 +1,33 @@
+using System.Numerics;
+
+namespace Bliss.CSharp.Geometry.Box;
+
+public struct OrientedBoundingBox {
+
+ ///
+ /// Minimum box-corner.
+ ///
+ public Vector3 Min;
+
+ ///
+ /// Maximum box-corner.
+ ///
+ public Vector3 Max;
+
+ ///
+ /// Box rotation.
+ ///
+ public Quaternion Rotation;
+
+ ///
+ /// Initializes a new instance of the struct with the specified minimum and maximum vectors and rotation.
+ ///
+ /// The minimum vector defining one corner of the bounding box.
+ /// The maximum vector defining the opposite corner of the bounding box.
+ /// The rotation of the bounding box as a quaternion.
+ public OrientedBoundingBox(Vector3 min, Vector3 max, Quaternion rotation) {
+ this.Min = min;
+ this.Max = max;
+ this.Rotation = rotation;
+ }
+}
\ No newline at end of file
diff --git a/src/Bliss/CSharp/Interact/Input.cs b/src/Bliss/CSharp/Interact/Input.cs
index 782812e..b7525a8 100644
--- a/src/Bliss/CSharp/Interact/Input.cs
+++ b/src/Bliss/CSharp/Interact/Input.cs
@@ -48,18 +48,18 @@ public static void Init(Window window) {
_mouseButtonsDown = new List();
_mouseButtonsReleased = new List();
- Window.Sdl2Window.MouseWheel += OnMouseWheel;
- Window.Sdl2Window.MouseMove += OnMouseMove;
- Window.Sdl2Window.MouseDown += OnMouseDown;
- Window.Sdl2Window.MouseUp += OnMouseUp;
+ Window.MouseWheel += OnMouseWheel;
+ Window.MouseMove += OnMouseMove;
+ Window.MouseDown += OnMouseDown;
+ Window.MouseUp += OnMouseUp;
// Keyboard
_keyboardKeysPressed = new List();
_keyboardKeysDown = new List();
_keyboardKeysReleased = new List();
- Window.Sdl2Window.KeyDown += OnKeyDown;
- Window.Sdl2Window.KeyUp += OnKeyUp;
+ Window.KeyDown += OnKeyDown;
+ Window.KeyUp += OnKeyUp;
// Gamepads
_gamepads = new Dictionary();
@@ -67,7 +67,7 @@ public static void Init(Window window) {
// Other
_filesDragDropped = new List();
- Window.Sdl2Window.DragDrop += OnDragDrop;
+ Window.DragDrop += OnDragDrop;
}
///
@@ -492,14 +492,14 @@ public static void Destroy() {
// Mouse
SetMouseCursor(MouseCursor.Default); // To free the Cursor.
- Window.Sdl2Window.MouseWheel -= OnMouseWheel;
- Window.Sdl2Window.MouseMove -= OnMouseMove;
- Window.Sdl2Window.MouseDown -= OnMouseDown;
- Window.Sdl2Window.MouseUp -= OnMouseUp;
+ Window.MouseWheel -= OnMouseWheel;
+ Window.MouseMove -= OnMouseMove;
+ Window.MouseDown -= OnMouseDown;
+ Window.MouseUp -= OnMouseUp;
// Keyboard
- Window.Sdl2Window.KeyDown -= OnKeyDown;
- Window.Sdl2Window.KeyUp -= OnKeyUp;
+ Window.KeyDown -= OnKeyDown;
+ Window.KeyUp -= OnKeyUp;
// Gamepad
foreach (Gamepad gamepad in _gamepads.Values) {
@@ -509,7 +509,7 @@ public static void Destroy() {
_gamepads.Clear();
// Other
- Window.Sdl2Window.DragDrop -= OnDragDrop;
+ Window.DragDrop -= OnDragDrop;
// Event
Sdl2Events.Unsubscribe(ProcessEvent);
diff --git a/src/Bliss/CSharp/Rendering/Graphics.cs b/src/Bliss/CSharp/Rendering/Graphics.cs
deleted file mode 100644
index a34022c..0000000
--- a/src/Bliss/CSharp/Rendering/Graphics.cs
+++ /dev/null
@@ -1,269 +0,0 @@
-using System.Numerics;
-using System.Runtime.InteropServices;
-using Bliss.CSharp.Colors;
-using Bliss.CSharp.Geometry;
-using Bliss.CSharp.Shaders;
-using Bliss.CSharp.Textures;
-using Veldrid;
-
-namespace Bliss.CSharp.Rendering;
-
-public class Graphics : Disposable {
-
- public GraphicsDevice GraphicsDevice { get; private set; }
- public CommandList CommandList { get; private set; }
-
- public (Shader, Shader) DefaultShader { get; private set; }
- public ResourceLayout ResourceLayout { get; private set; }
- public ResourceSet ResourceSet { get; private set; }
- public Pipeline DefaultPipeline { get; private set; }
-
- public DeviceBuffer MvpBuffer { get; private set; }
- public DeviceBuffer ColorBuffer { get; private set; }
-
- public DeviceBuffer VertexBuffer { get; private set; }
- public DeviceBuffer IndexBuffer { get; private set; }
-
- ///
- /// Initializes a new instance of the class with the specified graphics device and command list.
- ///
- /// The graphics device used for rendering operations.
- /// The command list used to issue rendering commands.
- public Graphics(GraphicsDevice graphicsDevice, CommandList commandList) {
- this.GraphicsDevice = graphicsDevice;
- this.CommandList = commandList;
-
- // Load Default Shader
- this.DefaultShader = ShaderHelper.Load(graphicsDevice.ResourceFactory, "content/shaders/default_shader.vert", "content/shaders/default_shader.frag");
-
- // Create uniform buffers
- this.MvpBuffer = graphicsDevice.ResourceFactory.CreateBuffer(new BufferDescription(64, BufferUsage.UniformBuffer)); // 64 bytes for mat4
- this.ColorBuffer = graphicsDevice.ResourceFactory.CreateBuffer(new BufferDescription(16, BufferUsage.UniformBuffer)); // 16 bytes for vec4
-
- // Load texture
- Texture2D texture = new Texture2D(graphicsDevice, "content/image.png");
-
- // Create resource layout
- this.ResourceLayout = graphicsDevice.ResourceFactory.CreateResourceLayout(
- new ResourceLayoutDescription(
- new ResourceLayoutElementDescription("MVP", ResourceKind.UniformBuffer, ShaderStages.Vertex),
- new ResourceLayoutElementDescription("Color", ResourceKind.UniformBuffer, ShaderStages.Fragment),
- new ResourceLayoutElementDescription("texture0", ResourceKind.TextureReadOnly, ShaderStages.Fragment),
- new ResourceLayoutElementDescription("Sampler", ResourceKind.Sampler, ShaderStages.Fragment)
- )
- );
-
- // Create resource set
- this.ResourceSet = graphicsDevice.ResourceFactory.CreateResourceSet(new ResourceSetDescription(this.ResourceLayout, this.MvpBuffer, this.ColorBuffer, texture.DeviceTexture, graphicsDevice.PointSampler));
-
- // Create Default Pipeline
- this.DefaultPipeline = graphicsDevice.ResourceFactory.CreateGraphicsPipeline(new GraphicsPipelineDescription() {
- BlendState = BlendStateDescription.SingleOverrideBlend,
- DepthStencilState = new DepthStencilStateDescription() {
- DepthTestEnabled = true,
- DepthWriteEnabled = true,
- DepthComparison = ComparisonKind.LessEqual
- },
- RasterizerState = new RasterizerStateDescription() {
- CullMode = FaceCullMode.Back,
- FillMode = PolygonFillMode.Solid,
- FrontFace = FrontFace.Clockwise,
- DepthClipEnabled = true,
- ScissorTestEnabled = false
- },
- PrimitiveTopology = PrimitiveTopology.TriangleStrip,
- ResourceLayouts = [
- this.ResourceLayout
- ],
- ShaderSet = new ShaderSetDescription() {
- VertexLayouts = [
- new VertexLayoutDescription(
- new VertexElementDescription("vertexPosition", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float3),
- new VertexElementDescription("vertexTexCoord", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float2),
- new VertexElementDescription("vertexColor", VertexElementSemantic.TextureCoordinate, VertexElementFormat.Float4)
- )
- ],
- Shaders = [
- this.DefaultShader.Item1,
- this.DefaultShader.Item2
- ]
- },
- Outputs = graphicsDevice.SwapchainFramebuffer.OutputDescription
- });
-
- // Create vertex and index buffer
- this.VertexBuffer = this.GraphicsDevice.ResourceFactory.CreateBuffer(new BufferDescription((uint) (4 * Marshal.SizeOf()), BufferUsage.VertexBuffer));
- this.IndexBuffer = this.GraphicsDevice.ResourceFactory.CreateBuffer(new BufferDescription(4 * sizeof(ushort), BufferUsage.IndexBuffer));
- }
-
- /* --------------------------------- Normal --------------------------------- */
-
- ///
- /// Begins the drawing operations.
- ///
- public void BeginDrawing() {
- this.CommandList.Begin();
- this.CommandList.SetFramebuffer(this.GraphicsDevice.SwapchainFramebuffer);
- }
-
- ///
- /// Ends the drawing operations.
- ///
- public void EndDrawing() {
- this.CommandList.End();
- this.GraphicsDevice.SubmitCommands(this.CommandList);
- this.GraphicsDevice.SwapBuffers();
- this.GraphicsDevice.WaitForIdle();
- }
-
- ///
- /// Clears the background color and depth stencil of the command list.
- ///
- /// The index of the color target to clear.
- /// The color used to clear the background.
- public void ClearBackground(uint index, Color clearColor) {
- this.CommandList.ClearColorTarget(index, clearColor.ToRgbaFloat());
-
- if (this.GraphicsDevice.SwapchainFramebuffer.DepthTarget != null) {
- this.CommandList.ClearDepthStencil(this.GraphicsDevice.IsDepthRangeZeroToOne ? 0.0F : 1.0F, 0);
- }
- }
-
- /* --------------------------------- Texture Drawing --------------------------------- */
-
- public void DrawTexture(Texture2D texture) {
- // Get the screen dimensions
- float screenWidth = this.GraphicsDevice.SwapchainFramebuffer.Width;
- float screenHeight = this.GraphicsDevice.SwapchainFramebuffer.Height;
-
- // Get the texture dimensions
- float textureWidth = texture.Width;
- float textureHeight = texture.Height;
-
- // Calculate normalized device coordinates for the texture's position and size
- Vector2 topLeft = new Vector2(
- -1.0f, // Start at the left of the screen (NDC -1.0)
- 1.0f // Start at the top of the screen (NDC 1.0)
- );
-
- Vector2 bottomRight = new Vector2(
- (textureWidth / screenWidth) * 2.0f - 1.0f, // Scale texture width to NDC
- 1.0f - (textureHeight / screenHeight) * 2.0f // Scale texture height to NDC
- );
-
- // Update Vertex Buffer with positions and texture coordinates
- this.GraphicsDevice.UpdateBuffer(this.VertexBuffer, 0, new Vertex[] {
- new Vertex()
- {
- Position = new Vector3(topLeft.X, topLeft.Y, 0.0f),
- TexCoords = new Vector2(0.0f, 0.0f),
- Color = Vector4.One
- },
- new Vertex()
- {
- Position = new Vector3(bottomRight.X, topLeft.Y, 0.0f),
- TexCoords = new Vector2(1.0f, 0.0f),
- Color = Vector4.One
- },
- new Vertex()
- {
- Position = new Vector3(topLeft.X, bottomRight.Y, 0.0f),
- TexCoords = new Vector2(0.0f, 1.0f),
- Color = Vector4.One
- },
- new Vertex()
- {
- Position = new Vector3(bottomRight.X, bottomRight.Y, 0.0f),
- TexCoords = new Vector2(1.0f, 1.0f),
- Color = Vector4.One
- }
- });
-
- // Update Index Buffer
- ushort[] quadIndices = [0, 1, 2, 3];
- this.GraphicsDevice.UpdateBuffer(this.IndexBuffer, 0, quadIndices);
-
- // Update MVP Buffer (Identity matrix in this case)
- Matrix4x4 mvp = Matrix4x4.Identity;
- this.GraphicsDevice.UpdateBuffer(this.MvpBuffer, 0, ref mvp);
-
- // Setup pipeline and resources
- this.CommandList.SetVertexBuffer(0, this.VertexBuffer);
- this.CommandList.SetIndexBuffer(this.IndexBuffer, IndexFormat.UInt16);
- this.CommandList.SetPipeline(this.DefaultPipeline);
- this.CommandList.SetGraphicsResourceSet(0, this.ResourceSet);
-
- // Draw the textured quad
- this.CommandList.DrawIndexed(4, 1, 0, 0, 0);
- }
-
- /* --------------------------------- Text Drawing --------------------------------- */
-
- public void DrawText(string text) {
- }
-
- /* --------------------------------- Shape Drawing --------------------------------- */
-
- public void DrawRectangle(Rectangle rectangle, Color color) {
-
- // Update Vertex Buffer
- this.GraphicsDevice.UpdateBuffer(this.VertexBuffer, 0, new Vertex[] {
- new Vertex() {
- Position = new Vector3(-0.5F, 0.5F, 0.0F),
- TexCoords = new Vector2(0.0F, 0.0F),
- Color = color.ToRgbaFloat().ToVector4()
- },
- new Vertex() {
- Position = new Vector3(0.5F, 0.5F, 0.0F),
- TexCoords = new Vector2(1.0F, 0.0F),
- Color = color.ToRgbaFloat().ToVector4()
- },
- new Vertex() {
- Position = new Vector3(-0.5F, -0.5F, 0.0F),
- TexCoords = new Vector2(0.0F, 1.0F),
- Color = color.ToRgbaFloat().ToVector4()
- },
- new Vertex() {
- Position = new Vector3(0.5F, -0.5F, 0.0F),
- TexCoords = new Vector2(1.0F, 1.0F),
- Color = color.ToRgbaFloat().ToVector4()
- }
- });
-
- // Update Index Buffer
- ushort[] quadIndices = [0, 1, 2, 3];
- this.GraphicsDevice.UpdateBuffer(this.IndexBuffer, 0, quadIndices);
-
- // Update Uniform Buffers
- Matrix4x4 mvp = Matrix4x4.Identity; // Normally you'd calculate a proper MVP matrix here
- this.GraphicsDevice.UpdateBuffer(this.MvpBuffer, 0, ref mvp);
-
- Vector4 finalColor = color.ToVector4();
- this.GraphicsDevice.UpdateBuffer(this.ColorBuffer, 0, ref finalColor);
-
- // Setup pipeline and resources
- this.CommandList.SetVertexBuffer(0, this.VertexBuffer);
- this.CommandList.SetIndexBuffer(this.IndexBuffer, IndexFormat.UInt16);
- this.CommandList.SetPipeline(this.DefaultPipeline);
- this.CommandList.SetGraphicsResourceSet(0, this.ResourceSet);
-
- // Draw rectangle
- this.CommandList.DrawIndexed(4, 1, 0, 0, 0);
- }
-
- /* --------------------------------- Model Drawing --------------------------------- */
-
- public void DrawModel(Model model) {
-
- }
-
- protected override void Dispose(bool disposing) {
- if (disposing) {
- this.DefaultPipeline.Dispose();
- this.DefaultShader.Item1.Dispose();
- this.DefaultShader.Item2.Dispose();
- this.VertexBuffer.Dispose();
- this.IndexBuffer.Dispose();
- }
- }
-}
\ No newline at end of file
diff --git a/src/Bliss/CSharp/Windowing/Window.cs b/src/Bliss/CSharp/Windowing/Window.cs
index cb0aa09..7417baa 100644
--- a/src/Bliss/CSharp/Windowing/Window.cs
+++ b/src/Bliss/CSharp/Windowing/Window.cs
@@ -7,8 +7,6 @@ namespace Bliss.CSharp.Windowing;
public class Window {
- // Todo: SDL2 Window events in this class!
-
///
/// Gets the underlying SDL2 window.
///
@@ -48,6 +46,96 @@ public class Window {
/// Gets the mouse movement delta.
///
public Vector2 MouseDelta => this.Sdl2Window.MouseDelta;
+
+ ///
+ /// Occurs when the window is resized.
+ ///
+ public event Action Resized;
+
+ ///
+ /// Occurs when the window is about to close.
+ ///
+ public event Action Closing;
+
+ ///
+ /// Occurs after the window has closed.
+ ///
+ public event Action Closed;
+
+ ///
+ /// Occurs when the window gains focus.
+ ///
+ public event Action FocusGained;
+
+ ///
+ /// Occurs when the window loses focus.
+ ///
+ public event Action FocusLost;
+
+ ///
+ /// Occurs when the window is shown.
+ ///
+ public event Action Shown;
+
+ ///
+ /// Occurs when the window is hidden.
+ ///
+ public event Action Hidden;
+
+ ///
+ /// Occurs when the window is exposed (made visible or unhidden).
+ ///
+ public event Action Exposed;
+
+ ///
+ /// Occurs when the window is moved.
+ ///
+ public event Action Moved;
+
+ ///
+ /// Occurs when the mouse enters the window.
+ ///
+ public event Action MouseEntered;
+
+ ///
+ /// Occurs when the mouse leaves the window.
+ ///
+ public event Action MouseLeft;
+
+ ///
+ /// Occurs when the mouse wheel is scrolled.
+ ///
+ public event Action MouseWheel;
+
+ ///
+ /// Occurs when the mouse is moved.
+ ///
+ public event Action MouseMove;
+
+ ///
+ /// Occurs when a mouse button is pressed.
+ ///
+ public event Action MouseDown;
+
+ ///
+ /// Occurs when a mouse button is released.
+ ///
+ public event Action MouseUp;
+
+ ///
+ /// Occurs when a key is pressed.
+ ///
+ public event Action KeyDown;
+
+ ///
+ /// Occurs when a key is released.
+ ///
+ public event Action KeyUp;
+
+ ///
+ /// Occurs when a drag-and-drop operation is performed.
+ ///
+ public event Action DragDrop;
///
/// Initializes a new instance of the class with the specified properties and creates a graphics device.
@@ -69,6 +157,25 @@ public Window(int width, int height, string title, GraphicsDeviceOptions options
VeldridStartup.CreateWindowAndGraphicsDevice(info, options, backend, out this.Sdl2Window, out graphicsDevice);
Sdl2Native.SDL_Init(SDLInitFlags.GameController | SDLInitFlags.Joystick);
+
+ this.Sdl2Window.Resized += this.OnResize;
+ this.Sdl2Window.Closing += this.OnClosing;
+ this.Sdl2Window.Closed += this.OnClosed;
+ this.Sdl2Window.FocusGained += this.OnFocusGained;
+ this.Sdl2Window.FocusLost += this.OnFocusLost;
+ this.Sdl2Window.Shown += this.OnShowing;
+ this.Sdl2Window.Hidden += this.OnHiding;
+ this.Sdl2Window.MouseEntered += this.OnMouseEntered;
+ this.Sdl2Window.MouseLeft += this.OnMouseLeft;
+ this.Sdl2Window.Exposed += this.OnExposing;
+ this.Sdl2Window.Moved += this.OnMoving;
+ this.Sdl2Window.MouseWheel += this.OnMouseWheel;
+ this.Sdl2Window.MouseMove += this.OnMouseMoving;
+ this.Sdl2Window.MouseDown += this.OnMouseDown;
+ this.Sdl2Window.MouseUp += this.OnMouseUp;
+ this.Sdl2Window.KeyDown += this.OnKeyDown;
+ this.Sdl2Window.KeyUp += this.OnKeyUp;
+ this.Sdl2Window.DragDrop += this.OnDragDrop;
}
///
@@ -220,6 +327,159 @@ public Point ScreenToClient(Point point) {
/// Closes the window.
///
public void Close() {
+ this.Sdl2Window.Resized -= this.OnResize;
+ this.Sdl2Window.Closing -= this.OnClosing;
+ this.Sdl2Window.Closed -= this.OnClosed;
+ this.Sdl2Window.FocusGained -= this.OnFocusGained;
+ this.Sdl2Window.FocusLost -= this.OnFocusLost;
+ this.Sdl2Window.Shown -= this.OnShowing;
+ this.Sdl2Window.Hidden -= this.OnHiding;
+ this.Sdl2Window.MouseEntered -= this.OnMouseEntered;
+ this.Sdl2Window.MouseLeft -= this.OnMouseLeft;
+ this.Sdl2Window.Exposed -= this.OnExposing;
+ this.Sdl2Window.Moved -= this.OnMoving;
+ this.Sdl2Window.MouseWheel -= this.OnMouseWheel;
+ this.Sdl2Window.MouseMove -= this.OnMouseMoving;
+ this.Sdl2Window.MouseDown -= this.OnMouseDown;
+ this.Sdl2Window.MouseUp -= this.OnMouseUp;
+ this.Sdl2Window.KeyDown -= this.OnKeyDown;
+ this.Sdl2Window.KeyUp -= this.OnKeyUp;
+ this.Sdl2Window.DragDrop -= this.OnDragDrop;
+
this.Sdl2Window.Close();
}
+
+ ///
+ /// Invokes the event when the window is resized.
+ ///
+ private void OnResize() {
+ this.Resized?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the window is about to close.
+ ///
+ private void OnClosing() {
+ this.Closing?.Invoke();
+ }
+
+ ///
+ /// Invokes the event after the window has closed.
+ ///
+ private void OnClosed() {
+ this.Closed?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the window gains focus.
+ ///
+ private void OnFocusGained() {
+ this.FocusGained?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the window loses focus.
+ ///
+ private void OnFocusLost() {
+ this.FocusLost?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the window is shown.
+ ///
+ private void OnShowing() {
+ this.Shown?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the window is hidden.
+ ///
+ private void OnHiding() {
+ this.Hidden?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the window is exposed.
+ ///
+ private void OnExposing() {
+ this.Exposed?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the window is moved, passing the new position.
+ ///
+ /// The new position of the window.
+ private void OnMoving(Point point) {
+ this.Moved?.Invoke(point);
+ }
+
+ ///
+ /// Invokes the event when the mouse enters the window.
+ ///
+ private void OnMouseEntered() {
+ this.MouseEntered?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the mouse leaves the window.
+ ///
+ private void OnMouseLeft() {
+ this.MouseLeft?.Invoke();
+ }
+
+ ///
+ /// Invokes the event when the mouse wheel is scrolled.
+ ///
+ /// The mouse wheel event arguments.
+ private void OnMouseWheel(MouseWheelEventArgs args) {
+ this.MouseWheel?.Invoke(args);
+ }
+
+ ///
+ /// Invokes the event when the mouse is moved.
+ ///
+ /// The mouse move event arguments.
+ private void OnMouseMoving(MouseMoveEventArgs args) {
+ this.MouseMove?.Invoke(args);
+ }
+
+ ///
+ /// Invokes the event when a mouse button is pressed.
+ ///
+ /// The mouse event arguments.
+ private void OnMouseDown(MouseEvent mouseEvent) {
+ this.MouseDown?.Invoke(mouseEvent);
+ }
+
+ ///
+ /// Invokes the event when a mouse button is released.
+ ///
+ /// The mouse event arguments.
+ private void OnMouseUp(MouseEvent mouseEvent) {
+ this.MouseUp?.Invoke(mouseEvent);
+ }
+
+ ///
+ /// Invokes the event when a key is pressed.
+ ///
+ /// The key event arguments.
+ private void OnKeyDown(KeyEvent keyEvent) {
+ this.KeyDown?.Invoke(keyEvent);
+ }
+
+ ///
+ /// Invokes the event when a key is released.
+ ///
+ /// The key event arguments.
+ private void OnKeyUp(KeyEvent keyEvent) {
+ this.KeyUp?.Invoke(keyEvent);
+ }
+
+ ///
+ /// Invokes the event when a drag-and-drop operation is performed.
+ ///
+ /// The drag-and-drop event arguments.
+ private void OnDragDrop(DragDropEvent dropEvent) {
+ this.DragDrop?.Invoke(dropEvent);
+ }
}
\ No newline at end of file