MyGUI: MyGUI_ControllerPosition.cpp Source File

MyGUI 3.2.2

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