1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-05-29 22:57:49 +02:00
vcmi/client/eventsSDL/InputSourceText.cpp
Ivan Savenko cacceda950 Renamed CGuiHandler to GameEngine
- class CGuiHandler is now called GameEngine to better describe its
functionality
- renamed global GH to more clear ENGINE
- GH/ENGINE is now unique_ptr to make construction / deconstruction
order more clear and to allow interface / implementation split
- CGuiHandler.cpp/h is now called GameEngine.cpp/h and located in root
directory of client dir
2025-02-21 16:53:13 +00:00

66 lines
1.5 KiB
C++

/*
* 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 "../GameEngine.h"
#include "../gui/EventDispatcher.h"
#include "../render/IScreenHandler.h"
#include "../renderSDL/SDL_Extensions.h"
#include "../../lib/Rect.h"
#include <SDL_events.h>
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();
}
void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text)
{
ENGINE->events().dispatchTextInput(text.text);
}
void InputSourceText::handleEventTextEditing(const SDL_TextEditingEvent & text)
{
ENGINE->events().dispatchTextEditing(text.text);
}
void InputSourceText::startTextInput(const Rect & whereInput)
{
ENGINE->dispatchMainThread([whereInput]()
{
Rect rectInScreenCoordinates = ENGINE->screenHandler().convertLogicalPointsToWindow(whereInput);
SDL_Rect textInputRect = CSDL_Ext::toSDL(rectInScreenCoordinates);
SDL_SetTextInputRect(&textInputRect);
if (SDL_IsTextInputActive() == SDL_FALSE)
{
SDL_StartTextInput();
}
});
}
void InputSourceText::stopTextInput()
{
ENGINE->dispatchMainThread([]()
{
if (SDL_IsTextInputActive() == SDL_TRUE)
{
SDL_StopTextInput();
}
});
}