SdlKeyboard.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * author: Patrick-Christopher Mattulat
  3. * e-mail: webmaster@lynarstudios.com
  4. */
  5. #include <input/SdlKeyboard.hpp>
  6. #include <utility>
  7. using ls::atlantis::glossary::KeyboardKeys;
  8. using ls::atlantis::input::KeyboardKeyMap;
  9. using ls::atlantis::input::KeyStatus;
  10. using ls::atlantis::input::SdlKeyboard;
  11. using ::std::move;
  12. SdlKeyboard::SdlKeyboard(KeyboardKeyMap _keys) : keys(::move(_keys))
  13. {}
  14. SdlKeyboard::~SdlKeyboard() = default;
  15. bool SdlKeyboard::isFreed(const KeyboardKeys &_key)
  16. {
  17. const auto entry = this->keys.find(_key);
  18. return entry != this->keys.end() && entry->second.getIsFreedValue();
  19. }
  20. bool SdlKeyboard::isPressed(const KeyboardKeys &_key)
  21. {
  22. const auto entry = this->keys.find(_key);
  23. return entry != this->keys.end() && entry->second.getIsPressedValue();
  24. }
  25. void SdlKeyboard::reset()
  26. {
  27. for (auto &[key, status] : this->keys)
  28. {
  29. status.setIsFreedValue(false);
  30. status.setIsPressedValue(false);
  31. }
  32. }
  33. void SdlKeyboard::updateKey(const KeyboardKeys &_key, const bool _isFreed, const bool _isPressed)
  34. {
  35. this->keys[_key].setIsFreedValue(_isFreed);
  36. this->keys[_key].setIsPressedValue(_isPressed);
  37. }