MyGUI  3.4.1
MyGUI_ControllerFadeAlpha.cpp
Go to the documentation of this file.
1 /*
2  * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3  * Distributed under the MIT License
4  * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5  */
6 
7 #include "MyGUI_Precompiled.h"
9 #include "MyGUI_Gui.h"
10 #include "MyGUI_InputManager.h"
11 #include "MyGUI_WidgetManager.h"
12 #include "MyGUI_Widget.h"
13 
14 namespace MyGUI
15 {
16 
18  mAlpha(1),
19  mCoef(1),
20  mEnabled(true)
21  {
22  }
23 
25  {
26  // подготовка виджета, блокируем если только нужно
27  if (!mEnabled) _widget->setEnabledSilent(mEnabled);
28 
29  if ((ALPHA_MIN != mAlpha) && (!_widget->getVisible()))
30  {
31  _widget->setAlpha(ALPHA_MIN);
32  _widget->setVisible(true);
33  }
34 
35  // отписываем его от ввода
36  if (!mEnabled) InputManager::getInstance().unlinkWidget(_widget);
37 
38  // вызываем пользовательский делегат для подготовки
39  eventPreAction(_widget, this);
40  }
41 
42  bool ControllerFadeAlpha::addTime(Widget* _widget, float _time)
43  {
44  float alpha = _widget->getAlpha();
45 
46  // проверяем нужно ли к чему еще стремиться
47  if (mAlpha > alpha)
48  {
49  alpha += _time * mCoef;
50  if (mAlpha > alpha)
51  {
52  _widget->setAlpha(alpha);
53  eventUpdateAction(_widget, this);
54  return true;
55  }
56  else
57  {
58  _widget->setAlpha(mAlpha);
59  }
60  }
61  else if (mAlpha < alpha)
62  {
63  alpha -= _time * mCoef;
64  if (mAlpha < alpha)
65  {
66  _widget->setAlpha(alpha);
67  eventUpdateAction(_widget, this);
68  return true;
69  }
70  else
71  {
72  _widget->setAlpha(mAlpha);
73  }
74  }
75 
76  // вызываем пользовательский делегат пост обработки
77  eventPostAction(_widget, this);
78 
79  return false;
80  }
81 
82  void ControllerFadeAlpha::setProperty(const std::string& _key, const std::string& _value)
83  {
84  if (_key == "Alpha")
85  setAlpha(utility::parseValue<float>(_value));
86  else if (_key == "Coef")
87  setCoef(utility::parseValue<float>(_value));
88  else if (_key == "Enabled")
89  setEnabled(utility::parseValue<bool>(_value));
90  }
91 
92  void ControllerFadeAlpha::setAlpha(float _value)
93  {
94  mAlpha = _value;
95  }
96 
97  void ControllerFadeAlpha::setCoef(float _value)
98  {
99  mCoef = _value;
100  }
101 
103  {
104  mEnabled = _value;
105  }
106 
107 } // namespace MyGUI
void prepareItem(Widget *_widget) override
void setProperty(const std::string &_key, const std::string &_value) override
bool addTime(Widget *_widget, float _time) override
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPreAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventUpdateAction
void unlinkWidget(Widget *_widget)
static InputManager & getInstance()
widget description should be here.
Definition: MyGUI_Widget.h:37
void setAlpha(float _value)
virtual void setVisible(bool _value)
bool getVisible() const
float getAlpha() const
void setEnabledSilent(bool _value)
const float ALPHA_MIN
Definition: MyGUI_Macros.h:20