| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687 |
- /*
- * Copyright (c) 2012-2015 Daniele Bartolini and individual contributors.
- * License: https://github.com/taylor001/crown/blob/master/LICENSE
- */
- #include "float_setting.h"
- #include "string_utils.h"
- #include "math_utils.h"
- namespace crown
- {
- static FloatSetting* g_float_settings_head = NULL;
- FloatSetting::FloatSetting(const char* name, const char* synopsis, float value, float min, float max)
- : _name(name)
- , _synopsis(synopsis)
- , _value(0)
- , _min(min)
- , _max(max)
- , _next(NULL)
- {
- *this = value;
- if (g_float_settings_head != NULL)
- {
- _next = g_float_settings_head;
- }
- g_float_settings_head = this;
- }
- const char* FloatSetting::name() const
- {
- return _name;
- }
- const char* FloatSetting::synopsis() const
- {
- return _synopsis;
- }
- float FloatSetting::value() const
- {
- return _value;
- }
- float FloatSetting::min() const
- {
- return _min;
- }
- float FloatSetting::max() const
- {
- return _max;
- }
- FloatSetting::operator float()
- {
- return _value;
- }
- FloatSetting& FloatSetting::operator=(const float value)
- {
- _value = clamp(_min, _max, value);
- return *this;
- }
- FloatSetting* FloatSetting::find_setting(const char* name)
- {
- FloatSetting* head = g_float_settings_head;
- while (head != NULL)
- {
- if (strcmp(name, head->name()) == 0)
- {
- return head;
- }
- head = head->_next;
- }
- return NULL;
- }
- } // namespace crown
|