openMSX
FloatSetting.cc
Go to the documentation of this file.
1 #include "FloatSetting.hh"
2 
3 namespace openmsx {
4 
6  std::string_view name_, std::string_view description_,
7  double initialValue,
8  double minValue_, double maxValue_)
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  double val = newValue.getDouble(interp); // may throw
17  newValue = std::min(std::max(val, minValue), maxValue);
18  });
19  init();
20 }
21 
22 std::string_view FloatSetting::getTypeString() const
23 {
24  return "float";
25 }
26 
28 {
29  result.addListElement(makeTclList(minValue, maxValue));
30 }
31 
33 {
34  setValue(TclObject(d));
35 }
36 
37 } // namespace openmsx
void setChecker(std::function< void(TclObject &)> checkFunc_)
Set value-check-callback.
Definition: Setting.hh:152
FloatSetting(CommandController &commandController, std::string_view name, std::string_view description, double initialValue, double minValue, double maxValue)
Definition: FloatSetting.cc:5
vecN< N, T > min(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:274
vecN< N, T > max(const vecN< N, T > &x, const vecN< N, T > &y)
Definition: gl_vec.hh:292
void additionalInfo(TclObject &result) const override
Helper method for info().
Definition: FloatSetting.cc:27
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: FloatSetting.cc:22
Thanks to enen for testing this on a real cartridge:
Definition: Autofire.cc:5
double getDouble(Interpreter &interp) const
Definition: TclObject.cc:92
void setValue(const TclObject &newValue) final override
Change the value of this setting to the given value.
Definition: Setting.cc:89
void setDouble(double d)
Definition: FloatSetting.cc:32
void addListElement(T t)
Definition: TclObject.hh:121
Interpreter & getInterpreter() const
Definition: Setting.cc:162
TclObject makeTclList(Args &&... args)
Definition: TclObject.hh:280