2023-05-18 19:32:29 +02:00
|
|
|
/*
|
|
|
|
* InputSourceText.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "StdInc.h"
|
|
|
|
#include "InputSourceText.h"
|
|
|
|
|
|
|
|
#include "../CMT.h"
|
|
|
|
#include "../gui/CGuiHandler.h"
|
|
|
|
#include "../gui/EventDispatcher.h"
|
2023-07-05 16:17:01 +02:00
|
|
|
#include "../render/IScreenHandler.h"
|
|
|
|
#include "../renderSDL/SDL_Extensions.h"
|
2023-05-18 19:32:29 +02:00
|
|
|
|
|
|
|
#include "../../lib/Rect.h"
|
|
|
|
|
|
|
|
#include <SDL_events.h>
|
|
|
|
|
|
|
|
#ifdef VCMI_APPLE
|
|
|
|
# include <dispatch/dispatch.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef VCMI_IOS
|
|
|
|
# include "ios/utils.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text)
|
|
|
|
{
|
|
|
|
GH.events().dispatchTextInput(text.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputSourceText::handleEventTextEditing(const SDL_TextEditingEvent & text)
|
|
|
|
{
|
|
|
|
GH.events().dispatchTextEditing(text.text);
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputSourceText::startTextInput(const Rect & whereInput)
|
|
|
|
{
|
2023-07-05 16:17:01 +02:00
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
#ifdef VCMI_APPLE
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
#endif
|
|
|
|
|
2023-07-05 16:17:01 +02:00
|
|
|
Rect rectInScreenCoordinates = GH.screenHandler().convertLogicalPointsToWindow(whereInput);
|
|
|
|
SDL_Rect textInputRect = CSDL_Ext::toSDL(rectInScreenCoordinates);
|
2023-05-18 19:32:29 +02:00
|
|
|
|
2023-07-05 16:17:01 +02:00
|
|
|
SDL_SetTextInputRect(&textInputRect);
|
2023-05-18 19:32:29 +02:00
|
|
|
|
|
|
|
if (SDL_IsTextInputActive() == SDL_FALSE)
|
|
|
|
{
|
|
|
|
SDL_StartTextInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef VCMI_APPLE
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputSourceText::stopTextInput()
|
|
|
|
{
|
|
|
|
#ifdef VCMI_APPLE
|
|
|
|
dispatch_async(dispatch_get_main_queue(), ^{
|
|
|
|
#endif
|
|
|
|
|
|
|
|
if (SDL_IsTextInputActive() == SDL_TRUE)
|
|
|
|
{
|
|
|
|
SDL_StopTextInput();
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef VCMI_APPLE
|
|
|
|
});
|
|
|
|
#endif
|
|
|
|
}
|