diff --git a/Source/Editor/Content/GUI/ContentView.cs b/Source/Editor/Content/GUI/ContentView.cs
index 5382bd731..424a804e3 100644
--- a/Source/Editor/Content/GUI/ContentView.cs
+++ b/Source/Editor/Content/GUI/ContentView.cs
@@ -673,6 +673,20 @@ namespace FlaxEditor.Content.GUI
}
}
+ ///
+ public override void OnGotFocus()
+ {
+ StartTextInput();
+ base.OnGotFocus();
+ }
+
+ ///
+ public override void OnLostFocus()
+ {
+ EndTextInput();
+ base.OnLostFocus();
+ }
+
///
public override bool OnMouseDown(Float2 location, MouseButton button)
{
diff --git a/Source/Editor/GUI/ContextMenu/ContextMenu.cs b/Source/Editor/GUI/ContextMenu/ContextMenu.cs
index f5705c6f5..42612de09 100644
--- a/Source/Editor/GUI/ContextMenu/ContextMenu.cs
+++ b/Source/Editor/GUI/ContextMenu/ContextMenu.cs
@@ -441,6 +441,20 @@ namespace FlaxEditor.GUI.ContextMenu
}
}
+ ///
+ protected override void OnShow()
+ {
+ StartTextInput();
+ base.OnShow();
+ }
+
+ ///
+ protected override void OnHide()
+ {
+ EndTextInput();
+ base.OnHide();
+ }
+
///
public override bool OnCharInput(char c)
{
diff --git a/Source/Editor/Surface/VisjectSurface.Input.cs b/Source/Editor/Surface/VisjectSurface.Input.cs
index ca15079c0..05e3b9c8b 100644
--- a/Source/Editor/Surface/VisjectSurface.Input.cs
+++ b/Source/Editor/Surface/VisjectSurface.Input.cs
@@ -401,6 +401,13 @@ namespace FlaxEditor.Surface
base.OnMouseMove(location);
CustomMouseMove?.Invoke(ref location);
}
+
+ ///
+ public override void OnGotFocus()
+ {
+ StartTextInput();
+ base.OnGotFocus();
+ }
///
public override void OnLostFocus()
@@ -423,6 +430,7 @@ namespace FlaxEditor.Surface
}
_isMovingSelection = false;
ConnectingEnd(null);
+ EndTextInput();
base.OnLostFocus();
}
@@ -834,7 +842,7 @@ namespace FlaxEditor.Surface
return true;
}
-
+
///
public override bool OnCharInput(char c)
{
diff --git a/Source/Editor/Windows/OutputLogWindow.cs b/Source/Editor/Windows/OutputLogWindow.cs
index b28fb2e61..fba93d4ad 100644
--- a/Source/Editor/Windows/OutputLogWindow.cs
+++ b/Source/Editor/Windows/OutputLogWindow.cs
@@ -144,7 +144,19 @@ namespace FlaxEditor.Windows
{
rect = new Rectangle(2, 0, Width - 4, Height);
}
+
+ public override void OnGotFocus()
+ {
+ StartTextInput();
+ base.OnGotFocus();
+ }
+ public override void OnLostFocus()
+ {
+ EndTextInput();
+ base.OnLostFocus();
+ }
+
public override bool OnCharInput(char c)
{
if (Owner != null && (!Owner._searchPopup?.Visible ?? true))
diff --git a/Source/Engine/Platform/Base/WindowBase.h b/Source/Engine/Platform/Base/WindowBase.h
index 21309c9d9..4ce6dcc89 100644
--- a/Source/Engine/Platform/Base/WindowBase.h
+++ b/Source/Engine/Platform/Base/WindowBase.h
@@ -43,6 +43,7 @@ protected:
Rectangle _mouseOffsetScreenSize;
bool _isUsingMouseOffset = false;
bool _isTrackingMouse = false;
+ bool _isTextInputEnabled = false;
bool _isHorizontalFlippingMouse = false;
bool _isVerticalFlippingMouse = false;
bool _isClippingCursor = false;
@@ -495,6 +496,20 @@ public:
API_FUNCTION() virtual void EndTrackingMouse()
{
}
+
+ ///
+ /// Enables character input events.
+ ///
+ API_FUNCTION() virtual void StartTextInput()
+ {
+ }
+
+ ///
+ /// Disables character input events.
+ ///
+ API_FUNCTION() virtual void EndTextInput()
+ {
+ }
///
/// Starts the cursor clipping.
diff --git a/Source/Engine/Platform/SDL/SDLPlatform.cpp b/Source/Engine/Platform/SDL/SDLPlatform.cpp
index 9cafdfe13..98752a3eb 100644
--- a/Source/Engine/Platform/SDL/SDLPlatform.cpp
+++ b/Source/Engine/Platform/SDL/SDLPlatform.cpp
@@ -157,8 +157,6 @@ bool SDLPlatform::Init()
SDLImpl::SystemDpi = (int)(SDL_GetDisplayContentScale(SDL_GetPrimaryDisplay()) * DefaultDPI);
- //SDL_StartTextInput(); // TODO: Call this only when text input is expected (shows virtual keyboard in some cases)
-
return SDLPlatformBase::Init();
}
diff --git a/Source/Engine/Platform/SDL/SDLWindow.cpp b/Source/Engine/Platform/SDL/SDLWindow.cpp
index a87ebbd89..98b6d9171 100644
--- a/Source/Engine/Platform/SDL/SDLWindow.cpp
+++ b/Source/Engine/Platform/SDL/SDLWindow.cpp
@@ -298,7 +298,7 @@ SDLWindow::~SDLWindow()
// The text input events seems to be controlled globally on macOS,
// calling this for closing window seems to remove keyboard focus from other windows...
-#if !PLATFORM_MAC
+#if !PLATFORM_MAC // TODO: Verify if this is still needed
if (_settings.AllowInput && SDL_TextInputActive(_window))
SDL_StopTextInput(_window);
#endif
@@ -514,8 +514,12 @@ void SDLWindow::HandleEvent(SDL_Event& event)
case SDL_EVENT_WINDOW_FOCUS_GAINED:
{
OnGotFocus();
+#if PLATFORM_MAC // TODO: Verify if this is still needed
if (_settings.AllowInput && !SDLPlatform::UsesX11())
SDL_StartTextInput(_window);
+#endif
+ if (_isTextInputEnabled)
+ SDL_StartTextInput(_window);
if (_isClippingCursor)
{
// The relative mode needs to be disabled for clipping to take effect
@@ -537,8 +541,12 @@ void SDLWindow::HandleEvent(SDL_Event& event)
}
case SDL_EVENT_WINDOW_FOCUS_LOST:
{
+#if PLATFORM_MAC // TODO: Verify if this is still needed
if (_settings.AllowInput && !SDLPlatform::UsesX11())
SDL_StopTextInput(_window);
+#endif
+ if (_isTextInputEnabled)
+ SDL_StopTextInput(_window);
if (_isClippingCursor)
SDL_SetWindowMouseRect(_window, nullptr);
@@ -910,6 +918,28 @@ void SDLWindow::EndTrackingMouse()
_restoreRelativeMode = false;
}
+void SDLWindow::StartTextInput()
+{
+#if !PLATFORM_MAC // TODO: Verify if this is still needed
+ if (_isTextInputEnabled || !_settings.AllowInput || SDLPlatform::UsesX11())
+ return;
+
+ _isTextInputEnabled = true;
+ SDL_StartTextInput(_window);
+#endif
+}
+
+void SDLWindow::EndTextInput()
+{
+#if !PLATFORM_MAC // TODO: Verify if this is still needed
+ if (!_isTextInputEnabled || !_settings.AllowInput || SDLPlatform::UsesX11())
+ return;
+
+ _isTextInputEnabled = false;
+ SDL_StopTextInput(_window);
+#endif
+}
+
void SDLWindow::StartClippingCursor(const Rectangle& bounds)
{
if (!IsFocused())
diff --git a/Source/Engine/Platform/SDL/SDLWindow.h b/Source/Engine/Platform/SDL/SDLWindow.h
index 3c5963f5a..242f7c784 100644
--- a/Source/Engine/Platform/SDL/SDLWindow.h
+++ b/Source/Engine/Platform/SDL/SDLWindow.h
@@ -103,6 +103,8 @@ public:
DragDropEffect DoDragDrop(const StringView& data, const Float2& offset, Window* dragSourceWindow) override;
void StartTrackingMouse(bool useMouseScreenOffset) override;
void EndTrackingMouse() override;
+ void StartTextInput() override;
+ void EndTextInput() override;
void StartClippingCursor(const Rectangle& bounds) override;
void EndClippingCursor() override;
void SetMousePosition(const Float2& position) const override;
diff --git a/Source/Engine/UI/GUI/CanvasRootControl.cs b/Source/Engine/UI/GUI/CanvasRootControl.cs
index 2fe3d0355..57dd15034 100644
--- a/Source/Engine/UI/GUI/CanvasRootControl.cs
+++ b/Source/Engine/UI/GUI/CanvasRootControl.cs
@@ -120,6 +120,20 @@ namespace FlaxEngine.GUI
parent?.EndTrackingMouse();
}
+ ///
+ public override void StartTextInput()
+ {
+ var parent = Parent?.Root;
+ parent?.StartTextInput();
+ }
+
+ ///
+ public override void EndTextInput()
+ {
+ var parent = Parent?.Root;
+ parent?.EndTextInput();
+ }
+
///
public override bool GetKey(KeyboardKeys key)
{
@@ -293,6 +307,20 @@ namespace FlaxEngine.GUI
heldTime = rateTime = 0;
}
}
+
+ ///
+ public override void OnGotFocus()
+ {
+ StartTextInput();
+ base.OnGotFocus();
+ }
+
+ ///
+ public override void OnLostFocus()
+ {
+ EndTextInput();
+ base.OnLostFocus();
+ }
///
public override bool OnCharInput(char c)
diff --git a/Source/Engine/UI/GUI/Common/TextBoxBase.cs b/Source/Engine/UI/GUI/Common/TextBoxBase.cs
index d3dbcc57a..45a56a057 100644
--- a/Source/Engine/UI/GUI/Common/TextBoxBase.cs
+++ b/Source/Engine/UI/GUI/Common/TextBoxBase.cs
@@ -1223,6 +1223,8 @@ namespace FlaxEngine.GUI
if (IsReadOnly)
return;
+
+ StartTextInput();
OnEditBegin();
}
@@ -1233,6 +1235,8 @@ namespace FlaxEngine.GUI
if (IsReadOnly)
return;
+
+ EndTextInput();
OnEditEnd();
}
diff --git a/Source/Engine/UI/GUI/Control.cs b/Source/Engine/UI/GUI/Control.cs
index 2c8138984..db1f722d3 100644
--- a/Source/Engine/UI/GUI/Control.cs
+++ b/Source/Engine/UI/GUI/Control.cs
@@ -598,6 +598,26 @@ namespace FlaxEngine.GUI
public virtual void OnEndMouseCapture()
{
}
+
+ ///
+ /// Enables events.
+ ///
+ [NoAnimate]
+ public virtual void StartTextInput()
+ {
+ var parent = Root;
+ parent?.StartTextInput();
+ }
+
+ ///
+ /// Disables events.
+ ///
+ [NoAnimate]
+ public virtual void EndTextInput()
+ {
+ var parent = Root;
+ parent?.EndTextInput();
+ }
#endregion
@@ -853,8 +873,12 @@ namespace FlaxEngine.GUI
#region Keyboard
///
- /// On input character
+ /// On character input
///
+ ///
+ /// Requires text input enabled in order to receive character input events.
+ /// See .
+ ///
/// Input character
/// True if event has been handled, otherwise false
[NoAnimate]
diff --git a/Source/Engine/UI/GUI/WindowRootControl.cs b/Source/Engine/UI/GUI/WindowRootControl.cs
index 739ff2485..4353ac0e4 100644
--- a/Source/Engine/UI/GUI/WindowRootControl.cs
+++ b/Source/Engine/UI/GUI/WindowRootControl.cs
@@ -195,6 +195,18 @@ namespace FlaxEngine.GUI
_window.EndTrackingMouse();
}
}
+
+ ///
+ public override void StartTextInput()
+ {
+ _window.StartTextInput();
+ }
+
+ ///
+ public override void EndTextInput()
+ {
+ _window.EndTextInput();
+ }
///
public override bool GetKey(KeyboardKeys key)