summaryrefslogtreecommitdiff
path: root/src/gui/inttextfield.cpp
diff options
context:
space:
mode:
authorJared Adams <jaxad0127@gmail.com>2009-02-16 18:52:24 +0000
committerJared Adams <jaxad0127@gmail.com>2009-02-16 18:52:24 +0000
commite1b66a9d88b43cee01ad15226c14fa6880fcbd04 (patch)
treec0953d44dc0f4f715715ba5e0f68b5973b68d923 /src/gui/inttextfield.cpp
parent91ee1c7b3e861d84c8aae51ad933ff6015adb5b8 (diff)
downloadmana-e1b66a9d88b43cee01ad15226c14fa6880fcbd04.tar.gz
mana-e1b66a9d88b43cee01ad15226c14fa6880fcbd04.tar.bz2
mana-e1b66a9d88b43cee01ad15226c14fa6880fcbd04.tar.xz
mana-e1b66a9d88b43cee01ad15226c14fa6880fcbd04.zip
Allow default value for IntTextField to be changed
Also check value and default value when range is changed
Diffstat (limited to 'src/gui/inttextfield.cpp')
-rw-r--r--src/gui/inttextfield.cpp26
1 files changed, 23 insertions, 3 deletions
diff --git a/src/gui/inttextfield.cpp b/src/gui/inttextfield.cpp
index fcbe938d..9f633965 100644
--- a/src/gui/inttextfield.cpp
+++ b/src/gui/inttextfield.cpp
@@ -57,6 +57,16 @@ void IntTextField::setRange(int min, int max)
{
mMin = min;
mMax = max;
+
+ if (mValue < mMin)
+ mValue = mMin;
+ else if (mValue > mMax)
+ mValue = mMax;
+
+ if (mDefault < mMin)
+ mDefault = mMin;
+ else if (mDefault > mMax)
+ mDefault = mMax;
}
int IntTextField::getValue()
@@ -66,18 +76,28 @@ int IntTextField::getValue()
void IntTextField::setValue(int i)
{
- if (i >= mMin && i <= mMax)
- mValue = i;
- else if (i < mMin)
+ if (i < mMin)
mValue = mMin;
else if (i > mMax)
mValue = mMax;
+ else
+ mValue = i;
const std::string valStr = toString(mValue);
setText(valStr);
setCaretPosition(valStr.length() + 1);
}
+void IntTextField::setDefaultValue(int value)
+{
+ if (value < mMin)
+ mDefault = mMin;
+ else if (value > mMax)
+ mDefault = mMax;
+ else
+ mDefault = value;
+}
+
void IntTextField::reset()
{
setValue(mDefault);