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 "../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>
|
|
|
|
|
2024-04-11 21:00:20 +02:00
|
|
|
InputSourceText::InputSourceText()
|
|
|
|
{
|
|
|
|
// For whatever reason, in SDL text input is considered to be active by default at least on desktop platforms
|
|
|
|
// Apparently fixed in SDL3, but until then we need a workaround
|
|
|
|
SDL_StopTextInput();
|
|
|
|
}
|
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
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)
|
|
|
|
{
|
2024-01-22 22:19:52 +02:00
|
|
|
GH.dispatchMainThread([whereInput]()
|
2023-05-18 19:32:29 +02:00
|
|
|
{
|
2024-01-22 22:19:52 +02:00
|
|
|
Rect rectInScreenCoordinates = GH.screenHandler().convertLogicalPointsToWindow(whereInput);
|
|
|
|
SDL_Rect textInputRect = CSDL_Ext::toSDL(rectInScreenCoordinates);
|
|
|
|
|
|
|
|
SDL_SetTextInputRect(&textInputRect);
|
2023-05-18 19:32:29 +02:00
|
|
|
|
2024-01-22 22:19:52 +02:00
|
|
|
if (SDL_IsTextInputActive() == SDL_FALSE)
|
|
|
|
{
|
|
|
|
SDL_StartTextInput();
|
|
|
|
}
|
2023-05-18 19:32:29 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
void InputSourceText::stopTextInput()
|
|
|
|
{
|
2024-01-22 22:19:52 +02:00
|
|
|
GH.dispatchMainThread([]()
|
2023-05-18 19:32:29 +02:00
|
|
|
{
|
2024-01-22 22:19:52 +02:00
|
|
|
if (SDL_IsTextInputActive() == SDL_TRUE)
|
|
|
|
{
|
|
|
|
SDL_StopTextInput();
|
|
|
|
}
|
2023-05-18 19:32:29 +02:00
|
|
|
});
|
|
|
|
}
|