MyGUI  3.0.3
MyGUI_ControllerFadeAlpha.cpp
Go to the documentation of this file.
00001 
00007 /*
00008     This file is part of MyGUI.
00009 
00010     MyGUI is free software: you can redistribute it and/or modify
00011     it under the terms of the GNU Lesser General Public License as published by
00012     the Free Software Foundation, either version 3 of the License, or
00013     (at your option) any later version.
00014 
00015     MyGUI is distributed in the hope that it will be useful,
00016     but WITHOUT ANY WARRANTY; without even the implied warranty of
00017     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018     GNU Lesser General Public License for more details.
00019 
00020     You should have received a copy of the GNU Lesser General Public License
00021     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00022 */
00023 #include "MyGUI_Precompiled.h"
00024 #include "MyGUI_ControllerFadeAlpha.h"
00025 #include "MyGUI_Gui.h"
00026 #include "MyGUI_InputManager.h"
00027 #include "MyGUI_WidgetManager.h"
00028 #include "MyGUI_Widget.h"
00029 
00030 namespace MyGUI
00031 {
00032 
00033     ControllerFadeAlpha::ControllerFadeAlpha() :
00034         mAlpha(1),
00035         mCoef(1),
00036         mEnabled(true)
00037     {
00038     }
00039 
00040     void ControllerFadeAlpha::prepareItem(Widget* _widget)
00041     {
00042         // подготовка виджета, блокируем если только нужно
00043         if (!mEnabled) _widget->setEnabledSilent(mEnabled);
00044 
00045         if ((ALPHA_MIN != mAlpha) && (!_widget->isVisible()))
00046         {
00047             _widget->setAlpha(ALPHA_MIN);
00048             _widget->setVisible(true);
00049         }
00050 
00051         // отписываем его от ввода
00052         if (!mEnabled) InputManager::getInstance().unlinkWidget(_widget);
00053 
00054         // вызываем пользовательский делегат для подготовки
00055         eventPreAction(_widget);
00056     }
00057 
00058     bool ControllerFadeAlpha::addTime(Widget* _widget, float _time)
00059     {
00060         float alpha = _widget->getAlpha();
00061 
00062         // проверяем нужно ли к чему еще стремиться
00063         if (mAlpha > alpha)
00064         {
00065             alpha += _time * mCoef;
00066             if (mAlpha > alpha)
00067             {
00068                 _widget->setAlpha(alpha);
00069                 eventUpdateAction(_widget);
00070                 return true;
00071             }
00072             else
00073             {
00074                 _widget->setAlpha(mAlpha);
00075             }
00076         }
00077         else if (mAlpha < alpha)
00078         {
00079             alpha -= _time * mCoef;
00080             if (mAlpha < alpha)
00081             {
00082                 _widget->setAlpha(alpha);
00083                 eventUpdateAction(_widget);
00084                 return true;
00085             }
00086             else
00087             {
00088                 _widget->setAlpha(mAlpha);
00089             }
00090         }
00091 
00092         // вызываем пользовательский делегат пост обработки
00093         eventPostAction(_widget);
00094 
00095         return false;
00096     }
00097 
00098     void ControllerFadeAlpha::setProperty(const std::string& _key, const std::string& _value)
00099     {
00100         if (_key == "Alpha") setAlpha(utility::parseValue<float>(_value));
00101         else if (_key == "Coef") setCoef(utility::parseValue<float>(_value));
00102         else if (_key == "Enabled") setEnabled(utility::parseValue<bool>(_value));
00103     }
00104 
00105 } // namespace MyGUI