From 33b31f91556ecd917d91b2d4c81b404139d145a4 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Wed, 2 Jun 2021 09:48:02 +0200 Subject: [PATCH] Fix using Keyboard and Mouse in C# scripting --- Source/Engine/Platform/Android/AndroidPlatform.cpp | 8 ++++---- Source/Engine/Platform/Linux/LinuxPlatform.cpp | 8 ++++---- Source/Engine/Platform/UWP/UWPPlatform.cpp | 8 ++++---- Source/Engine/Platform/UWP/UWPWindow.cpp | 4 ++-- Source/Engine/Platform/Windows/WindowsInput.cpp | 12 ++++++------ 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Source/Engine/Platform/Android/AndroidPlatform.cpp b/Source/Engine/Platform/Android/AndroidPlatform.cpp index 786df6654..5b9d02424 100644 --- a/Source/Engine/Platform/Android/AndroidPlatform.cpp +++ b/Source/Engine/Platform/Android/AndroidPlatform.cpp @@ -260,7 +260,7 @@ namespace String AppPackageName, DeviceManufacturer, DeviceModel, DeviceBuildNumber; String SystemVersion, SystemLanguage, CacheDir, ExecutablePath; byte MacAddress[6]; - AndroidKeyboard KeyboardImpl; + AndroidKeyboard* KeyboardImpl; AndroidDeviceGamepad* GamepadImpl; AndroidTouchScreen* TouchScreenImpl; ScreenOrientationType Orientation; @@ -496,9 +496,9 @@ namespace if (eventType.KeyboardKey != KeyboardKeys::None) { if (isDown) - KeyboardImpl.OnKeyDown(eventType.KeyboardKey); + KeyboardImpl->OnKeyDown(eventType.KeyboardKey); else - KeyboardImpl.OnKeyUp(eventType.KeyboardKey); + KeyboardImpl->OnKeyUp(eventType.KeyboardKey); } // Gamepad @@ -850,7 +850,7 @@ bool AndroidPlatform::Init() } // Setup native platform input devices - Input::Keyboard = &KeyboardImpl; + Input::Keyboard = KeyboardImpl = New(); Input::Gamepads.Add(GamepadImpl = New()); Input::OnGamepadsChanged(); Input::CustomDevices.Add(TouchScreenImpl = New()); diff --git a/Source/Engine/Platform/Linux/LinuxPlatform.cpp b/Source/Engine/Platform/Linux/LinuxPlatform.cpp index 90bd1784f..74d39df7e 100644 --- a/Source/Engine/Platform/Linux/LinuxPlatform.cpp +++ b/Source/Engine/Platform/Linux/LinuxPlatform.cpp @@ -1195,8 +1195,8 @@ struct Property namespace Impl { - LinuxKeyboard Keyboard; - LinuxMouse Mouse; + LinuxKeyboard* Keyboard; + LinuxMouse* Mouse; StringAnsi ClipboardText; void ClipboardGetText(String& result, X11::Atom source, X11::Atom atom, X11::Window window) @@ -2193,8 +2193,8 @@ bool LinuxPlatform::Init() } } - Input::Mouse = &Impl::Mouse; - Input::Keyboard = &Impl::Keyboard; + Input::Mouse = Impl::Mouse = New(); + Input::Keyboard = Impl::Keyboard = New(); return false; } diff --git a/Source/Engine/Platform/UWP/UWPPlatform.cpp b/Source/Engine/Platform/UWP/UWPPlatform.cpp index 522d5db15..b0fdf8f21 100644 --- a/Source/Engine/Platform/UWP/UWPPlatform.cpp +++ b/Source/Engine/Platform/UWP/UWPPlatform.cpp @@ -22,8 +22,8 @@ UWPPlatformImpl* CUWPPlatform = nullptr; namespace Impl { - extern UWPWindow::UWPKeyboard Keyboard; - extern UWPWindow::UWPMouse Mouse; + extern UWPWindow::UWPKeyboard* Keyboard; + extern UWPWindow::UWPMouse* Mouse; extern UWPWindow* Window; } @@ -62,8 +62,8 @@ bool UWPPlatform::Init() UserName = String::Empty; SystemDpi = CUWPPlatform->GetDpi(); - Input::Mouse = &Impl::Mouse; - Input::Keyboard = &Impl::Keyboard; + Input::Mouse = Impl::Mouse = New(); + Input::Keyboard = Impl::Keyboard = New(); return false; } diff --git a/Source/Engine/Platform/UWP/UWPWindow.cpp b/Source/Engine/Platform/UWP/UWPWindow.cpp index ba509b089..a55f3b5d2 100644 --- a/Source/Engine/Platform/UWP/UWPWindow.cpp +++ b/Source/Engine/Platform/UWP/UWPWindow.cpp @@ -11,8 +11,8 @@ namespace Impl { - UWPWindow::UWPKeyboard Keyboard; - UWPWindow::UWPMouse Mouse; + UWPWindow::UWPKeyboard* Keyboard = nullptr; + UWPWindow::UWPMouse* Mouse = nullptr; UWPWindow* Window = nullptr; } diff --git a/Source/Engine/Platform/Windows/WindowsInput.cpp b/Source/Engine/Platform/Windows/WindowsInput.cpp index 177eb067c..2838e2286 100644 --- a/Source/Engine/Platform/Windows/WindowsInput.cpp +++ b/Source/Engine/Platform/Windows/WindowsInput.cpp @@ -105,14 +105,14 @@ namespace WindowsInputImpl { float XInputLastUpdateTime = 0; bool XInputGamepads[XUSER_MAX_COUNT] = { false }; - WindowsMouse Mouse; - WindowsKeyboard Keyboard; + WindowsMouse* Mouse = nullptr; + WindowsKeyboard* Keyboard = nullptr; } void WindowsInput::Init() { - Input::Mouse = &WindowsInputImpl::Mouse; - Input::Keyboard = &WindowsInputImpl::Keyboard; + Input::Mouse = WindowsInputImpl::Mouse = New(); + Input::Keyboard = WindowsInputImpl::Keyboard = New(); } void WindowsInput::Update() @@ -142,9 +142,9 @@ void WindowsInput::Update() bool WindowsInput::WndProc(Window* window, Windows::UINT msg, Windows::WPARAM wParam, Windows::LPARAM lParam) { - if (WindowsInputImpl::Mouse.WndProc(window, msg, wParam, lParam)) + if (WindowsInputImpl::Mouse->WndProc(window, msg, wParam, lParam)) return true; - if (WindowsInputImpl::Keyboard.WndProc(window, msg, wParam, lParam)) + if (WindowsInputImpl::Keyboard->WndProc(window, msg, wParam, lParam)) return true; return false; }