Added support for on screen keyboard on Windows.

--HG--
branch : dev
This commit is contained in:
Martín Lucas Golini
2020-01-12 14:56:40 -03:00
parent f60d4c183e
commit af29d3e7ef
12 changed files with 189 additions and 34 deletions

View File

@@ -1,6 +1,7 @@
#ifndef EE_VIRTUALFILESYSTEM_HPP
#define EE_VIRTUALFILESYSTEM_HPP
#include <cstddef>
#include <eepp/system/container.hpp>
#include <eepp/system/iostream.hpp>
#include <eepp/system/pack.hpp>

View File

@@ -37,14 +37,22 @@ namespace WindowBackend {
enum { SDL2, Default };
}
#ifndef EE_SCREEN_KEYBOARD_ENABLED
#if EE_PLATFORM == EE_PLATFORM_ANDROID || EE_PLATFORM == EE_PLATFORM_IOS
#define EE_SCREEN_KEYBOARD_ENABLED true
#else
#define EE_SCREEN_KEYBOARD_ENABLED false
#endif
#endif
/** @brief WindowSettings A small class that contains the window settings */
class WindowSettings {
public:
inline WindowSettings( Uint32 width, Uint32 height, const std::string& caption = std::string(),
Uint32 style = WindowStyle::Default,
Uint32 backend = WindowBackend::Default, Uint32 bpp = 32,
const std::string& icon = std::string(),
const Float& pixelDensity = 1 ) :
const std::string& icon = std::string(), const Float& pixelDensity = 1,
const bool& useScreenKeyboard = EE_SCREEN_KEYBOARD_ENABLED ) :
Style( style ),
Width( width ),
Height( height ),
@@ -52,7 +60,8 @@ class WindowSettings {
Icon( icon ),
Caption( caption ),
Backend( backend ),
PixelDensity( pixelDensity ) {}
PixelDensity( pixelDensity ),
UseScreenKeyboard( useScreenKeyboard ) {}
inline WindowSettings() :
Style( WindowStyle::Default ),
@@ -60,7 +69,8 @@ class WindowSettings {
Height( 600 ),
BitsPerPixel( 32 ),
Backend( WindowBackend::Default ),
PixelDensity( 1 ) {}
PixelDensity( 1 ),
UseScreenKeyboard( EE_SCREEN_KEYBOARD_ENABLED ) {}
Uint32 Style;
Uint32 Width;
@@ -70,6 +80,7 @@ class WindowSettings {
std::string Caption;
Uint32 Backend;
Float PixelDensity;
bool UseScreenKeyboard;
};
/** @brief ContextSettings Small class that contains the renderer context information */
@@ -405,8 +416,8 @@ class EE_API Window {
virtual bool isScreenKeyboardShown();
/** @return True if the current window support a threaded GL Context. This means that supports
*OpenGL Shared Contexts ( multithreaded opengl contexts ). * Only supported with SDL2
*backend.*/
*OpenGL Shared Contexts ( multithreaded opengl contexts ). * Only supported with SDL2
*backend.*/
virtual bool isThreadedGLContext();
/** Activates the shared GL context in the current thread. */

View File

@@ -465,9 +465,9 @@ function generate_os_links()
table.insert( os_links, "dl" )
end
elseif os.is_real("windows") then
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm" } )
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
elseif os.is_real("mingw32") then
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm" } )
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
elseif os.is_real("macosx") then
multiple_insert( os_links, { "OpenGL.framework", "OpenAL.framework", "CoreFoundation.framework" } )
elseif os.is_real("freebsd") then
@@ -916,6 +916,7 @@ solution "eepp"
project "eepp-ew"
set_kind()
language "C++"
links { "ole32" }
files { "src/examples/empty_window/*.cpp" }
build_link_configuration( "eeew", true )

View File

@@ -302,9 +302,9 @@ function generate_os_links()
table.insert( os_links, "dl" )
end
elseif os.istarget("windows") then
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm" } )
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
elseif os.istarget("mingw32") then
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm" } )
multiple_insert( os_links, { "OpenAL32", "opengl32", "glu32", "gdi32", "ws2_32", "winmm", "ole32" } )
elseif os.istarget("macosx") then
multiple_insert( os_links, { "OpenGL.framework", "OpenAL.framework", "CoreFoundation.framework" } )
elseif os.istarget("freebsd") then

View File

@@ -1,5 +1,4 @@
#define EE_SDL_VERSION_2
#define EE_X11_PLATFORM
#define EE_DEBUG
#define EE_MEMORY_MANAGER
#define EE_SHADERS_SUPPORTED

View File

@@ -1,4 +1,6 @@
../../README.md
../../bin/assets/ee.ini
../../bin/assets/layouts/imported.css
../../bin/assets/layouts/test.css
../../bin/assets/layouts/test.xml
../../bin/assets/layouts/test_widgets.xml
@@ -26,13 +28,11 @@
../../include/eepp/audio/soundsource.hpp
../../include/eepp/audio/soundstream.hpp
../../include/eepp/config.hpp
../../include/eepp/core/allocator.hpp
../../include/eepp/core/core.hpp
../../include/eepp/core/debug.hpp
../../include/eepp/core.hpp
../../include/eepp/core/memorymanager.hpp
../../include/eepp/core/noncopyable.hpp
../../include/eepp/core/stlcontainers.hpp
../../include/eepp/core/string.hpp
../../include/eepp/core/utf.hpp
../../include/eepp/core/utf.inl
@@ -49,7 +49,6 @@
../../include/eepp/graphics/drawableresource.hpp
../../include/eepp/graphics/drawablesearcher.hpp
../../include/eepp/graphics/fontbmfont.hpp
../../include/eepp/graphics/fonthelper.hpp
../../include/eepp/graphics/font.hpp
../../include/eepp/graphics/fontmanager.hpp
../../include/eepp/graphics/fontsprite.hpp
@@ -102,6 +101,7 @@
../../include/eepp/graphics/textureloader.hpp
../../include/eepp/graphics/texturepacker.hpp
../../include/eepp/graphics/textureregion.hpp
../../include/eepp/graphics/triangledrawable.hpp
../../include/eepp/graphics/vertexbufferhelper.hpp
../../include/eepp/graphics/vertexbuffer.hpp
../../include/eepp/graphics/vertexbuffermanager.hpp
@@ -215,7 +215,6 @@
../../include/eepp/scene.hpp
../../include/eepp/scene/keyevent.hpp
../../include/eepp/scene/mouseevent.hpp
../../include/eepp/scene/nodeattribute.hpp
../../include/eepp/scene/node.hpp
../../include/eepp/scene/nodemessage.hpp
../../include/eepp/scene/scenemanager.hpp
@@ -230,6 +229,7 @@
../../include/eepp/system/directorypack.hpp
../../include/eepp/system/filesystem.hpp
../../include/eepp/system.hpp
../../include/eepp/system/functionstring.hpp
../../include/eepp/system/inifile.hpp
../../include/eepp/system/iostreamdeflate.hpp
../../include/eepp/system/iostreamfile.hpp
@@ -288,17 +288,27 @@
../../include/eepp/thirdparty/PlusCallback/callback.hpp
../../include/eepp/ui/base.hpp
../../include/eepp/ui.hpp
../../include/eepp/ui/css/mediaquery.hpp
../../include/eepp/ui/css/propertydefinition.hpp
../../include/eepp/ui/css/propertyspecification.hpp
../../include/eepp/ui/css/shorthanddefinition.hpp
../../include/eepp/ui/css/stylesheet.hpp
../../include/eepp/ui/css/stylesheetelement.hpp
../../include/eepp/ui/css/stylesheetlength.hpp
../../include/eepp/ui/css/stylesheetparser.hpp
../../include/eepp/ui/css/stylesheetpropertiesparser.hpp
../../include/eepp/ui/css/stylesheetproperty.hpp
../../include/eepp/ui/css/stylesheetpropertytransition.hpp
../../include/eepp/ui/css/stylesheetselector.hpp
../../include/eepp/ui/css/stylesheetselectorparser.hpp
../../include/eepp/ui/css/stylesheetselectorrule.hpp
../../include/eepp/ui/css/stylesheetspecification.hpp
../../include/eepp/ui/css/stylesheetstyle.hpp
../../include/eepp/ui/css/stylesheetvariable.hpp
../../include/eepp/ui/css/transitiondefinition.hpp
../../include/eepp/ui/marginmove/scale.hpp
../../include/eepp/ui/tools/textureatlaseditor.hpp
../../include/eepp/ui/tools/uicolorpicker.hpp
../../include/eepp/ui/uicheckbox.hpp
../../include/eepp/ui/uicombobox.hpp
../../include/eepp/ui/uicommondialog.hpp
@@ -322,6 +332,7 @@
../../include/eepp/ui/uimenusubmenu.hpp
../../include/eepp/ui/uimessagebox.hpp
../../include/eepp/ui/uinode.hpp
../../include/eepp/ui/uinodedrawable.hpp
../../include/eepp/ui/uipopupmenu.hpp
../../include/eepp/ui/uiprogressbar.hpp
../../include/eepp/ui/uipushbutton.hpp
@@ -333,7 +344,6 @@
../../include/eepp/ui/uiselectbutton.hpp
../../include/eepp/ui/uiskin.hpp
../../include/eepp/ui/uiskinstate.hpp
../../include/eepp/ui/uisliderbutton.hpp
../../include/eepp/ui/uislider.hpp
../../include/eepp/ui/uispinbox.hpp
../../include/eepp/ui/uisprite.hpp
@@ -528,6 +538,7 @@
../../src/eepp/graphics/texturepackertex.hpp
../../src/eepp/graphics/textureregion.cpp
../../src/eepp/graphics/scopedtexture.hpp
../../src/eepp/graphics/triangledrawable.cpp
../../src/eepp/graphics/vertexbuffer.cpp
../../src/eepp/graphics/vertexbuffermanager.cpp
../../src/eepp/graphics/vertexbuffermanager.hpp
@@ -647,7 +658,6 @@
../../src/eepp/scene/eventdispatcher.cpp
../../src/eepp/scene/keyevent.cpp
../../src/eepp/scene/mouseevent.cpp
../../src/eepp/scene/nodeattribute.cpp
../../src/eepp/scene/node.cpp
../../src/eepp/scene/nodemessage.cpp
../../src/eepp/scene/scenemanager.cpp
@@ -659,6 +669,7 @@
../../src/eepp/system/condition.cpp
../../src/eepp/system/directorypack.cpp
../../src/eepp/system/filesystem.cpp
../../src/eepp/system/functionstring.cpp
../../src/eepp/system/inifile.cpp
../../src/eepp/system/iostreamdeflate.cpp
../../src/eepp/system/iostreamfile.cpp
@@ -706,19 +717,29 @@
../../src/eepp/system/translator.cpp
../../src/eepp/system/virtualfilesystem.cpp
../../src/eepp/system/zip.cpp
../../src/eepp/ui/css/mediaquery.cpp
../../src/eepp/ui/css/propertydefinition.cpp
../../src/eepp/ui/css/propertyspecification.cpp
../../src/eepp/ui/css/shorthanddefinition.cpp
../../src/eepp/ui/css/stylesheet.cpp
../../src/eepp/ui/css/stylesheetlength.cpp
../../src/eepp/ui/css/stylesheetparser.cpp
../../src/eepp/ui/css/stylesheetpropertiesparser.cpp
../../src/eepp/ui/css/stylesheetproperty.cpp
../../src/eepp/ui/css/stylesheetpropertytransition.cpp
../../src/eepp/ui/css/stylesheetselector.cpp
../../src/eepp/ui/css/stylesheetselectorparser.cpp
../../src/eepp/ui/css/stylesheetselectorrule.cpp
../../src/eepp/ui/css/stylesheetspecification.cpp
../../src/eepp/ui/css/stylesheetstyle.cpp
../../src/eepp/ui/css/stylesheetvariable.cpp
../../src/eepp/ui/css/transitiondefinition.cpp
../../src/eepp/ui/tools/textureatlaseditor.cpp
../../src/eepp/ui/tools/textureatlasnew.cpp
../../src/eepp/ui/tools/textureatlasnew.hpp
../../src/eepp/ui/tools/textureatlastextureregioneditor.cpp
../../src/eepp/ui/tools/textureatlastextureregioneditor.hpp
../../src/eepp/ui/tools/uicolorpicker.cpp
../../src/eepp/ui/uicheckbox.cpp
../../src/eepp/ui/uicombobox.cpp
../../src/eepp/ui/uicommondialog.cpp
@@ -739,6 +760,7 @@
../../src/eepp/ui/uimenusubmenu.cpp
../../src/eepp/ui/uimessagebox.cpp
../../src/eepp/ui/uinode.cpp
../../src/eepp/ui/uinodedrawable.cpp
../../src/eepp/ui/uipopupmenu.cpp
../../src/eepp/ui/uiprogressbar.cpp
../../src/eepp/ui/uipushbutton.cpp
@@ -750,7 +772,6 @@
../../src/eepp/ui/uiselectbutton.cpp
../../src/eepp/ui/uiskin.cpp
../../src/eepp/ui/uiskinstate.cpp
../../src/eepp/ui/uisliderbutton.cpp
../../src/eepp/ui/uislider.cpp
../../src/eepp/ui/uispinbox.cpp
../../src/eepp/ui/uisprite.cpp

View File

@@ -161,6 +161,8 @@ Uint32 UITextInput::onFocus() {
mTextBuffer.setActive( true );
resetWaitCursor();
getSceneNode()->getWindow()->startTextInput();
}
return 1;
@@ -168,6 +170,7 @@ Uint32 UITextInput::onFocus() {
Uint32 UITextInput::onFocusLoss() {
mTextBuffer.setActive( false );
getSceneNode()->getWindow()->stopTextInput();
return UITextView::onFocusLoss();
}

View File

@@ -21,6 +21,109 @@
#define SDL2_THREADED_GLCONTEXT
#endif
#if EE_PLATFORM == EE_PLATFORM_WIN
#include <Objbase.h>
#include <initguid.h>
#include <shellapi.h>
#include <tlhelp32.H>
bool WindowsIsProcessRunning( const char* processName, bool killProcess = false ) {
bool exists = false;
PROCESSENTRY32 entry = {};
entry.dwSize = sizeof( PROCESSENTRY32 );
HANDLE snapshot = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );
if ( Process32First( snapshot, &entry ) ) {
while ( Process32Next( snapshot, &entry ) ) {
if ( !stricmp( entry.szExeFile, processName ) ) {
exists = true;
if ( killProcess ) {
HANDLE aProc = OpenProcess( PROCESS_TERMINATE, 0, entry.th32ProcessID );
if ( aProc ) {
TerminateProcess( aProc, 9 );
CloseHandle( aProc );
}
}
break;
}
}
}
CloseHandle( snapshot );
return exists;
}
#ifndef ERROR_ELEVATION_REQUIRED
#define ERROR_ELEVATION_REQUIRED ( 740 )
#endif // ERROR_ELEVATION_REQUIRED
bool WindowsProcessLaunch( std::string command, HWND windowHwnd ) {
char expandedCmd[1024] = {};
static PROCESS_INFORMATION pi = {};
static STARTUPINFO si = {};
si.cb = sizeof( si );
ExpandEnvironmentStrings( command.c_str(), expandedCmd, 1024 );
if ( CreateProcess( NULL, expandedCmd, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi ) ) {
// Wait until child process exits.
WaitForSingleObject( pi.hProcess, 10000 );
CloseHandle( pi.hProcess );
CloseHandle( pi.hThread );
return true;
} else {
DWORD error = GetLastError();
if ( error == ERROR_ELEVATION_REQUIRED && 0 != windowHwnd ) {
if ( reinterpret_cast<std::intptr_t>( ShellExecute( windowHwnd, "open", expandedCmd, "",
NULL, SW_SHOWDEFAULT ) ) <= 32 ) {
return false;
}
}
}
return false;
}
// 4ce576fa-83dc-4F88-951c-9d0782b4e376
DEFINE_GUID( CLSID_UIHostNoLaunch, 0x4CE576FA, 0x83DC, 0x4f88, 0x95, 0x1C, 0x9D, 0x07, 0x82, 0xB4,
0xE3, 0x76 );
// 37c994e7_432b_4834_a2f7_dce1f13b834b
DEFINE_GUID( IID_ITipInvocation, 0x37c994e7, 0x432b, 0x4834, 0xa2, 0xf7, 0xdc, 0xe1, 0xf1, 0x3b,
0x83, 0x4b );
struct ITipInvocation : IUnknown {
virtual HRESULT STDMETHODCALLTYPE Toggle( HWND wnd ) = 0;
};
static bool WIN_OSK_VISIBLE = false;
int showOSK( HWND windowHwnd ) {
if ( !WindowsIsProcessRunning( "TabTip.exe" ) ) {
WindowsIsProcessRunning(
"WindowsInternal.ComposableShell.Experiences.TextInput.InputApp.EXE", true );
std::string programFiles( Sys::getOSArchitecture() == "x64" ? "%ProgramW6432%"
: "%ProgramFiles(x86)%" );
WindowsProcessLaunch( programFiles + "\\Common Files\\microsoft shared\\ink\\TabTip.exe",
windowHwnd );
}
CoInitialize( 0 );
ITipInvocation* tip;
CoCreateInstance( CLSID_UIHostNoLaunch, 0, CLSCTX_INPROC_HANDLER | CLSCTX_LOCAL_SERVER,
IID_ITipInvocation, (void**)&tip );
if ( tip != NULL ) {
tip->Toggle( GetDesktopWindow() );
tip->Release();
WIN_OSK_VISIBLE = true;
}
return 0;
}
int hideOSK() {
WIN_OSK_VISIBLE = false;
return PostMessage( GetDesktopWindow(), WM_SYSCOMMAND, (int)SC_CLOSE, 0 );
}
#endif
namespace EE { namespace Window { namespace Backend { namespace SDL2 {
WindowSDL::WindowSDL( WindowSettings Settings, ContextSettings Context ) :
@@ -46,13 +149,13 @@ WindowSDL::~WindowSDL() {
SDL_GL_DeleteContext( mGLContextThread );
}
if ( NULL != mSDLWindow ) {
SDL_DestroyWindow( mSDLWindow );
}
#ifdef EE_USE_WMINFO
eeSAFE_DELETE( mWMinfo );
#endif
if ( NULL != mSDLWindow ) {
SDL_DestroyWindow( mSDLWindow );
}
}
bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) {
@@ -208,6 +311,10 @@ bool WindowSDL::create( WindowSettings Settings, ContextSettings Context ) {
SDL_GL_MakeCurrent( mSDLWindow, mGLContext );
#ifdef EE_USE_WMINFO
mWMinfo = eeNew( WMInfo, ( mSDLWindow ) );
#endif
if ( NULL == Renderer::existsSingleton() ) {
Renderer::createSingleton( mWindow.ContextConfig.Version );
Renderer::instance()->init();
@@ -621,15 +728,31 @@ SDL_Window* WindowSDL::GetSDLWindow() const {
}
void WindowSDL::startTextInput() {
SDL_StartTextInput();
if ( mWindow.WindowConfig.UseScreenKeyboard ) {
#if EE_PLATFORM == EE_PLATFORM_WIN
showOSK( getWindowHandler() );
#else
SDL_StartTextInput();
#endif
}
}
bool WindowSDL::isTextInputActive() {
#if EE_PLATFORM == EE_PLATFORM_WIN
return WIN_OSK_VISIBLE;
#else
return SDL_TRUE == SDL_IsTextInputActive();
#endif
}
void WindowSDL::stopTextInput() {
SDL_StopTextInput();
if ( mWindow.WindowConfig.UseScreenKeyboard ) {
#if EE_PLATFORM == EE_PLATFORM_WIN
hideOSK();
#else
SDL_StopTextInput();
#endif
}
}
void WindowSDL::setTextInputRect( Rect& rect ) {

View File

@@ -18,7 +18,7 @@
namespace EE { namespace Window { namespace Backend { namespace SDL2 {
#ifdef EE_WMINFO
WMInfo::WMInfo( SDL_Window* win ) : mWMInfo( eeNew( SDL_SysWMinfo, () ) ) {
WMInfo::WMInfo( SDL_Window* win ) : mWMInfo( eeMalloc( sizeof(SDL_SysWMinfo) ) ) {
SDL_SysWMinfo* info = static_cast<SDL_SysWMinfo*>( mWMInfo );
SDL_VERSION( &info->version );
SDL_GetWindowWMInfo( win, info );
@@ -29,8 +29,7 @@ WMInfo::WMInfo( SDL_Window* win ) : mWMInfo( NULL ) {}
WMInfo::~WMInfo() {
#ifdef EE_WMINFO
SDL_SysWMinfo* info = static_cast<SDL_SysWMinfo*>( mWMInfo );
eeSAFE_DELETE( info );
eeSAFE_FREE( mWMInfo );
#endif
}

View File

@@ -6,7 +6,7 @@
namespace EE { namespace Window { namespace Backend { namespace SDL2 {
class WMInfo {
class EE_API WMInfo {
public:
WMInfo( SDL_Window* win );

View File

@@ -243,6 +243,7 @@ WindowSettings Engine::createWindowSettings( IniFile* ini, std::string iniKeyNam
bool UseDesktopResolution = ini->getValueB( iniKeyName, "UseDesktopResolution", false );
std::string pixelDensityStr = ini->getValue( iniKeyName, "PixelDensity" );
float pixelDensity = PixelDensity::getPixelDensity();
bool useScreenKeyboard = ini->getValueB( iniKeyName, "UseScreenKeyboard" );
if ( !pixelDensityStr.empty() ) {
if ( String::toLower( pixelDensityStr ) == "auto" ) {
@@ -283,7 +284,7 @@ WindowSettings Engine::createWindowSettings( IniFile* ini, std::string iniKeyNam
std::string Caption = ini->getValue( iniKeyName, "WinCaption", "" );
WindowSettings WinSettings( Width, Height, Caption, Style, WinBackend, BitColor, Icon,
pixelDensity );
pixelDensity, useScreenKeyboard );
return WinSettings;
}
@@ -339,7 +340,7 @@ ContextSettings Engine::createContextSettings( IniFile* ini, std::string iniKeyN
ContextSettings Engine::createContextSettings( std::string iniPath, std::string iniKeyName ) {
IniFile Ini( iniPath );
return createContextSettings( &Ini );
return createContextSettings( &Ini, iniKeyName );
}
void Engine::enableSharedGLContext() {

View File

@@ -1,9 +1,5 @@
#include <eepp/ee.hpp>
#include <eepp/audio/music.hpp>
#include <eepp/audio/sound.hpp>
#include <eepp/audio/soundbuffer.hpp>
EE::Window::Window* win = NULL;
void mainLoop() {