Commit ae541ffa authored by cutealien's avatar cutealien

- IGUISpinBox now passes on the EGET_BUTTON_CLICKED, EGET_EDITBOX_CHANGED and...

- IGUISpinBox now passes on the EGET_BUTTON_CLICKED, EGET_EDITBOX_CHANGED and EGET_EDITBOX_ENTER events from it's sub-elements.
- IGUISpinBox no longer validates values after each character type but only on KEY_ENTER and when losing focus. New behavior can be set with IGUISpinBox::setValidateOn

git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@4428 dfc29bdd-3216-0410-991c-e03cc46cb475
parent c2d2390e
-------------------------- --------------------------
Changes in 1.9 (not yet released) Changes in 1.9 (not yet released)
- IGUISpinBox now passes on the EGET_BUTTON_CLICKED, EGET_EDITBOX_CHANGED and EGET_EDITBOX_ENTER events from it's sub-elements.
- IGUISpinBox no longer validates values after each character type but only on KEY_ENTER and when losing focus. New behavior can be set with IGUISpinBox::setValidateOn
- IAttributes::getAttributeAs functions now can have a customizable default-parameter to return when attributeName is not found - IAttributes::getAttributeAs functions now can have a customizable default-parameter to return when attributeName is not found
- Added ECFN_DISABLED value (it works like ECFN_NEVER worked before) and changed ECFN_NEVER behaviour - Added ECFN_DISABLED value (it works like ECFN_NEVER worked before) and changed ECFN_NEVER behaviour
(it works like its equivalent value in OpenGL/Direct3D). (it works like its equivalent value in OpenGL/Direct3D).
......
...@@ -13,6 +13,21 @@ namespace gui ...@@ -13,6 +13,21 @@ namespace gui
{ {
class IGUIEditBox; class IGUIEditBox;
//! Enumeration bitflag for when to validate the text typed into the spinbox
//! Default used by Irrlicht is: (EGUI_SBV_ENTER|EGUI_SBV_LOSE_FOCUS)
enum EGUI_SPINBOX_VALIDATION
{
//! Does not validate typed text, probably a bad idea setting this usually.
EGUI_SBV_NEVER = 0,
//! Validate on each change. Was default up to Irrlicht 1.8
EGUI_SBV_CHANGE = 1,
//! Validate when enter was pressed
EGUI_SBV_ENTER = 2,
//! Validate when the editbox loses the focus
EGUI_SBV_LOSE_FOCUS = 4,
};
//! Single line edit box + spin buttons //! Single line edit box + spin buttons
/** \par This element can create the following events of type EGUI_EVENT_TYPE: /** \par This element can create the following events of type EGUI_EVENT_TYPE:
\li EGET_SPINBOX_CHANGED \li EGET_SPINBOX_CHANGED
...@@ -59,6 +74,14 @@ namespace gui ...@@ -59,6 +74,14 @@ namespace gui
//! get the current step size //! get the current step size
virtual f32 getStepSize() const = 0; virtual f32 getStepSize() const = 0;
//! Sets when the spinbox has to validate entered text.
/** \param validateOn Can be any combination of EGUI_SPINBOX_VALIDATION bit flags */
virtual void setValidateOn(u32 validateOn) = 0;
//! Gets when the spinbox has to validate entered text.
/** \return A combination of EGUI_SPINBOX_VALIDATION bit flags */
virtual u32 getValidateOn() const = 0;
}; };
......
...@@ -23,7 +23,7 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* envir ...@@ -23,7 +23,7 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* envir
: IGUISpinBox(environment, parent, id, rectangle), : IGUISpinBox(environment, parent, id, rectangle),
EditBox(0), ButtonSpinUp(0), ButtonSpinDown(0), StepSize(1.f), EditBox(0), ButtonSpinUp(0), ButtonSpinDown(0), StepSize(1.f),
RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"), RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"),
DecimalPlaces(-1) DecimalPlaces(-1), ValidateOn(EGUI_SBV_ENTER|EGUI_SBV_LOSE_FOCUS)
{ {
#ifdef _DEBUG #ifdef _DEBUG
setDebugName("CGUISpinBox"); setDebugName("CGUISpinBox");
...@@ -156,7 +156,6 @@ f32 CGUISpinBox::getStepSize() const ...@@ -156,7 +156,6 @@ f32 CGUISpinBox::getStepSize() const
return StepSize; return StepSize;
} }
void CGUISpinBox::setStepSize(f32 step) void CGUISpinBox::setStepSize(f32 step)
{ {
StepSize = step; StepSize = step;
...@@ -179,12 +178,24 @@ void CGUISpinBox::setDecimalPlaces(s32 places) ...@@ -179,12 +178,24 @@ void CGUISpinBox::setDecimalPlaces(s32 places)
setValue(getValue()); setValue(getValue());
} }
//! Sets when the spinbox has to validate entered text.
void CGUISpinBox::setValidateOn(u32 validateOn)
{
ValidateOn = validateOn;
}
//! Gets when the spinbox has to validate entered text.
u32 CGUISpinBox::getValidateOn() const
{
return ValidateOn;
}
bool CGUISpinBox::OnEvent(const SEvent& event) bool CGUISpinBox::OnEvent(const SEvent& event)
{ {
if (IsEnabled) if (IsEnabled)
{ {
bool changeEvent = false; bool changeEvent = false;
bool eatEvent = false;
switch(event.EventType) switch(event.EventType)
{ {
case EET_MOUSE_INPUT_EVENT: case EET_MOUSE_INPUT_EVENT:
...@@ -195,6 +206,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event) ...@@ -195,6 +206,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
f32 val = getValue() + (StepSize * (event.MouseInput.Wheel < 0 ? -1.f : 1.f)); f32 val = getValue() + (StepSize * (event.MouseInput.Wheel < 0 ? -1.f : 1.f));
setValue(val); setValue(val);
changeEvent = true; changeEvent = true;
eatEvent = true;
} }
break; break;
default: default:
...@@ -203,6 +215,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event) ...@@ -203,6 +215,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
break; break;
case EET_GUI_EVENT: case EET_GUI_EVENT:
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED) if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
{ {
if (event.GUIEvent.Caller == ButtonSpinUp) if (event.GUIEvent.Caller == ButtonSpinUp)
...@@ -220,9 +233,12 @@ bool CGUISpinBox::OnEvent(const SEvent& event) ...@@ -220,9 +233,12 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
changeEvent = true; changeEvent = true;
} }
} }
if (event.GUIEvent.EventType == EGET_EDITBOX_CHANGED || event.GUIEvent.EventType == EGET_EDITBOX_ENTER) if (event.GUIEvent.Caller == EditBox)
{ {
if (event.GUIEvent.Caller == EditBox) if ( (event.GUIEvent.EventType == EGET_EDITBOX_CHANGED && ValidateOn & EGUI_SBV_CHANGE)
|| (event.GUIEvent.EventType == EGET_EDITBOX_ENTER && ValidateOn & EGUI_SBV_ENTER)
|| (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST && ValidateOn & EGUI_SBV_LOSE_FOCUS)
)
{ {
verifyValueRange(); verifyValueRange();
changeEvent = true; changeEvent = true;
...@@ -243,7 +259,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event) ...@@ -243,7 +259,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
e.GUIEvent.EventType = EGET_SPINBOX_CHANGED; e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
if ( Parent ) if ( Parent )
Parent->OnEvent(e); Parent->OnEvent(e);
return true; return eatEvent;
} }
} }
...@@ -307,6 +323,7 @@ void CGUISpinBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWr ...@@ -307,6 +323,7 @@ void CGUISpinBox::serializeAttributes(io::IAttributes* out, io::SAttributeReadWr
out->addFloat("Max", getMax()); out->addFloat("Max", getMax());
out->addFloat("Step", getStepSize()); out->addFloat("Step", getStepSize());
out->addInt("DecimalPlaces", DecimalPlaces); out->addInt("DecimalPlaces", DecimalPlaces);
out->addInt("ValidateOn", (s32)ValidateOn);
} }
...@@ -317,6 +334,7 @@ void CGUISpinBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadW ...@@ -317,6 +334,7 @@ void CGUISpinBox::deserializeAttributes(io::IAttributes* in, io::SAttributeReadW
setRange(in->getAttributeAsFloat("Min"), in->getAttributeAsFloat("Max")); setRange(in->getAttributeAsFloat("Min"), in->getAttributeAsFloat("Max"));
setStepSize(in->getAttributeAsFloat("Step")); setStepSize(in->getAttributeAsFloat("Step"));
setDecimalPlaces(in->getAttributeAsInt("DecimalPlaces")); setDecimalPlaces(in->getAttributeAsInt("DecimalPlaces"));
setValidateOn((u32)in->getAttributeAsInt("ValidateOn", (s32)ValidateOn) );
} }
......
...@@ -76,6 +76,13 @@ namespace gui ...@@ -76,6 +76,13 @@ namespace gui
/** \param places: The number of decimal places to display, use -1 to reset */ /** \param places: The number of decimal places to display, use -1 to reset */
virtual void setDecimalPlaces(s32 places); virtual void setDecimalPlaces(s32 places);
//! Sets when the spinbox has to validate entered text.
/** \param validateOn Can be any combination of EGUI_SPINBOX_VALIDATION bit flags */
virtual void setValidateOn(u32 validateOn);
//! Gets when the spinbox has to validate entered text.
virtual u32 getValidateOn() const;
//! Writes attributes of the element. //! Writes attributes of the element.
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const; virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const;
...@@ -96,6 +103,7 @@ namespace gui ...@@ -96,6 +103,7 @@ namespace gui
core::stringw FormatString; core::stringw FormatString;
s32 DecimalPlaces; s32 DecimalPlaces;
u32 ValidateOn; // combination of EGUI_SPINBOX_VALIDATION bit-flags
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment