InputSourceText.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. /*
  2. * InputSourceText.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "InputSourceText.h"
  12. #include "../CMT.h"
  13. #include "../gui/CGuiHandler.h"
  14. #include "../gui/EventDispatcher.h"
  15. #include "../render/IScreenHandler.h"
  16. #include "../renderSDL/SDL_Extensions.h"
  17. #include "../../lib/Rect.h"
  18. #include <SDL_events.h>
  19. void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text)
  20. {
  21. GH.events().dispatchTextInput(text.text);
  22. }
  23. void InputSourceText::handleEventTextEditing(const SDL_TextEditingEvent & text)
  24. {
  25. GH.events().dispatchTextEditing(text.text);
  26. }
  27. void InputSourceText::startTextInput(const Rect & whereInput)
  28. {
  29. GH.dispatchMainThread([whereInput]()
  30. {
  31. Rect rectInScreenCoordinates = GH.screenHandler().convertLogicalPointsToWindow(whereInput);
  32. SDL_Rect textInputRect = CSDL_Ext::toSDL(rectInScreenCoordinates);
  33. SDL_SetTextInputRect(&textInputRect);
  34. if (SDL_IsTextInputActive() == SDL_FALSE)
  35. {
  36. SDL_StartTextInput();
  37. }
  38. });
  39. }
  40. void InputSourceText::stopTextInput()
  41. {
  42. GH.dispatchMainThread([]()
  43. {
  44. if (SDL_IsTextInputActive() == SDL_TRUE)
  45. {
  46. SDL_StopTextInput();
  47. }
  48. });
  49. }