MyGUI 3.2.2

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"
8 #include "MyGUI_ControllerFadeAlpha.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
17 ControllerFadeAlpha::ControllerFadeAlpha() :
18 mAlpha(1),
19 mCoef(1),
20 mEnabled(true)
21 {
22 }
23
24 ControllerFadeAlpha::~ControllerFadeAlpha()
25 {
26 }
27
28 void ControllerFadeAlpha::prepareItem(Widget* _widget)
29 {
30 // подготовка виджета, блокируем если только нужно
31 if (!mEnabled) _widget->setEnabledSilent(mEnabled);
32
33 if ((ALPHA_MIN != mAlpha) && (!_widget->getVisible()))
34 {
35 _widget->setAlpha(ALPHA_MIN);
36 _widget->setVisible(true);
37 }
38
39 // отписываем его от ввода
40 if (!mEnabled) InputManager::getInstance().unlinkWidget(_widget);
41
42 // вызываем пользовательский делегат для подготовки
43 eventPreAction(_widget, this);
44 }
45
46 bool ControllerFadeAlpha::addTime(Widget* _widget, float _time)
47 {
48 float alpha = _widget->getAlpha();
49
50 // проверяем нужно ли к чему еще стремиться
51 if (mAlpha > alpha)
52 {
53 alpha += _time * mCoef;
54 if (mAlpha > alpha)
55 {
56 _widget->setAlpha(alpha);
57 eventUpdateAction(_widget, this);
58 return true;
59 }
60 else
61 {
62 _widget->setAlpha(mAlpha);
63 }
64 }
65 else if (mAlpha < alpha)
66 {
67 alpha -= _time * mCoef;
68 if (mAlpha < alpha)
69 {
70 _widget->setAlpha(alpha);
71 eventUpdateAction(_widget, this);
72 return true;
73 }
74 else
75 {
76 _widget->setAlpha(mAlpha);
77 }
78 }
79
80 // вызываем пользовательский делегат пост обработки
81 eventPostAction(_widget, this);
82
83 return false;
84 }
85
86 void ControllerFadeAlpha::setProperty(const std::string& _key, const std::string& _value)
87 {
88 if (_key == "Alpha")
89 setAlpha(utility::parseValue<float>(_value));
90 else if (_key == "Coef")
91 setCoef(utility::parseValue<float>(_value));
92 else if (_key == "Enabled")
93 setEnabled(utility::parseValue<bool>(_value));
94 }
95
96 void ControllerFadeAlpha::setAlpha(float _value)
97 {
98 mAlpha = _value;
99 }
100
101 void ControllerFadeAlpha::setCoef(float _value)
102 {
103 mCoef = _value;
104 }
105
106 void ControllerFadeAlpha::setEnabled(bool _value)
107 {
108 mEnabled = _value;
109 }
110
111 } // namespace MyGUI
MyGUI::ALPHA_MIN
const float ALPHA_MIN
Definition: MyGUI_Macros.h:20
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI_Precompiled.h
MyGUI::Singleton< InputManager >::getInstance
static InputManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI_WidgetManager.h
MyGUI::Widget::getAlpha
float getAlpha() const
Definition: MyGUI_Widget.cpp:1260
MyGUI::ControllerItem::eventPreAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPreAction
Definition: MyGUI_ControllerItem.h:42
MyGUI::Widget::setVisible
virtual void setVisible(bool _value)
Definition: MyGUI_Widget.cpp:965
MyGUI::ControllerFadeAlpha::setProperty
virtual void setProperty(const std::string &_key, const std::string &_value)
Definition: MyGUI_ControllerFadeAlpha.cpp:86
MyGUI::Widget::getVisible
bool getVisible() const
Definition: MyGUI_Widget.cpp:1250
MyGUI::ControllerItem::eventPostAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
Definition: MyGUI_ControllerItem.h:54
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::ControllerFadeAlpha::ControllerFadeAlpha
ControllerFadeAlpha()
Definition: MyGUI_ControllerFadeAlpha.cpp:17
MyGUI::ControllerFadeAlpha::addTime
virtual bool addTime(Widget *_widget, float _time)
Definition: MyGUI_ControllerFadeAlpha.cpp:46
MyGUI::ControllerFadeAlpha::setAlpha
void setAlpha(float _value)
Definition: MyGUI_ControllerFadeAlpha.cpp:96
MyGUI::ControllerFadeAlpha::setCoef
void setCoef(float _value)
Definition: MyGUI_ControllerFadeAlpha.cpp:101
MyGUI::ControllerFadeAlpha::setEnabled
void setEnabled(bool _value)
Definition: MyGUI_ControllerFadeAlpha.cpp:106
MyGUI_InputManager.h
MyGUI_ControllerFadeAlpha.h
MyGUI::Widget::setEnabledSilent
void setEnabledSilent(bool _value)
Definition: MyGUI_Widget.cpp:1280
MyGUI::ControllerItem::eventUpdateAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventUpdateAction
Definition: MyGUI_ControllerItem.h:48
MyGUI_Widget.h
MyGUI::InputManager::unlinkWidget
void unlinkWidget(Widget *_widget)
Definition: MyGUI_InputManager.cpp:675
MyGUI::ControllerFadeAlpha::prepareItem
virtual void prepareItem(Widget *_widget)
Definition: MyGUI_ControllerFadeAlpha.cpp:28
MyGUI_Gui.h
MyGUI::ControllerFadeAlpha::~ControllerFadeAlpha
virtual ~ControllerFadeAlpha()
Definition: MyGUI_ControllerFadeAlpha.cpp:24
MyGUI::Widget::setAlpha
void setAlpha(float _value)
Definition: MyGUI_Widget.cpp:435