openMSX
IntegerSetting.cc
Go to the documentation of this file.
1 #include "IntegerSetting.hh"
2 
3 namespace openmsx {
4 
6  std::string_view name_, std::string_view description_,
7  int initialValue, int minValue_, int maxValue_)
8  : Setting(commandController_, name_, description_,
9  TclObject(initialValue), SAVE)
10  , minValue(minValue_)
11  , maxValue(maxValue_)
12 {
13  auto& interp = getInterpreter();
14  setChecker([this, &interp](TclObject& newValue) {
15  int val = newValue.getInt(interp); // may throw
16  newValue = std::min(std::max(val, minValue), maxValue);
17  });
18  init();
19 }
20 
21 std::string_view IntegerSetting::getTypeString() const
22 {
23  return "integer";
24 }
25 
27 {
28  result.addListElement(makeTclList(minValue, maxValue));
29 }
30 
32 {
33  setValue(TclObject(i));
34 }
35 
36 } // namespace openmsx
void setChecker(std::function< void(TclObject &)> checkFunc_)
Set value-check-callback.
Definition: Setting.hh:152
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:274
IntegerSetting(CommandController &commandController, std::string_view name, std::string_view description, int initialValue, int minValue, int maxValue)
void additionalInfo(TclObject &result) const override
Helper method for info().
vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:292
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
void setValue(const TclObject &newValue) final override
Change the value of this setting to the given value.
Definition: Setting.cc:89
int getInt(Interpreter &interp) const
Definition: TclObject.cc:72
void addListElement(T t)
Definition: TclObject.hh:121
Interpreter & getInterpreter() const
Definition: Setting.cc:162
std::string_view getTypeString() const override
Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an ...
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:280