openMSX
IntegerSetting.cc
Go to the documentation of this file.
1 #include "IntegerSetting.hh"
2 
3 namespace openmsx {
4 
6  string_view name_, 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 
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:151
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:269
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:287
IntegerSetting(CommandController &commandController, string_view name, string_view description, int initialValue, int minValue, int maxValue)
string_view getTypeString() const override
Returns a string describing the setting type (integer, string, ..) Could be used in a GUI to pick an ...
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:88
This class implements a (close approximation) of the std::string_view class.
Definition: string_view.hh:16
int getInt(Interpreter &interp) const
Definition: TclObject.cc:72
void addListElement(T t)
Definition: TclObject.hh:121
Interpreter & getInterpreter() const
Definition: Setting.cc:161
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:280