MyGUI  3.2.1
MyGUI_ControllerFadeAlpha.cpp
Go to the documentation of this file.
00001 /*
00002  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
00003  * Distributed under the MIT License
00004  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
00005  */
00006 
00007 #include "MyGUI_Precompiled.h"
00008 #include "MyGUI_ControllerFadeAlpha.h"
00009 #include "MyGUI_Gui.h"
00010 #include "MyGUI_InputManager.h"
00011 #include "MyGUI_WidgetManager.h"
00012 #include "MyGUI_Widget.h"
00013 
00014 namespace MyGUI
00015 {
00016 
00017     ControllerFadeAlpha::ControllerFadeAlpha() :
00018         mAlpha(1),
00019         mCoef(1),
00020         mEnabled(true)
00021     {
00022     }
00023 
00024     ControllerFadeAlpha::~ControllerFadeAlpha()
00025     {
00026     }
00027 
00028     void ControllerFadeAlpha::prepareItem(Widget* _widget)
00029     {
00030         // подготовка виджета, блокируем если только нужно
00031         if (!mEnabled) _widget->setEnabledSilent(mEnabled);
00032 
00033         if ((ALPHA_MIN != mAlpha) && (!_widget->getVisible()))
00034         {
00035             _widget->setAlpha(ALPHA_MIN);
00036             _widget->setVisible(true);
00037         }
00038 
00039         // отписываем его от ввода
00040         if (!mEnabled) InputManager::getInstance().unlinkWidget(_widget);
00041 
00042         // вызываем пользовательский делегат для подготовки
00043         eventPreAction(_widget, this);
00044     }
00045 
00046     bool ControllerFadeAlpha::addTime(Widget* _widget, float _time)
00047     {
00048         float alpha = _widget->getAlpha();
00049 
00050         // проверяем нужно ли к чему еще стремиться
00051         if (mAlpha > alpha)
00052         {
00053             alpha += _time * mCoef;
00054             if (mAlpha > alpha)
00055             {
00056                 _widget->setAlpha(alpha);
00057                 eventUpdateAction(_widget, this);
00058                 return true;
00059             }
00060             else
00061             {
00062                 _widget->setAlpha(mAlpha);
00063             }
00064         }
00065         else if (mAlpha < alpha)
00066         {
00067             alpha -= _time * mCoef;
00068             if (mAlpha < alpha)
00069             {
00070                 _widget->setAlpha(alpha);
00071                 eventUpdateAction(_widget, this);
00072                 return true;
00073             }
00074             else
00075             {
00076                 _widget->setAlpha(mAlpha);
00077             }
00078         }
00079 
00080         // вызываем пользовательский делегат пост обработки
00081         eventPostAction(_widget, this);
00082 
00083         return false;
00084     }
00085 
00086     void ControllerFadeAlpha::setProperty(const std::string& _key, const std::string& _value)
00087     {
00088         if (_key == "Alpha")
00089             setAlpha(utility::parseValue<float>(_value));
00090         else if (_key == "Coef")
00091             setCoef(utility::parseValue<float>(_value));
00092         else if (_key == "Enabled")
00093             setEnabled(utility::parseValue<bool>(_value));
00094     }
00095 
00096     void ControllerFadeAlpha::setAlpha(float _value)
00097     {
00098         mAlpha = _value;
00099     }
00100 
00101     void ControllerFadeAlpha::setCoef(float _value)
00102     {
00103         mCoef = _value;
00104     }
00105 
00106     void ControllerFadeAlpha::setEnabled(bool _value)
00107     {
00108         mEnabled = _value;
00109     }
00110 
00111 } // namespace MyGUI