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