InputSourceText.cpp 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifdef VCMI_APPLE
  20. # include <dispatch/dispatch.h>
  21. #endif
  22. void InputSourceText::handleEventTextInput(const SDL_TextInputEvent & text)
  23. {
  24. GH.events().dispatchTextInput(text.text);
  25. }
  26. void InputSourceText::handleEventTextEditing(const SDL_TextEditingEvent & text)
  27. {
  28. GH.events().dispatchTextEditing(text.text);
  29. }
  30. void InputSourceText::startTextInput(const Rect & whereInput)
  31. {
  32. #ifdef VCMI_APPLE
  33. dispatch_async(dispatch_get_main_queue(), ^{
  34. #endif
  35. Rect rectInScreenCoordinates = GH.screenHandler().convertLogicalPointsToWindow(whereInput);
  36. SDL_Rect textInputRect = CSDL_Ext::toSDL(rectInScreenCoordinates);
  37. SDL_SetTextInputRect(&textInputRect);
  38. if (SDL_IsTextInputActive() == SDL_FALSE)
  39. {
  40. SDL_StartTextInput();
  41. }
  42. #ifdef VCMI_APPLE
  43. });
  44. #endif
  45. }
  46. void InputSourceText::stopTextInput()
  47. {
  48. #ifdef VCMI_APPLE
  49. dispatch_async(dispatch_get_main_queue(), ^{
  50. #endif
  51. if (SDL_IsTextInputActive() == SDL_TRUE)
  52. {
  53. SDL_StopTextInput();
  54. }
  55. #ifdef VCMI_APPLE
  56. });
  57. #endif
  58. }