MyGUI 3.4.1
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
19 mTime(1),
20 mElapsedTime(0),
21 mCalcPosition(false),
22 mCalcSize(false)
23 {
24 setFunction("Linear");
25 }
26
27 void ControllerPosition::setCoord(const IntCoord& _destCoord)
28 {
29 mDestCoord = _destCoord;
30 mCalcPosition = true;
31 mCalcSize = true;
32 }
33
34 void ControllerPosition::setSize(const IntSize& _destSize)
35 {
36 mDestCoord.width = _destSize.width;
37 mDestCoord.height = _destSize.height;
38 mCalcPosition = false;
39 mCalcSize = true;
40 }
41
43 {
44 mDestCoord.left = _destPoint.left;
45 mDestCoord.top = _destPoint.top;
46 mCalcPosition = true;
47 mCalcSize = false;
48 }
49
51 {
52 MYGUI_DEBUG_ASSERT(mTime > 0, "Time must be > 0");
53
54 mStartCoord = _widget->getCoord();
55
56 // вызываем пользовательский делегат для подготовки
57 eventPreAction(_widget, this);
58 }
59
60 bool ControllerPosition::addTime(Widget* _widget, float _time)
61 {
62 mElapsedTime += _time;
63
64 if (mElapsedTime < mTime)
65 {
66 IntCoord coord;
67 eventFrameAction(mStartCoord, mDestCoord, coord, mElapsedTime / mTime);
68 if (mCalcPosition)
69 {
70 if (mCalcSize) _widget->setCoord(coord);
71 else _widget->setPosition(coord.point());
72 }
73 else if (mCalcSize) _widget->setSize(coord.size());
74
75 // вызываем пользовательский делегат обновления
76 eventUpdateAction(_widget, this);
77
78 return true;
79 }
80
81 // поставить точно в конец
82 IntCoord coord;
83 eventFrameAction(mStartCoord, mDestCoord, coord, 1.0f);
84 if (mCalcPosition)
85 {
86 if (mCalcSize) _widget->setCoord(coord);
87 else _widget->setPosition(coord.point());
88 }
89 else if (mCalcSize) _widget->setSize(coord.size());
90
91 // вызываем пользовательский делегат обновления
92 eventUpdateAction(_widget, this);
93
94 // вызываем пользовательский делегат пост обработки
95 eventPostAction(_widget, this);
96
97 return false;
98 }
99
100 void ControllerPosition::setProperty(const std::string& _key, const std::string& _value)
101 {
102 if (_key == "Time")
103 setTime(utility::parseValue<float>(_value));
104 else if (_key == "Coord")
105 setCoord(utility::parseValue<IntCoord>(_value));
106 else if (_key == "Size")
107 setSize(utility::parseValue<IntSize>(_value));
108 else if (_key == "Position")
109 setPosition(utility::parseValue<IntPoint>(_value));
110 else if (_key == "Function")
111 setFunction(_value);
112 }
113
114 void ControllerPosition::setFunction(const std::string& _value)
115 {
116 if (_value == "Linear")
118 else if (_value == "Inertional")
120 else if (_value == "Accelerated")
121 setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<30>));
122 else if (_value == "Slowed")
123 setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<4>));
124 else if (_value == "Jump")
125 setAction(MyGUI::newDelegate(action::jumpMoveFunction<5>));
126 }
127
129 {
130 mTime = _value;
131 }
132
134 {
135 eventFrameAction = _value;
136 }
137
138} // namespace MyGUI
#define MYGUI_DEBUG_ASSERT(exp, dest)
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPreAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventUpdateAction
void setPosition(const IntPoint &_value)
void setAction(FrameAction::IDelegate *_value)
void setCoord(const IntCoord &_value)
bool addTime(Widget *_widget, float _time) override
void setProperty(const std::string &_key, const std::string &_value) override
void prepareItem(Widget *_widget) override
void setSize(const IntSize &_value)
void setFunction(const std::string &_value)
const IntCoord & getCoord() const
widget description should be here.
Definition: MyGUI_Widget.h:37
void setCoord(const IntCoord &_value) override
void setPosition(const IntPoint &_value) override
void setSize(const IntSize &_value) override
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)
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
TPoint< T > point() const
Definition: MyGUI_TCoord.h:185
TSize< T > size() const
Definition: MyGUI_TCoord.h:190