From cee712105850ac3385cd0091a923438167433f9f Mon Sep 17 00:00:00 2001
From: TSR Berry <20988865+TSRBerry@users.noreply.github.com>
Date: Sat, 8 Apr 2023 01:22:00 +0200
Subject: Move solution and projects to src
---
src/Ryujinx.Input/IMouse.cs | 104 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 104 insertions(+)
create mode 100644 src/Ryujinx.Input/IMouse.cs
(limited to 'src/Ryujinx.Input/IMouse.cs')
diff --git a/src/Ryujinx.Input/IMouse.cs b/src/Ryujinx.Input/IMouse.cs
new file mode 100644
index 00000000..fde150fc
--- /dev/null
+++ b/src/Ryujinx.Input/IMouse.cs
@@ -0,0 +1,104 @@
+using System.Drawing;
+using System.Numerics;
+
+namespace Ryujinx.Input
+{
+ ///
+ /// Represent an emulated mouse.
+ ///
+ public interface IMouse : IGamepad
+ {
+ private const int SwitchPanelWidth = 1280;
+ private const int SwitchPanelHeight = 720;
+
+ ///
+ /// Check if a given button is pressed on the mouse.
+ ///
+ /// The button
+ /// True if the given button is pressed on the mouse
+ bool IsButtonPressed(MouseButton button);
+
+ ///
+ /// Get the position of the mouse in the client.
+ ///
+ Vector2 GetPosition();
+
+ ///
+ /// Get the mouse scroll delta.
+ ///
+ Vector2 GetScroll();
+
+ ///
+ /// Get the client size.
+ ///
+ Size ClientSize { get; }
+
+ ///
+ /// Get the button states of the mouse.
+ ///
+ bool[] Buttons { get; }
+
+ ///
+ /// Get a snaphost of the state of a mouse.
+ ///
+ /// The mouse to do a snapshot of
+ /// A snaphost of the state of the mouse.
+ public static MouseStateSnapshot GetMouseStateSnapshot(IMouse mouse)
+ {
+ bool[] buttons = new bool[(int)MouseButton.Count];
+
+ mouse.Buttons.CopyTo(buttons, 0);
+
+ return new MouseStateSnapshot(buttons, mouse.GetPosition(), mouse.GetScroll());
+ }
+
+ ///
+ /// Get the position of a mouse on screen relative to the app's view
+ ///
+ /// The position of the mouse in the client
+ /// The size of the client
+ /// The aspect ratio of the view
+ /// A snaphost of the state of the mouse.
+ public static Vector2 GetScreenPosition(Vector2 mousePosition, Size clientSize, float aspectRatio)
+ {
+ float mouseX = mousePosition.X;
+ float mouseY = mousePosition.Y;
+
+ float aspectWidth = SwitchPanelHeight * aspectRatio;
+
+ int screenWidth = clientSize.Width;
+ int screenHeight = clientSize.Height;
+
+ if (clientSize.Width > clientSize.Height * aspectWidth / SwitchPanelHeight)
+ {
+ screenWidth = (int)(clientSize.Height * aspectWidth) / SwitchPanelHeight;
+ }
+ else
+ {
+ screenHeight = (clientSize.Width * SwitchPanelHeight) / (int)aspectWidth;
+ }
+
+ int startX = (clientSize.Width - screenWidth) >> 1;
+ int startY = (clientSize.Height - screenHeight) >> 1;
+
+ int endX = startX + screenWidth;
+ int endY = startY + screenHeight;
+
+ if (mouseX >= startX &&
+ mouseY >= startY &&
+ mouseX < endX &&
+ mouseY < endY)
+ {
+ int screenMouseX = (int)mouseX - startX;
+ int screenMouseY = (int)mouseY - startY;
+
+ mouseX = (screenMouseX * (int)aspectWidth) / screenWidth;
+ mouseY = (screenMouseY * SwitchPanelHeight) / screenHeight;
+
+ return new Vector2(mouseX, mouseY);
+ }
+
+ return new Vector2();
+ }
+ }
+}
\ No newline at end of file
--
cgit v1.2.3