InputSourceKeyboard.cpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * InputSourceKeyboard.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 "InputSourceKeyboard.h"
  12. #include "../../lib/CConfigHandler.h"
  13. #include "../CPlayerInterface.h"
  14. #include "../gui/CGuiHandler.h"
  15. #include "../gui/EventDispatcher.h"
  16. #include "../gui/ShortcutHandler.h"
  17. #include <SDL_events.h>
  18. void InputSourceKeyboard::handleEventKeyDown(const SDL_KeyboardEvent & key)
  19. {
  20. if(key.repeat != 0)
  21. return; // ignore periodic event resends
  22. assert(key.state == SDL_PRESSED);
  23. if(key.keysym.sym >= SDLK_F1 && key.keysym.sym <= SDLK_F15 && settings["session"]["spectate"].Bool())
  24. {
  25. //TODO: we need some central place for all interface-independent hotkeys
  26. Settings s = settings.write["session"];
  27. switch(key.keysym.sym)
  28. {
  29. case SDLK_F5:
  30. if(settings["session"]["spectate-locked-pim"].Bool())
  31. CPlayerInterface::pim->unlock();
  32. else
  33. CPlayerInterface::pim->lock();
  34. s["spectate-locked-pim"].Bool() = !settings["session"]["spectate-locked-pim"].Bool();
  35. break;
  36. case SDLK_F6:
  37. s["spectate-ignore-hero"].Bool() = !settings["session"]["spectate-ignore-hero"].Bool();
  38. break;
  39. case SDLK_F7:
  40. s["spectate-skip-battle"].Bool() = !settings["session"]["spectate-skip-battle"].Bool();
  41. break;
  42. case SDLK_F8:
  43. s["spectate-skip-battle-result"].Bool() = !settings["session"]["spectate-skip-battle-result"].Bool();
  44. break;
  45. default:
  46. break;
  47. }
  48. return;
  49. }
  50. auto shortcutsVector = GH.shortcuts().translateKeycode(key.keysym.sym);
  51. GH.events().dispatchShortcutPressed(shortcutsVector);
  52. }
  53. void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
  54. {
  55. if(key.repeat != 0)
  56. return; // ignore periodic event resends
  57. assert(key.state == SDL_RELEASED);
  58. auto shortcutsVector = GH.shortcuts().translateKeycode(key.keysym.sym);
  59. GH.events().dispatchShortcutReleased(shortcutsVector);
  60. }