Add text input on mobile

This commit is contained in:
elasota
2020-11-02 22:06:38 -05:00
parent 2ab1416eef
commit 0d5db76492
7 changed files with 47 additions and 2 deletions

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;
};

View File

@@ -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)
{

View File

@@ -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();

View File

@@ -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;