openMSX
KeyCodeSetting.cc
Go to the documentation of this file.
1#include "KeyCodeSetting.hh"
2#include "CommandException.hh"
3
4namespace openmsx {
5
7 std::string_view name_, static_string_view description_,
8 SDLKey initialValue)
9 : Setting(commandController_, name_, description_,
10 TclObject(initialValue.toString()), SAVE)
11{
12 setChecker([](TclObject& newValue) {
13 const auto& str = newValue.getString();
14 if (!SDLKey::fromString(str)) {
15 throw CommandException("Not a valid key: ", str);
16 }
17 });
18 init();
19}
20
21std::string_view KeyCodeSetting::getTypeString() const
22{
23 return "key";
24}
25
27{
28 auto key = SDLKey::fromString(getValue().getString());
29 assert(key);
30 return *key;
31}
32
33} // namespace openmsx
SDLKey getKey() const noexcept
KeyCodeSetting(CommandController &commandController, std::string_view name, static_string_view description, SDLKey initialValue)
std::string_view getTypeString() const override
Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an ...
void setChecker(std::function< void(TclObject &)> checkFunc_)
Set value-check-callback.
Definition Setting.hh:145
const TclObject & getValue() const final
Gets the current value of this setting as a TclObject.
Definition Setting.hh:133
zstring_view getString() const
Definition TclObject.cc:141
static_string_view
This file implemented 3 utility functions:
Definition Autofire.cc:11
std::string toString(const BooleanInput &input)
static std::optional< SDLKey > fromString(std::string_view name)
Definition SDLKey.cc:119