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