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