summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/inttextfield.cpp26
-rw-r--r--src/gui/inttextfield.h5
2 files changed, 28 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);
diff --git a/src/gui/inttextfield.h b/src/gui/inttextfield.h
index add78084..ec768bea 100644
--- a/src/gui/inttextfield.h
+++ b/src/gui/inttextfield.h
@@ -56,6 +56,11 @@ class IntTextField : public TextField
void setValue(int value);
/**
+ * Set the default value of the text box to the specified value.
+ */
+ void setDefaultValue(int value);
+
+ /**
* Responds to key presses.
*/
void keyPressed(gcn::KeyEvent &event);