From 0d5db764926de5f852fb345f2f556d30a08e6c9e Mon Sep 17 00:00:00 2001 From: elasota Date: Mon, 2 Nov 2020 22:06:38 -0500 Subject: [PATCH] Add text input on mobile --- Aerofoil/GpSystemServices_Win32.cpp | 4 ++++ Aerofoil/GpSystemServices_Win32.h | 2 ++ .../app/jni/main/GpSystemServices_Android.cpp | 11 +++++++++++ .../app/jni/main/GpSystemServices_Android.h | 6 ++++++ AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp | 15 +++++++++++++-- PortabilityLayer/HostSystemServices.h | 2 ++ PortabilityLayer/PLEditboxWidget.cpp | 9 +++++++++ 7 files changed, 47 insertions(+), 2 deletions(-) diff --git a/Aerofoil/GpSystemServices_Win32.cpp b/Aerofoil/GpSystemServices_Win32.cpp index 4fbfd99..f33fc50 100644 --- a/Aerofoil/GpSystemServices_Win32.cpp +++ b/Aerofoil/GpSystemServices_Win32.cpp @@ -151,6 +151,10 @@ unsigned int GpSystemServices_Win32::GetCPUCount() const return sysInfo.dwNumberOfProcessors; } +void GpSystemServices_Win32::SetTextInputEnabled(bool isEnabled) +{ +} + void GpSystemServices_Win32::SetTouchscreenSimulation(bool isTouchscreenSimulation) { m_isTouchscreenSimulation = isTouchscreenSimulation; diff --git a/Aerofoil/GpSystemServices_Win32.h b/Aerofoil/GpSystemServices_Win32.h index 4d2be2c..834fcc0 100644 --- a/Aerofoil/GpSystemServices_Win32.h +++ b/Aerofoil/GpSystemServices_Win32.h @@ -32,6 +32,8 @@ public: bool IsUsingMouseAsTouch() const override; bool IsTextInputObstructive() const override; unsigned int GetCPUCount() const override; + void SetTextInputEnabled(bool isEnabled) override; + bool IsTextInputEnabled() const override; void SetTouchscreenSimulation(bool isTouchscreenSimulation); diff --git a/AerofoilAndroid/app/jni/main/GpSystemServices_Android.cpp b/AerofoilAndroid/app/jni/main/GpSystemServices_Android.cpp index a2710e0..d29a110 100644 --- a/AerofoilAndroid/app/jni/main/GpSystemServices_Android.cpp +++ b/AerofoilAndroid/app/jni/main/GpSystemServices_Android.cpp @@ -166,6 +166,7 @@ void GpThreadEvent_Cpp11::Destroy() } GpSystemServices_Android::GpSystemServices_Android() + : m_textInputEnabled(false) { } @@ -269,6 +270,16 @@ unsigned int GpSystemServices_Android::GetCPUCount() const return SDL_GetCPUCount(); } +void GpSystemServices_Android::SetTextInputEnabled(bool isEnabled) +{ + m_textInputEnabled = isEnabled; +} + +bool GpSystemServices_Android::IsTextInputEnabled() const +{ + return m_textInputEnabled; +} + GpSystemServices_Android *GpSystemServices_Android::GetInstance() { return &ms_instance; diff --git a/AerofoilAndroid/app/jni/main/GpSystemServices_Android.h b/AerofoilAndroid/app/jni/main/GpSystemServices_Android.h index efcbcee..f726505 100644 --- a/AerofoilAndroid/app/jni/main/GpSystemServices_Android.h +++ b/AerofoilAndroid/app/jni/main/GpSystemServices_Android.h @@ -20,9 +20,15 @@ public: bool IsUsingMouseAsTouch() const override; bool IsTextInputObstructive() const override; unsigned int GetCPUCount() const override; + void SetTextInputEnabled(bool isEnabled) override; + bool IsTextInputEnabled() const override; + + void FlushTextInputEnabled(); static GpSystemServices_Android *GetInstance(); private: static GpSystemServices_Android ms_instance; + + bool m_textInputEnabled; }; diff --git a/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp b/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp index 3ed7e3b..aecb468 100644 --- a/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp +++ b/AerofoilSDL/GpDisplayDriver_SDL_GL2.cpp @@ -912,6 +912,8 @@ private: uint8_t m_paletteStorage[256 * 4 + GP_SYSTEM_MEMORY_ALIGNMENT]; uint8_t *m_paletteData; + + bool m_textInputEnabled; }; @@ -1205,6 +1207,7 @@ GpDisplayDriver_SDL_GL2::GpDisplayDriver_SDL_GL2(const GpDisplayDriverProperties , m_contextLost(true) , m_lastSurface(nullptr) , m_firstSurface(nullptr) + , m_textInputEnabled(false) { m_bgColor[0] = 0.f; m_bgColor[1] = 0.f; @@ -1915,7 +1918,6 @@ void GpDisplayDriver_SDL_GL2::Run() } TranslateSDLMessage(&msg, m_properties.m_eventQueue, m_pixelScaleX, m_pixelScaleY, obstructiveTextInput); - } else { @@ -1937,7 +1939,6 @@ void GpDisplayDriver_SDL_GL2::Run() int clientHeight = 0; SDL_GetWindowSize(m_window, &clientWidth, &clientHeight); - unsigned int desiredWidth = clientWidth; unsigned int desiredHeight = clientHeight; if (desiredWidth != m_windowWidthPhysical || desiredHeight != m_windowHeightPhysical || m_isResolutionResetDesired) @@ -2011,6 +2012,16 @@ void GpDisplayDriver_SDL_GL2::Run() continue; } + bool wantTextInput = m_properties.m_systemServices->IsTextInputEnabled(); + if (wantTextInput != m_textInputEnabled) + { + m_textInputEnabled = wantTextInput; + if (m_textInputEnabled) + SDL_StartTextInput(); + else + SDL_StopTextInput(); + } + GpDisplayDriverTickStatus_t tickStatus = PresentFrameAndSync(); if (tickStatus == GpDisplayDriverTickStatuses::kFatalFault || tickStatus == GpDisplayDriverTickStatuses::kApplicationTerminated) { diff --git a/PortabilityLayer/HostSystemServices.h b/PortabilityLayer/HostSystemServices.h index 000eb7c..8fa7fff 100644 --- a/PortabilityLayer/HostSystemServices.h +++ b/PortabilityLayer/HostSystemServices.h @@ -32,6 +32,8 @@ namespace PortabilityLayer virtual bool IsUsingMouseAsTouch() const = 0; virtual bool IsTextInputObstructive() const = 0; virtual unsigned int GetCPUCount() const = 0; + virtual void SetTextInputEnabled(bool isEnabled) = 0; + virtual bool IsTextInputEnabled() const = 0; static void SetInstance(HostSystemServices *instance); static HostSystemServices *GetInstance(); diff --git a/PortabilityLayer/PLEditboxWidget.cpp b/PortabilityLayer/PLEditboxWidget.cpp index 1bc9242..fbd30e0 100644 --- a/PortabilityLayer/PLEditboxWidget.cpp +++ b/PortabilityLayer/PLEditboxWidget.cpp @@ -2,6 +2,7 @@ #include "FontFamily.h" #include "FontManager.h" +#include "HostSystemServices.h" #include "InputManager.h" #include "MacRomanConversion.h" #include "MemoryManager.h" @@ -42,6 +43,9 @@ namespace PortabilityLayer EditboxWidget::~EditboxWidget() { + if (m_hasFocus) + PortabilityLayer::HostSystemServices::GetInstance()->SetTextInputEnabled(false); + PortabilityLayer::MemoryManager *mm = PortabilityLayer::MemoryManager::GetInstance(); if (m_chars) @@ -155,10 +159,15 @@ namespace PortabilityLayer DrawSurface *surface = m_window->GetDrawSurface(); DrawControl(surface); } + + PortabilityLayer::HostSystemServices::GetInstance()->SetTextInputEnabled(true); } void EditboxWidget::LoseFocus() { + if (m_hasFocus) + PortabilityLayer::HostSystemServices::GetInstance()->SetTextInputEnabled(false); + m_hasFocus = false; m_selStartChar = 0; m_selEndChar = 0;