mirror of
				https://github.com/OpenMW/openmw.git
				synced 2025-11-04 04:56:39 +00:00 
			
		
		
		
	use Allman style brackets not K&R style, additional formatting for fallback.cpp which needed some love revert allman formatting changes
		
			
				
	
	
		
			78 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
			
		
		
	
	
			78 lines
		
	
	
	
		
			1.8 KiB
		
	
	
	
		
			C++
		
	
	
	
	
	
#include <stdexcept>
 | 
						|
 | 
						|
#include "numericeditbox.hpp"
 | 
						|
 | 
						|
namespace Gui
 | 
						|
{
 | 
						|
 | 
						|
    void NumericEditBox::initialiseOverride()
 | 
						|
    {
 | 
						|
        Base::initialiseOverride();
 | 
						|
        eventEditTextChange += MyGUI::newDelegate(this, &NumericEditBox::onEditTextChange);
 | 
						|
 | 
						|
        mValue = 0;
 | 
						|
        setCaption("0");
 | 
						|
    }
 | 
						|
 | 
						|
    void NumericEditBox::shutdownOverride()
 | 
						|
    {
 | 
						|
        Base::shutdownOverride();
 | 
						|
        eventEditTextChange -= MyGUI::newDelegate(this, &NumericEditBox::onEditTextChange);
 | 
						|
    }
 | 
						|
 | 
						|
    void NumericEditBox::onEditTextChange(MyGUI::EditBox *sender)
 | 
						|
    {
 | 
						|
        std::string newCaption = sender->getCaption();
 | 
						|
        if (newCaption.empty())
 | 
						|
        {
 | 
						|
            return;
 | 
						|
        }
 | 
						|
 | 
						|
        try
 | 
						|
        {
 | 
						|
            mValue = std::stoi(newCaption);
 | 
						|
            int capped = std::min(mMaxValue, std::max(mValue, mMinValue));
 | 
						|
            if (capped != mValue)
 | 
						|
            {
 | 
						|
                mValue = capped;
 | 
						|
                setCaption(MyGUI::utility::toString(mValue));
 | 
						|
            }
 | 
						|
        }
 | 
						|
        catch (std::invalid_argument)
 | 
						|
        {
 | 
						|
            setCaption(MyGUI::utility::toString(mValue));
 | 
						|
        }
 | 
						|
        catch (std::out_of_range)
 | 
						|
        {
 | 
						|
            setCaption(MyGUI::utility::toString(mValue));
 | 
						|
        }
 | 
						|
 | 
						|
        eventValueChanged(mValue);
 | 
						|
    }
 | 
						|
 | 
						|
    void NumericEditBox::setValue(int value)
 | 
						|
    {
 | 
						|
        if (value != mValue)
 | 
						|
        {
 | 
						|
            setCaption(MyGUI::utility::toString(value));
 | 
						|
            mValue = value;
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    void NumericEditBox::setMinValue(int minValue)
 | 
						|
    {
 | 
						|
        mMinValue = minValue;
 | 
						|
    }
 | 
						|
 | 
						|
    void NumericEditBox::setMaxValue(int maxValue)
 | 
						|
    {
 | 
						|
        mMaxValue = maxValue;
 | 
						|
    }
 | 
						|
 | 
						|
    void NumericEditBox::onKeyLostFocus(MyGUI::Widget* _new)
 | 
						|
    {
 | 
						|
        Base::onKeyLostFocus(_new);
 | 
						|
        setCaption(MyGUI::utility::toString(mValue));
 | 
						|
    }
 | 
						|
 | 
						|
}
 |