Fixed reorder warning and indentation.
git-svn-id: svn://svn.code.sf.net/p/irrlicht/code/trunk@748 dfc29bdd-3216-0410-991c-e03cc46cb475master
parent
4996342b0f
commit
c2670ddc08
|
@ -20,9 +20,10 @@ namespace gui
|
|||
//! constructor
|
||||
CGUISpinBox::CGUISpinBox(const wchar_t* text, IGUIEnvironment* environment,
|
||||
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle)
|
||||
: IGUISpinBox(environment, parent, id, rectangle),
|
||||
ButtonSpinUp(0), ButtonSpinDown(0),
|
||||
StepSize(1.f), RangeMin(-FLT_MAX), RangeMax(FLT_MAX), FormatString(L"%f"), DecimalPlaces(-1)
|
||||
: 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)
|
||||
{
|
||||
s32 ButtonWidth = 16;
|
||||
IGUISpriteBank *sb = 0;
|
||||
|
@ -32,17 +33,17 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, IGUIEnvironment* environment,
|
|||
sb = environment->getSkin()->getSpriteBank();
|
||||
}
|
||||
|
||||
ButtonSpinDown = Environment->addButton(
|
||||
core::rect<s32>(rectangle.getWidth() - ButtonWidth, rectangle.getHeight()/2 +1,
|
||||
ButtonSpinDown = Environment->addButton(
|
||||
core::rect<s32>(rectangle.getWidth() - ButtonWidth, rectangle.getHeight()/2 +1,
|
||||
rectangle.getWidth(), rectangle.getHeight()), this);
|
||||
ButtonSpinDown->grab();
|
||||
ButtonSpinDown->grab();
|
||||
ButtonSpinDown->setSubElement(true);
|
||||
ButtonSpinDown->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_CENTER, EGUIA_LOWERRIGHT);
|
||||
|
||||
ButtonSpinUp = Environment->addButton(
|
||||
core::rect<s32>(rectangle.getWidth() - ButtonWidth, 0,
|
||||
ButtonSpinUp = Environment->addButton(
|
||||
core::rect<s32>(rectangle.getWidth() - ButtonWidth, 0,
|
||||
rectangle.getWidth(), rectangle.getHeight()/2), this);
|
||||
ButtonSpinUp->grab();
|
||||
ButtonSpinUp->grab();
|
||||
ButtonSpinUp->setSubElement(true);
|
||||
ButtonSpinUp->setAlignment(EGUIA_LOWERRIGHT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_CENTER);
|
||||
if (sb)
|
||||
|
@ -61,9 +62,9 @@ CGUISpinBox::CGUISpinBox(const wchar_t* text, IGUIEnvironment* environment,
|
|||
ButtonSpinUp->setText(L"+");
|
||||
}
|
||||
|
||||
core::rect<s32> rectEdit(0, 0, rectangle.getWidth() - ButtonWidth - 1, rectangle.getHeight());
|
||||
EditBox = Environment->addEditBox(text, rectEdit, true, this, -1);
|
||||
EditBox->grab();
|
||||
core::rect<s32> rectEdit(0, 0, rectangle.getWidth() - ButtonWidth - 1, rectangle.getHeight());
|
||||
EditBox = Environment->addEditBox(text, rectEdit, true, this, -1);
|
||||
EditBox->grab();
|
||||
EditBox->setSubElement(true);
|
||||
EditBox->setAlignment(EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT, EGUIA_UPPERLEFT, EGUIA_LOWERRIGHT);
|
||||
|
||||
|
@ -75,54 +76,50 @@ CGUISpinBox::~CGUISpinBox()
|
|||
{
|
||||
if (ButtonSpinUp)
|
||||
ButtonSpinUp->drop();
|
||||
if (ButtonSpinDown)
|
||||
ButtonSpinDown->drop();
|
||||
if (EditBox)
|
||||
EditBox->drop();
|
||||
if (ButtonSpinDown)
|
||||
ButtonSpinDown->drop();
|
||||
if (EditBox)
|
||||
EditBox->drop();
|
||||
}
|
||||
|
||||
IGUIEditBox* CGUISpinBox::getEditBox()
|
||||
{
|
||||
return EditBox;
|
||||
return EditBox;
|
||||
}
|
||||
|
||||
void CGUISpinBox::setValue(f32 val)
|
||||
{
|
||||
wchar_t str[100];
|
||||
|
||||
#ifdef _IRR_WINDOWS_
|
||||
_snwprintf(str, 99, FormatString.c_str(), val);
|
||||
#else
|
||||
swprintf(str, 99, FormatString.c_str(), val);
|
||||
#endif
|
||||
EditBox->setText(str);
|
||||
verifyValueRange();
|
||||
wchar_t str[100];
|
||||
|
||||
swprintf(str, 99, FormatString.c_str(), val);
|
||||
EditBox->setText(str);
|
||||
verifyValueRange();
|
||||
}
|
||||
|
||||
f32 CGUISpinBox::getValue()
|
||||
{
|
||||
const wchar_t* val = EditBox->getText();
|
||||
if ( !val )
|
||||
return 0.f;
|
||||
const wchar_t* val = EditBox->getText();
|
||||
if ( !val )
|
||||
return 0.f;
|
||||
core::stringc tmp(val);
|
||||
return core::fast_atof(tmp.c_str());
|
||||
return core::fast_atof(tmp.c_str());
|
||||
}
|
||||
|
||||
void CGUISpinBox::setRange(f32 min, f32 max)
|
||||
{
|
||||
RangeMin = min;
|
||||
RangeMax = max;
|
||||
verifyValueRange();
|
||||
RangeMin = min;
|
||||
RangeMax = max;
|
||||
verifyValueRange();
|
||||
}
|
||||
|
||||
f32 CGUISpinBox::getMin()
|
||||
{
|
||||
return RangeMin;
|
||||
return RangeMin;
|
||||
}
|
||||
|
||||
f32 CGUISpinBox::getMax()
|
||||
{
|
||||
return RangeMax;
|
||||
return RangeMax;
|
||||
}
|
||||
|
||||
f32 CGUISpinBox::getStepSize()
|
||||
|
@ -132,10 +129,10 @@ f32 CGUISpinBox::getStepSize()
|
|||
|
||||
void CGUISpinBox::setStepSize(f32 step)
|
||||
{
|
||||
StepSize = step;
|
||||
StepSize = step;
|
||||
}
|
||||
|
||||
//! Sets the number of decimal places to display.
|
||||
//! Sets the number of decimal places to display.
|
||||
void CGUISpinBox::setDecimalPlaces(s32 places)
|
||||
{
|
||||
DecimalPlaces = places;
|
||||
|
@ -143,8 +140,8 @@ void CGUISpinBox::setDecimalPlaces(s32 places)
|
|||
FormatString = "%f";
|
||||
else
|
||||
{
|
||||
FormatString = "%.";
|
||||
FormatString += places;
|
||||
FormatString = "%.";
|
||||
FormatString += places;
|
||||
FormatString += "f";
|
||||
}
|
||||
setValue(getValue());
|
||||
|
@ -152,71 +149,71 @@ void CGUISpinBox::setDecimalPlaces(s32 places)
|
|||
|
||||
bool CGUISpinBox::OnEvent(SEvent event)
|
||||
{
|
||||
bool changeEvent = false;
|
||||
switch(event.EventType)
|
||||
bool changeEvent = false;
|
||||
switch(event.EventType)
|
||||
{
|
||||
case EET_GUI_EVENT:
|
||||
if (event.GUIEvent.EventType == EGET_BUTTON_CLICKED)
|
||||
{
|
||||
if (event.GUIEvent.Caller == ButtonSpinUp)
|
||||
{
|
||||
f32 val = getValue();
|
||||
val += StepSize;
|
||||
setValue(val);
|
||||
changeEvent = true;
|
||||
}
|
||||
else if ( event.GUIEvent.Caller == ButtonSpinDown)
|
||||
{
|
||||
f32 val = getValue();
|
||||
val -= StepSize;
|
||||
setValue(val);
|
||||
changeEvent = true;
|
||||
}
|
||||
if (event.GUIEvent.Caller == ButtonSpinUp)
|
||||
{
|
||||
f32 val = getValue();
|
||||
val += StepSize;
|
||||
setValue(val);
|
||||
changeEvent = true;
|
||||
}
|
||||
else if ( event.GUIEvent.Caller == ButtonSpinDown)
|
||||
{
|
||||
f32 val = getValue();
|
||||
val -= StepSize;
|
||||
setValue(val);
|
||||
changeEvent = true;
|
||||
}
|
||||
}
|
||||
if ( event.GUIEvent.EventType == EGET_EDITBOX_ENTER )
|
||||
{
|
||||
if (event.GUIEvent.Caller == EditBox)
|
||||
{
|
||||
verifyValueRange();
|
||||
changeEvent = true;
|
||||
}
|
||||
if (event.GUIEvent.Caller == EditBox)
|
||||
{
|
||||
verifyValueRange();
|
||||
changeEvent = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if ( changeEvent )
|
||||
{
|
||||
SEvent e;
|
||||
e.EventType = EET_GUI_EVENT;
|
||||
e.GUIEvent.Caller = this;
|
||||
//fprintf(stderr, "EGET_SPINBOX_CHANGED caller:%p id: %d\n", e.GUIEvent.Caller, e.GUIEvent.Caller->getID() );
|
||||
e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
|
||||
if ( Parent )
|
||||
Parent->OnEvent(e);
|
||||
SEvent e;
|
||||
e.EventType = EET_GUI_EVENT;
|
||||
e.GUIEvent.Caller = this;
|
||||
//fprintf(stderr, "EGET_SPINBOX_CHANGED caller:%p id: %d\n", e.GUIEvent.Caller, e.GUIEvent.Caller->getID() );
|
||||
e.GUIEvent.EventType = EGET_SPINBOX_CHANGED;
|
||||
if ( Parent )
|
||||
Parent->OnEvent(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
return false;
|
||||
}
|
||||
|
||||
void CGUISpinBox::verifyValueRange()
|
||||
{
|
||||
f32 val = getValue();
|
||||
if ( val < RangeMin )
|
||||
val = RangeMin;
|
||||
else if ( val > RangeMax )
|
||||
val = RangeMax;
|
||||
else
|
||||
return;
|
||||
f32 val = getValue();
|
||||
if ( val < RangeMin )
|
||||
val = RangeMin;
|
||||
else if ( val > RangeMax )
|
||||
val = RangeMax;
|
||||
else
|
||||
return;
|
||||
|
||||
setValue(val);
|
||||
setValue(val);
|
||||
}
|
||||
|
||||
//! Sets the new caption of the element
|
||||
void CGUISpinBox::setText(const wchar_t* text)
|
||||
{
|
||||
EditBox->setText(text);
|
||||
EditBox->setText(text);
|
||||
setValue(getValue());
|
||||
verifyValueRange();
|
||||
}
|
||||
|
@ -224,7 +221,7 @@ void CGUISpinBox::setText(const wchar_t* text)
|
|||
//! Returns caption of this element.
|
||||
const wchar_t* CGUISpinBox::getText()
|
||||
{
|
||||
return EditBox->getText();
|
||||
return EditBox->getText();
|
||||
}
|
||||
|
||||
//! Writes attributes of the element.
|
||||
|
|
|
@ -1,93 +1,94 @@
|
|||
// Copyright (C) 2006 Michael Zeilfelder
|
||||
// This file uses the licence of the Irrlicht Engine.
|
||||
|
||||
#ifndef __C_GUI_SPIN_BOX_H_INCLUDED__
|
||||
#define __C_GUI_SPIN_BOX_H_INCLUDED__
|
||||
|
||||
#include "IGUISpinBox.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace gui
|
||||
{
|
||||
class IGUIEditBox;
|
||||
class IGUIButton;
|
||||
|
||||
class CGUISpinBox : public IGUISpinBox
|
||||
{
|
||||
public:
|
||||
|
||||
//! constructor
|
||||
CGUISpinBox(const wchar_t* text, IGUIEnvironment* environment,
|
||||
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
|
||||
|
||||
//! destructor
|
||||
~CGUISpinBox();
|
||||
|
||||
//! Access the edit box used in the spin control
|
||||
/** \param enable: If set to true, the override color, which can be set
|
||||
with IGUIEditBox::setOverrideColor is used, otherwise the
|
||||
EGDC_BUTTON_TEXT color of the skin. */
|
||||
virtual IGUIEditBox* getEditBox();
|
||||
|
||||
//! set the current value of the spinbox
|
||||
/** \param val: value to be set in the spinbox */
|
||||
virtual void setValue(f32 val);
|
||||
|
||||
//! Get the current value of the spinbox
|
||||
virtual f32 getValue();
|
||||
|
||||
//! set the range of values which can be used in the spinbox
|
||||
/** \param min: minimum value
|
||||
\param max: maximum value */
|
||||
virtual void setRange(f32 min, f32 max);
|
||||
|
||||
//! get the minimum value which can be used in the spinbox
|
||||
virtual f32 getMin();
|
||||
|
||||
//! get the maximum value which can be used in the spinbox
|
||||
virtual f32 getMax();
|
||||
|
||||
//! step size by which values are changed when pressing the spin buttons
|
||||
/** \param step: stepsize used for value changes when pressing spin buttons */
|
||||
virtual void setStepSize(f32 step=1.f);
|
||||
|
||||
//! returns the step size
|
||||
virtual f32 getStepSize();
|
||||
|
||||
//! called if an event happened.
|
||||
virtual bool OnEvent(SEvent event);
|
||||
|
||||
//! Sets the new caption of the element
|
||||
virtual void setText(const wchar_t* text);
|
||||
|
||||
//! Returns caption of this element.
|
||||
virtual const wchar_t* getText();
|
||||
|
||||
//! Sets the number of decimal places to display.
|
||||
/** \param places: The number of decimal places to display, use -1 to reset */
|
||||
virtual void setDecimalPlaces(s32 places);
|
||||
|
||||
// Copyright (C) 2006 Michael Zeilfelder
|
||||
// This file uses the licence of the Irrlicht Engine.
|
||||
|
||||
#ifndef __C_GUI_SPIN_BOX_H_INCLUDED__
|
||||
#define __C_GUI_SPIN_BOX_H_INCLUDED__
|
||||
|
||||
#include "IGUISpinBox.h"
|
||||
|
||||
namespace irr
|
||||
{
|
||||
namespace gui
|
||||
{
|
||||
class IGUIEditBox;
|
||||
class IGUIButton;
|
||||
|
||||
class CGUISpinBox : public IGUISpinBox
|
||||
{
|
||||
public:
|
||||
|
||||
//! constructor
|
||||
CGUISpinBox(const wchar_t* text, IGUIEnvironment* environment,
|
||||
IGUIElement* parent, s32 id, const core::rect<s32>& rectangle);
|
||||
|
||||
//! destructor
|
||||
~CGUISpinBox();
|
||||
|
||||
//! Access the edit box used in the spin control
|
||||
/** \param enable: If set to true, the override color, which can be set
|
||||
with IGUIEditBox::setOverrideColor is used, otherwise the
|
||||
EGDC_BUTTON_TEXT color of the skin. */
|
||||
virtual IGUIEditBox* getEditBox();
|
||||
|
||||
//! set the current value of the spinbox
|
||||
/** \param val: value to be set in the spinbox */
|
||||
virtual void setValue(f32 val);
|
||||
|
||||
//! Get the current value of the spinbox
|
||||
virtual f32 getValue();
|
||||
|
||||
//! set the range of values which can be used in the spinbox
|
||||
/** \param min: minimum value
|
||||
\param max: maximum value */
|
||||
virtual void setRange(f32 min, f32 max);
|
||||
|
||||
//! get the minimum value which can be used in the spinbox
|
||||
virtual f32 getMin();
|
||||
|
||||
//! get the maximum value which can be used in the spinbox
|
||||
virtual f32 getMax();
|
||||
|
||||
//! step size by which values are changed when pressing the spin buttons
|
||||
/** \param step: stepsize used for value changes when pressing spin buttons */
|
||||
virtual void setStepSize(f32 step=1.f);
|
||||
|
||||
//! returns the step size
|
||||
virtual f32 getStepSize();
|
||||
|
||||
//! called if an event happened.
|
||||
virtual bool OnEvent(SEvent event);
|
||||
|
||||
//! Sets the new caption of the element
|
||||
virtual void setText(const wchar_t* text);
|
||||
|
||||
//! Returns caption of this element.
|
||||
virtual const wchar_t* getText();
|
||||
|
||||
//! Sets the number of decimal places to display.
|
||||
/** \param places: The number of decimal places to display, use -1 to reset */
|
||||
virtual void setDecimalPlaces(s32 places);
|
||||
|
||||
//! Writes attributes of the element.
|
||||
virtual void serializeAttributes(io::IAttributes* out, io::SAttributeReadWriteOptions* options);
|
||||
|
||||
//! Reads attributes of the element
|
||||
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
|
||||
|
||||
protected:
|
||||
virtual void verifyValueRange();
|
||||
|
||||
core::stringw FormatString;
|
||||
s32 DecimalPlaces;
|
||||
|
||||
IGUIEditBox * EditBox;
|
||||
IGUIButton * ButtonSpinUp;
|
||||
IGUIButton * ButtonSpinDown;
|
||||
f32 StepSize;
|
||||
f32 RangeMin;
|
||||
f32 RangeMax;
|
||||
};
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
||||
|
||||
#endif // __C_GUI_SPIN_BOX_H_INCLUDED__
|
||||
virtual void deserializeAttributes(io::IAttributes* in, io::SAttributeReadWriteOptions* options);
|
||||
|
||||
protected:
|
||||
virtual void verifyValueRange();
|
||||
|
||||
IGUIEditBox * EditBox;
|
||||
IGUIButton * ButtonSpinUp;
|
||||
IGUIButton * ButtonSpinDown;
|
||||
f32 StepSize;
|
||||
f32 RangeMin;
|
||||
f32 RangeMax;
|
||||
|
||||
core::stringw FormatString;
|
||||
s32 DecimalPlaces;
|
||||
};
|
||||
} // end namespace gui
|
||||
} // end namespace irr
|
||||
|
||||
#endif // __C_GUI_SPIN_BOX_H_INCLUDED__
|
||||
|
||||
|
|
Loading…
Reference in New Issue