MyGUI 3.5.3
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
14namespace MyGUI
15{
16
17 void ControllerFadeAlpha::prepareItem(Widget* _widget)
18 {
19 // prepare widget, block if needed
20 if (!mEnabled)
21 _widget->setEnabledSilent(mEnabled);
22
23 if ((ALPHA_MIN != mAlpha) && (!_widget->getVisible()))
24 {
25 _widget->setAlpha(ALPHA_MIN);
26 _widget->setVisible(true);
27 }
28
29 if (!mEnabled)
30 InputManager::getInstance().unlinkWidget(_widget);
31
32 eventPreAction(_widget, this);
33 }
34
35 bool ControllerFadeAlpha::addTime(Widget* _widget, float _time)
36 {
37 float alpha = _widget->getAlpha();
38
39 // check if we need to approach target
40 if (mAlpha > alpha)
41 {
42 alpha += _time * mCoef;
43 if (mAlpha > alpha)
44 {
45 _widget->setAlpha(alpha);
46 eventUpdateAction(_widget, this);
47 return true;
48 }
49
50 _widget->setAlpha(mAlpha);
51 }
52 else if (mAlpha < alpha)
53 {
54 alpha -= _time * mCoef;
55 if (mAlpha < alpha)
56 {
57 _widget->setAlpha(alpha);
58 eventUpdateAction(_widget, this);
59 return true;
60 }
61
62 _widget->setAlpha(mAlpha);
63 }
64
65 eventPostAction(_widget, this);
66
67 return false;
68 }
69
70 void ControllerFadeAlpha::setProperty(std::string_view _key, std::string_view _value)
71 {
72 if (_key == "Alpha")
73 setAlpha(utility::parseValue<float>(_value));
74 else if (_key == "Coef")
75 setCoef(utility::parseValue<float>(_value));
76 else if (_key == "Enabled")
77 setEnabled(utility::parseValue<bool>(_value));
78 }
79
80 void ControllerFadeAlpha::setAlpha(float _value)
81 {
82 mAlpha = _value;
83 }
84
85 void ControllerFadeAlpha::setCoef(float _value)
86 {
87 mCoef = _value;
88 }
89
90 void ControllerFadeAlpha::setEnabled(bool _value)
91 {
92 mEnabled = _value;
93 }
94
95} // namespace MyGUI
T parseValue(std::string_view value)
constexpr float ALPHA_MIN