MyGUI 3.5.3
MyGUI_ControllerPosition.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"
14
15namespace MyGUI
16{
17
18 ControllerPosition::ControllerPosition()
19 {
20 setFunction("Linear");
21 }
22
23 void ControllerPosition::setCoord(const IntCoord& _destCoord)
24 {
25 mDestCoord = _destCoord;
26 mCalcPosition = true;
27 mCalcSize = true;
28 }
29
30 void ControllerPosition::setSize(const IntSize& _destSize)
31 {
32 mDestCoord.width = _destSize.width;
33 mDestCoord.height = _destSize.height;
34 mCalcPosition = false;
35 mCalcSize = true;
36 }
37
38 void ControllerPosition::setPosition(const IntPoint& _destPoint)
39 {
40 mDestCoord.left = _destPoint.left;
41 mDestCoord.top = _destPoint.top;
42 mCalcPosition = true;
43 mCalcSize = false;
44 }
45
46 void ControllerPosition::prepareItem(Widget* _widget)
47 {
48 MYGUI_DEBUG_ASSERT(mTime > 0, "Time must be > 0");
49
50 mStartCoord = _widget->getCoord();
51
52 eventPreAction(_widget, this);
53 }
54
55 bool ControllerPosition::addTime(Widget* _widget, float _time)
56 {
57 mElapsedTime += _time;
58
59 float currentTime = std::min(1.0f, mElapsedTime / mTime);
60
61 IntCoord coord;
62 eventFrameAction(mStartCoord, mDestCoord, coord, currentTime);
63 if (mCalcPosition)
64 {
65 if (mCalcSize)
66 _widget->setCoord(coord);
67 else
68 _widget->setPosition(coord.point());
69 }
70 else if (mCalcSize)
71 _widget->setSize(coord.size());
72
73 eventUpdateAction(_widget, this);
74
75 if (currentTime < 1.0f)
76 return true;
77
78 eventPostAction(_widget, this);
79 return false;
80 }
81
82 void ControllerPosition::setProperty(std::string_view _key, std::string_view _value)
83 {
84 if (_key == "Time")
85 setTime(utility::parseValue<float>(_value));
86 else if (_key == "Coord")
87 setCoord(utility::parseValue<IntCoord>(_value));
88 else if (_key == "Size")
89 setSize(utility::parseValue<IntSize>(_value));
90 else if (_key == "Position")
91 setPosition(utility::parseValue<IntPoint>(_value));
92 else if (_key == "Function")
93 setFunction(_value);
94 }
95
96 void ControllerPosition::setFunction(std::string_view _value)
97 {
98 if (_value == "Linear")
100 else if (_value == "Inertional")
102 else if (_value == "Accelerated")
104 else if (_value == "Slowed")
106 else if (_value == "Jump")
108 }
109
110 void ControllerPosition::setTime(float _value)
111 {
112 mTime = _value;
113 }
114
115 void ControllerPosition::setAction(FrameAction::IDelegate* _value)
116 {
117 eventFrameAction = _value;
118 }
119
120} // namespace MyGUI
#define MYGUI_DEBUG_ASSERT(exp, dest)
void acceleratedMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
void jumpMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
void linearMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _k)
void inertionalMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
T parseValue(std::string_view value)
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:26
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:35
types::TSize< int > IntSize
Definition MyGUI_Types.h:29
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))