MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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"
23 #include "MyGUI_ControllerFadeAlpha.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
32 ControllerFadeAlpha::ControllerFadeAlpha() :
33 mAlpha(1),
34 mCoef(1),
35 mEnabled(true)
36 {
37 }
38
39 ControllerFadeAlpha::~ControllerFadeAlpha()
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
121 void ControllerFadeAlpha::setEnabled(bool _value)
122 {
123 mEnabled = _value;
124 }
125
126 } // namespace MyGUI
MyGUI::ALPHA_MIN
const float ALPHA_MIN
Definition: MyGUI_Macros.h:35
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI::ControllerItem::eventUpdateAction
delegates::CMultiDelegate1< Widget * > eventUpdateAction
Definition: MyGUI_ControllerItem.h:59
MyGUI_Precompiled.h
MyGUI::Singleton< InputManager >::getInstance
static InputManager & getInstance()
Definition: MyGUI_Singleton.h:53
MyGUI_WidgetManager.h
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:101
MyGUI::ControllerFadeAlpha::ControllerFadeAlpha
ControllerFadeAlpha()
Definition: MyGUI_ControllerFadeAlpha.cpp:32
MyGUI::ControllerFadeAlpha::setAlpha
void setAlpha(float _value)
Definition: MyGUI_ControllerFadeAlpha.cpp:111
MyGUI::ControllerFadeAlpha::setCoef
void setCoef(float _value)
Definition: MyGUI_ControllerFadeAlpha.cpp:116
MyGUI::ControllerFadeAlpha::setEnabled
void setEnabled(bool _value)
Definition: MyGUI_ControllerFadeAlpha.cpp:121
MyGUI_InputManager.h
MyGUI_ControllerFadeAlpha.h
MyGUI::Widget::setEnabledSilent
void setEnabledSilent(bool _value)
Definition: MyGUI_Widget.cpp:1250
MyGUI::ControllerItem::eventPostAction
delegates::CMultiDelegate1< Widget * > eventPostAction
Definition: MyGUI_ControllerItem.h:66
MyGUI_Widget.h
MyGUI::InputManager::unlinkWidget
void unlinkWidget(Widget *_widget)
Definition: MyGUI_InputManager.cpp:682
MyGUI::ControllerItem::eventPreAction
delegates::CMultiDelegate1< Widget * > eventPreAction
Definition: MyGUI_ControllerItem.h:52
MyGUI_Gui.h
MyGUI::ControllerFadeAlpha::~ControllerFadeAlpha
virtual ~ControllerFadeAlpha()
Definition: MyGUI_ControllerFadeAlpha.cpp:39
MyGUI::Widget::getVisible
bool getVisible() const
Definition: MyGUI_Widget.cpp:1220
MyGUI::Widget::setAlpha
void setAlpha(float _value)
Definition: MyGUI_Widget.cpp:450