Commit c2670ddc authored by hybrid's avatar hybrid

Fixed reorder warning and indentation.

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