| 1 |
#include "KeyCodeSetting.hh" |
| 2 |
|
| 3 |
#include "CommandException.hh" |
| 4 |
|
| 5 |
namespace openmsx { |
| 6 |
|
| 7 |
KeyCodeSetting::KeyCodeSetting(CommandController& commandController_, |
| 8 |
std::string_view name_, static_string_view description_, |
| 9 |
SDLKey initialValue) |
| 10 |
: Setting(commandController_, name_, description_, |
| 11 |
TclObject(initialValue.toString()), Save::YES) |
| 12 |
{ |
| 13 |
setChecker([](const TclObject& newValue) { |
| 14 |
const auto& str = newValue.getString(); |
| 15 |
if (!SDLKey::fromString(str)) { |
| 16 |
throw CommandException("Not a valid key: ", str); |
| 17 |
} |
| 18 |
}); |
| 19 |
init(); |
| 20 |
} |
| 21 |
|
| 22 |
std::string_view KeyCodeSetting::getTypeString() const |
| 23 |
{ |
| 24 |
return "key"; |
| 25 |
} |
| 26 |
|
| 27 |
SDLKey KeyCodeSetting::getKey() const noexcept |
| 28 |
{ |
| 29 |
auto key = SDLKey::fromString(getValue().getString()); |
| 30 |
assert(key); |
| 31 |
return *key; |
| 32 |
} |
| 33 |
|
| 34 |
} |