mirror of
https://github.com/minetest/irrlicht.git
synced 2024-12-24 01:30:31 +01:00
Add IGUISpinBox functions getValueFor and getOldValue
Also documenting some missing feature (decimal places ignored with direct text input) getValueFor allows to check the value a given text would have getOldValue can be used to check the previous value in a EGET_SPINBOX_CHANGED event git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@6429 dfc29bdd-3216-0410-991c-e03cc46cb475
This commit is contained in:
parent
0ef9102ac6
commit
a883d464f9
@ -1,6 +1,7 @@
|
||||
--------------------------
|
||||
Changes in 1.9 (not yet released)
|
||||
|
||||
- Add IGUISpinBox functions getValueFor and getOldValue
|
||||
- Bugfix: IGUIElement::getNextElement now passing includeInvisible and includeDisabled flags recursively instead of disabling those for children.
|
||||
This fixes problems that elements sometimes didn't get a tab order because some parent was invisible and so tab'ing for them failed completely.
|
||||
Also setTabOrder(-1) now also checks for disabled elements for the same reason (disabled parent causing children to not get a tab-order).
|
||||
|
@ -51,6 +51,12 @@ namespace gui
|
||||
//! Get the current value of the spinbox
|
||||
virtual f32 getValue() const = 0;
|
||||
|
||||
//! Get the value the spinbox would have for the given text
|
||||
/** Note: There is no rounding for decimal places going on here
|
||||
The reason is that so far spinbox doesn't restrict entering longer
|
||||
numbers (or any other text) (TODO)*/
|
||||
virtual f32 getValueFor(const wchar_t* text) const = 0;
|
||||
|
||||
//! set the range of values which can be used in the spinbox
|
||||
/** \param min: minimum value
|
||||
\param max: maximum value */
|
||||
@ -68,7 +74,8 @@ namespace gui
|
||||
virtual void setStepSize(f32 step=1.f) = 0;
|
||||
|
||||
//! Sets the number of decimal places to display.
|
||||
//! Note that this also rounds the range to the same number of decimal places.
|
||||
//! Note: This also rounds the range to the same number of decimal places.
|
||||
//! Note: This is only used for the buttons so far, text-input ignores it (TODO)
|
||||
/** \param places: The number of decimal places to display, use -1 to reset */
|
||||
virtual void setDecimalPlaces(s32 places) = 0;
|
||||
|
||||
@ -82,6 +89,12 @@ namespace gui
|
||||
//! Gets when the spinbox has to validate entered text.
|
||||
/** \return A combination of EGUI_SPINBOX_VALIDATION bit flags */
|
||||
virtual u32 getValidateOn() const = 0;
|
||||
|
||||
//! Gets previous value in EGET_SPINBOX_CHANGED events
|
||||
/** Note: That value changes as soon as a new value is set (to the new value).
|
||||
So it's only useful to check for last value in the event and has no use otherwise.
|
||||
Also it's possible to mess it up by setting text via the editbox sub-element directly. */
|
||||
virtual f32 getOldValue() const = 0;
|
||||
};
|
||||
|
||||
|
||||
|
@ -23,7 +23,8 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* envir
|
||||
: IGUISpinBox(environment, parent, id, rectangle),
|
||||
EditBox(0), ButtonSpinUp(0), ButtonSpinDown(0), StepSize(1.f),
|
||||
RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"),
|
||||
DecimalPlaces(-1), ValidateOn(EGUI_SBV_ENTER|EGUI_SBV_LOSE_FOCUS)
|
||||
DecimalPlaces(-1), ValidateOn(EGUI_SBV_ENTER|EGUI_SBV_LOSE_FOCUS),
|
||||
OldValue(0.f)
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
setDebugName("CGUISpinBox");
|
||||
@ -55,6 +56,8 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, bool border,IGUIEnvironment* envir
|
||||
EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
|
||||
|
||||
refreshSprites();
|
||||
|
||||
OldValue = getValue();
|
||||
}
|
||||
|
||||
|
||||
@ -103,24 +106,28 @@ IGUIEditBox* CGUISpinBox::getEditBox() const
|
||||
|
||||
void CGUISpinBox::setValue(f32 val)
|
||||
{
|
||||
wchar_t str[100];
|
||||
OldValue = val;
|
||||
|
||||
wchar_t str[100];
|
||||
swprintf_irr(str, 99, FormatString.c_str(), val);
|
||||
EditBox->setText(str);
|
||||
verifyValueRange();
|
||||
verifyValueRange(getValue());
|
||||
}
|
||||
|
||||
|
||||
f32 CGUISpinBox::getValue() const
|
||||
{
|
||||
const wchar_t* val = EditBox->getText();
|
||||
return getValueFor(EditBox->getText());
|
||||
}
|
||||
|
||||
f32 CGUISpinBox::getValueFor(const wchar_t* val) const
|
||||
{
|
||||
if ( !val )
|
||||
return 0.f;
|
||||
core::stringc tmp(val);
|
||||
return core::fast_atof(tmp.c_str());
|
||||
}
|
||||
|
||||
|
||||
void CGUISpinBox::setRange(f32 min, f32 max)
|
||||
{
|
||||
if (max<min)
|
||||
@ -135,7 +142,7 @@ void CGUISpinBox::setRange(f32 min, f32 max)
|
||||
swprintf_irr(str, 99, FormatString.c_str(), RangeMax);
|
||||
RangeMax = core::fast_atof(core::stringc(str).c_str());
|
||||
|
||||
verifyValueRange();
|
||||
verifyValueRange(getValue());
|
||||
}
|
||||
|
||||
|
||||
@ -194,6 +201,7 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
|
||||
{
|
||||
if (IsEnabled)
|
||||
{
|
||||
f32 oldValue = OldValue;
|
||||
bool changeEvent = false;
|
||||
bool eatEvent = false;
|
||||
switch(event.EventType)
|
||||
@ -240,7 +248,8 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
|
||||
|| (event.GUIEvent.EventType == EGET_ELEMENT_FOCUS_LOST && ValidateOn & EGUI_SBV_LOSE_FOCUS)
|
||||
)
|
||||
{
|
||||
verifyValueRange();
|
||||
OldValue = getValue(); // no call to setValue when text was changed without setText call
|
||||
verifyValueRange(OldValue);
|
||||
changeEvent = true;
|
||||
}
|
||||
}
|
||||
@ -251,14 +260,18 @@ bool CGUISpinBox::OnEvent(const SEvent& event)
|
||||
|
||||
if ( changeEvent )
|
||||
{
|
||||
SEvent e;
|
||||
e.EventType = EET_GUI_EVENT;
|
||||
e.GUIEvent.Caller = this;
|
||||
e.GUIEvent.Element = 0;
|
||||
|
||||
e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
|
||||
if ( Parent )
|
||||
{
|
||||
SEvent e;
|
||||
e.EventType = EET_GUI_EVENT;
|
||||
e.GUIEvent.Caller = this;
|
||||
e.GUIEvent.Element = 0;
|
||||
e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
|
||||
|
||||
core::swap(oldValue, OldValue);
|
||||
Parent->OnEvent(e);
|
||||
core::swap(oldValue, OldValue);
|
||||
}
|
||||
if ( eatEvent )
|
||||
return true;
|
||||
}
|
||||
@ -286,17 +299,12 @@ void CGUISpinBox::draw()
|
||||
IGUISpinBox::draw();
|
||||
}
|
||||
|
||||
void CGUISpinBox::verifyValueRange()
|
||||
void CGUISpinBox::verifyValueRange(f32 val)
|
||||
{
|
||||
f32 val = getValue();
|
||||
if ( val+core::ROUNDING_ERROR_f32 < RangeMin )
|
||||
val = RangeMin;
|
||||
setValue(RangeMin);
|
||||
else if ( val-core::ROUNDING_ERROR_f32 > RangeMax )
|
||||
val = RangeMax;
|
||||
else
|
||||
return;
|
||||
|
||||
setValue(val);
|
||||
setValue(RangeMax);
|
||||
}
|
||||
|
||||
|
||||
@ -305,7 +313,6 @@ void CGUISpinBox::setText(const wchar_t* text)
|
||||
{
|
||||
EditBox->setText(text);
|
||||
setValue(getValue());
|
||||
verifyValueRange();
|
||||
}
|
||||
|
||||
|
||||
|
@ -41,6 +41,9 @@ namespace gui
|
||||
//! Get the current value of the spinbox
|
||||
virtual f32 getValue() const IRR_OVERRIDE;
|
||||
|
||||
//! Get the value the spinbox would have for the given text
|
||||
virtual f32 getValueFor(const wchar_t* text) const IRR_OVERRIDE;
|
||||
|
||||
//! set the range of values which can be used in the spinbox
|
||||
/** \param min: minimum value
|
||||
\param max: maximum value */
|
||||
@ -83,6 +86,12 @@ namespace gui
|
||||
//! Gets when the spinbox has to validate entered text.
|
||||
virtual u32 getValidateOn() const IRR_OVERRIDE;
|
||||
|
||||
//! Gets previous value in EGET_SPINBOX_CHANGED events
|
||||
virtual f32 getOldValue() const IRR_OVERRIDE
|
||||
{
|
||||
return OldValue;
|
||||
}
|
||||
|
||||
//! Writes attributes of the element.
|
||||
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options) const IRR_OVERRIDE;
|
||||
|
||||
@ -90,7 +99,7 @@ namespace gui
|
||||
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options) IRR_OVERRIDE;
|
||||
|
||||
protected:
|
||||
virtual void verifyValueRange();
|
||||
void verifyValueRange(f32 val);
|
||||
void refreshSprites();
|
||||
|
||||
IGUIEditBox * EditBox;
|
||||
@ -104,6 +113,7 @@ namespace gui
|
||||
core::stringw FormatString;
|
||||
s32 DecimalPlaces;
|
||||
u32 ValidateOn; // combination of EGUI_SPINBOX_VALIDATION bit-flags
|
||||
f32 OldValue;
|
||||
};
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user