diff --git a/Source/Engine/Input/Keyboard.h b/Source/Engine/Input/Keyboard.h
index 45f8e295e..7e238bcf5 100644
--- a/Source/Engine/Input/Keyboard.h
+++ b/Source/Engine/Input/Keyboard.h
@@ -26,9 +26,8 @@ protected:
public:
///
- /// Gets the text entered during the current frame.
+ /// Gets the text entered during the current frame (Unicode format).
///
- /// The input text (Unicode).
API_PROPERTY() StringView GetInputText() const
{
return StringView(_state.InputText, _state.InputTextLength);
diff --git a/Source/Engine/Input/Mouse.h b/Source/Engine/Input/Mouse.h
index 7fc2be75a..0acd31238 100644
--- a/Source/Engine/Input/Mouse.h
+++ b/Source/Engine/Input/Mouse.h
@@ -58,7 +58,6 @@ public:
///
/// Gets the position of the mouse in the screen-space coordinates.
///
- /// The mouse position
API_PROPERTY() FORCE_INLINE Float2 GetPosition() const
{
return _state.MousePosition;
@@ -72,7 +71,6 @@ public:
///
/// Gets the delta position of the mouse in the screen-space coordinates.
///
- /// The mouse position delta
API_PROPERTY() FORCE_INLINE Float2 GetPositionDelta() const
{
return _state.MousePosition - _prevState.MousePosition;
@@ -81,7 +79,6 @@ public:
///
/// Gets the mouse wheel change during the last frame.
///
- /// Mouse wheel value delta
API_PROPERTY() FORCE_INLINE float GetScrollDelta() const
{
return _state.MouseWheelDelta;
diff --git a/Source/Engine/Platform/Base/PlatformBase.cpp b/Source/Engine/Platform/Base/PlatformBase.cpp
index eb02c1ce9..89fcc1011 100644
--- a/Source/Engine/Platform/Base/PlatformBase.cpp
+++ b/Source/Engine/Platform/Base/PlatformBase.cpp
@@ -5,6 +5,7 @@
#include "Engine/Platform/MemoryStats.h"
#include "Engine/Platform/MessageBox.h"
#include "Engine/Platform/FileSystem.h"
+#include "Engine/Platform/Window.h"
#include "Engine/Platform/User.h"
#include "Engine/Core/Log.h"
#include "Engine/Core/Types/DateTime.h"
@@ -520,6 +521,21 @@ void PlatformBase::CreateGuid(Guid& result)
result = Guid(dateThingHigh, randomThing | (sequentialThing << 16), cyclesThing, dateThingLow);
}
+Float2 PlatformBase::GetMousePosition()
+{
+ const Window* win = Engine::MainWindow;
+ if (win)
+ return win->ClientToScreen(win->GetMousePosition());
+ return Float2::Minimum;
+}
+
+void PlatformBase::SetMousePosition(const Float2& position)
+{
+ const Window* win = Engine::MainWindow;
+ if (win)
+ win->SetMousePosition(win->ScreenToClient(position));
+}
+
Float2 PlatformBase::GetVirtualDesktopSize()
{
return Platform::GetVirtualDesktopBounds().Size;
diff --git a/Source/Engine/Platform/Base/PlatformBase.h b/Source/Engine/Platform/Base/PlatformBase.h
index e7800c94d..7b06fa3d0 100644
--- a/Source/Engine/Platform/Base/PlatformBase.h
+++ b/Source/Engine/Platform/Base/PlatformBase.h
@@ -660,6 +660,18 @@ public:
public:
+ ///
+ /// Gets the mouse cursor position in screen-space coordinates.
+ ///
+ /// Mouse cursor coordinates.
+ API_PROPERTY() static Float2 GetMousePosition();
+
+ ///
+ /// Sets the mouse cursor position in screen-space coordinates.
+ ///
+ /// Cursor position to set.
+ API_PROPERTY() static void SetMousePosition(const Float2& position);
+
///
/// Gets the origin position and size of the monitor at the given screen-space location.
///
diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp
index 631b8d017..e954dd784 100644
--- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp
+++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp
@@ -2643,10 +2643,8 @@ Float2 LinuxPlatform::GetMousePosition()
{
if (!xDisplay)
return Float2::Zero;
-
- int32 x, y;
+ int32 x = 0, y = 0;
uint32 screenCount = (uint32)X11::XScreenCount(xDisplay);
-
for (uint32 i = 0; i < screenCount; i++)
{
X11::Window outRoot, outChild;
@@ -2655,7 +2653,6 @@ Float2 LinuxPlatform::GetMousePosition()
if (X11::XQueryPointer(xDisplay, X11::XRootWindow(xDisplay, i), &outRoot, &outChild, &x, &y, &childX, &childY, &mask))
break;
}
-
return Float2((float)x, (float)y);
}
diff --git a/Source/Engine/Platform/UWP/UWPPlatform.cpp b/Source/Engine/Platform/UWP/UWPPlatform.cpp
index f7c883878..06a0d964d 100644
--- a/Source/Engine/Platform/UWP/UWPPlatform.cpp
+++ b/Source/Engine/Platform/UWP/UWPPlatform.cpp
@@ -158,27 +158,6 @@ void UWPPlatform::OpenUrl(const StringView& url)
// TODO: add support for OpenUrl on UWP
}
-Float2 UWPPlatform::GetMousePosition()
-{
- // Use the main window
- auto win = Engine::MainWindow;
- if (win)
- {
- return win->ClientToScreen(win->GetMousePosition());
- }
- return Float2::Minimum;
-}
-
-void UWPPlatform::SetMousePosition(const Float2& pos)
-{
- // Use the main window
- auto win = Engine::MainWindow;
- if (win)
- {
- win->SetMousePosition(win->ScreenToClient(pos));
- }
-}
-
Float2 UWPPlatform::GetDesktopSize()
{
Float2 result;
diff --git a/Source/Engine/Platform/UWP/UWPPlatform.h b/Source/Engine/Platform/UWP/UWPPlatform.h
index be114f419..9bc0d7afd 100644
--- a/Source/Engine/Platform/UWP/UWPPlatform.h
+++ b/Source/Engine/Platform/UWP/UWPPlatform.h
@@ -37,8 +37,6 @@ public:
static bool GetHasFocus();
static bool CanOpenUrl(const StringView& url);
static void OpenUrl(const StringView& url);
- static Float2 GetMousePosition();
- static void SetMousePosition(const Float2& pos);
static Rectangle GetMonitorBounds(const Float2& screenPos);
static Float2 GetDesktopSize();
static Rectangle GetVirtualDesktopBounds();
diff --git a/Source/Engine/Platform/Win32/Win32Platform.h b/Source/Engine/Platform/Win32/Win32Platform.h
index b50d31616..d3f9a5cdc 100644
--- a/Source/Engine/Platform/Win32/Win32Platform.h
+++ b/Source/Engine/Platform/Win32/Win32Platform.h
@@ -109,7 +109,7 @@ public:
static void CreateGuid(Guid& result);
static String GetMainDirectory();
static String GetExecutableFilePath();
- static struct Guid GetUniqueDeviceId();
+ static Guid GetUniqueDeviceId();
static String GetWorkingDirectory();
static bool SetWorkingDirectory(const String& path);
static void FreeLibrary(void* handle);
diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.cpp b/Source/Engine/Platform/Windows/WindowsPlatform.cpp
index e215cbaf0..7c8a5b060 100644
--- a/Source/Engine/Platform/Windows/WindowsPlatform.cpp
+++ b/Source/Engine/Platform/Windows/WindowsPlatform.cpp
@@ -825,6 +825,18 @@ void WindowsPlatform::OpenUrl(const StringView& url)
::ShellExecuteW(nullptr, TEXT("open"), *url, nullptr, nullptr, SW_SHOWNORMAL);
}
+Float2 WindowsPlatform::GetMousePosition()
+{
+ POINT cursorPos;
+ GetCursorPos(&cursorPos);
+ return Float2((float)cursorPos.x, (float)cursorPos.y);
+}
+
+void WindowsPlatform::SetMousePosition(const Float2& pos)
+{
+ ::SetCursorPos((int)pos.X, (int)pos.Y);
+}
+
struct GetMonitorBoundsData
{
Float2 Pos;
diff --git a/Source/Engine/Platform/Windows/WindowsPlatform.h b/Source/Engine/Platform/Windows/WindowsPlatform.h
index 7441d0812..a144e09e5 100644
--- a/Source/Engine/Platform/Windows/WindowsPlatform.h
+++ b/Source/Engine/Platform/Windows/WindowsPlatform.h
@@ -71,6 +71,8 @@ public:
static bool GetHasFocus();
static bool CanOpenUrl(const StringView& url);
static void OpenUrl(const StringView& url);
+ static Float2 GetMousePosition();
+ static void SetMousePosition(const Float2& pos);
static Rectangle GetMonitorBounds(const Float2& screenPos);
static Float2 GetDesktopSize();
static Rectangle GetVirtualDesktopBounds();