OXYGENHUB
◆ main openmsx / src / settings / FloatSetting.cc
1.0 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
e8555c89 Andy McCall 1
#include "FloatSetting.hh"
2
3
namespace openmsx {
4
5
FloatSetting::FloatSetting(CommandController& commandController_,
6
                           std::string_view name_, static_string_view description_,
7
                           double initialValue,
8
                           double minValue_, double maxValue_,
9
                           Save save_)
10
	: Setting(commandController_, name_, description_,
11
	          TclObject(initialValue), save_)
12
	, minValue(minValue_)
13
	, maxValue(maxValue_)
14
{
15
	auto& interp = getInterpreter();
16
	setChecker([this, &interp](TclObject& newValue) {
17
		double val = newValue.getDouble(interp); // may throw
18
		newValue = std::clamp(val, minValue, maxValue);
19
	});
20
	init();
21
}
22
23
std::string_view FloatSetting::getTypeString() const
24
{
25
	return "float";
26
}
27
28
void FloatSetting::additionalInfo(TclObject& result) const
29
{
30
	result.addListElement(makeTclList(minValue, maxValue));
31
}
32
33
void FloatSetting::setDouble(double d)
34
{
35
	setValue(TclObject(d));
36
}
37
38
void FloatSetting::setFloat(float f)
39
{
40
	setDouble(double(f));
41
}
42
43
} // namespace openmsx