MyGUI  3.0.1
MyGUI_ControllerFadeAlpha.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
25 #include "MyGUI_Gui.h"
26 #include "MyGUI_InputManager.h"
27 #include "MyGUI_WidgetManager.h"
28 #include "MyGUI_Widget.h"
29 
30 namespace MyGUI
31 {
32 
34  mAlpha(1),
35  mCoef(1),
36  mEnabled(true)
37  {
38  }
39 
40  void ControllerFadeAlpha::prepareItem(Widget* _widget)
41  {
42  // подготовка виджета, блокируем если только нужно
43  if (!mEnabled) _widget->setEnabledSilent(mEnabled);
44 
45  if ((ALPHA_MIN != mAlpha) && (!_widget->isVisible()))
46  {
47  _widget->setAlpha(ALPHA_MIN);
48  _widget->setVisible(true);
49  }
50 
51  // отписываем его от ввода
52  if (!mEnabled) InputManager::getInstance().unlinkWidget(_widget);
53 
54  // вызываем пользовательский делегат для подготовки
55  eventPreAction(_widget);
56  }
57 
58  bool ControllerFadeAlpha::addTime(Widget* _widget, float _time)
59  {
60  float alpha = _widget->getAlpha();
61 
62  // проверяем нужно ли к чему еще стремиться
63  if (mAlpha > alpha)
64  {
65  alpha += _time * mCoef;
66  if (mAlpha > alpha)
67  {
68  _widget->setAlpha(alpha);
69  eventUpdateAction(_widget);
70  return true;
71  }
72  else
73  {
74  _widget->setAlpha(mAlpha);
75  }
76  }
77  else if (mAlpha < alpha)
78  {
79  alpha -= _time * mCoef;
80  if (mAlpha < alpha)
81  {
82  _widget->setAlpha(alpha);
83  eventUpdateAction(_widget);
84  return true;
85  }
86  else
87  {
88  _widget->setAlpha(mAlpha);
89  }
90  }
91 
92  // вызываем пользовательский делегат пост обработки
93  eventPostAction(_widget);
94 
95  return false;
96  }
97 
98  void ControllerFadeAlpha::setProperty(const std::string& _key, const std::string& _value)
99  {
100  if (_key == "Alpha") setAlpha(utility::parseValue<float>(_value));
101  else if (_key == "Coef") setCoef(utility::parseValue<float>(_value));
102  else if (_key == "Enabled") setEnabled(utility::parseValue<bool>(_value));
103  }
104 
105 } // namespace MyGUI