MyGUI: MyGUI_ControllerPosition.cpp Source File

MyGUI 3.4.2

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

- File List
- Globals

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
15namespace MyGUI
16{
17
18 ControllerPosition::ControllerPosition() :
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
42 void ControllerPosition::setPosition(const IntPoint& _destPoint)
43 {
44 mDestCoord.left = _destPoint.left;
45 mDestCoord.top = _destPoint.top;
46 mCalcPosition = true;
47 mCalcSize = false;
48 }
49
50 void ControllerPosition::prepareItem(Widget* _widget)
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")
117 setAction(MyGUI::newDelegate(action::linearMoveFunction));
118 else if (_value == "Inertional")
119 setAction(MyGUI::newDelegate(action::inertionalMoveFunction));
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
128 void ControllerPosition::setTime(float _value)
129 {
130 mTime = _value;
131 }
132
133 void ControllerPosition::setAction(FrameAction::IDelegate* _value)
134 {
135 eventFrameAction = _value;
136 }
137
138} // namespace MyGUI
MyGUI_ActionController.h
MyGUI_ControllerPosition.h
MYGUI_DEBUG_ASSERT
#define MYGUI_DEBUG_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:50
MyGUI_Gui.h
MyGUI_InputManager.h
MyGUI_Precompiled.h
MyGUI_Widget.h
MyGUI_WidgetManager.h
MyGUI::ControllerItem::eventPreAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPreAction
Definition MyGUI_ControllerItem.h:42
MyGUI::ControllerItem::eventPostAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
Definition MyGUI_ControllerItem.h:54
MyGUI::ControllerItem::eventUpdateAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventUpdateAction
Definition MyGUI_ControllerItem.h:48
MyGUI::ControllerPosition::ControllerPosition
ControllerPosition()
Definition MyGUI_ControllerPosition.cpp:18
MyGUI::ControllerPosition::setPosition
void setPosition(const IntPoint &_value)
Definition MyGUI_ControllerPosition.cpp:42
MyGUI::ControllerPosition::setAction
void setAction(FrameAction::IDelegate *_value)
Definition MyGUI_ControllerPosition.cpp:133
MyGUI::ControllerPosition::setCoord
void setCoord(const IntCoord &_value)
Definition MyGUI_ControllerPosition.cpp:27
MyGUI::ControllerPosition::setTime
void setTime(float _value)
Definition MyGUI_ControllerPosition.cpp:128
MyGUI::ControllerPosition::addTime
bool addTime(Widget *_widget, float _time) override
Definition MyGUI_ControllerPosition.cpp:60
MyGUI::ControllerPosition::setProperty
void setProperty(const std::string &_key, const std::string &_value) override
Definition MyGUI_ControllerPosition.cpp:100
MyGUI::ControllerPosition::prepareItem
void prepareItem(Widget *_widget) override
Definition MyGUI_ControllerPosition.cpp:50
MyGUI::ControllerPosition::setSize
void setSize(const IntSize &_value)
Definition MyGUI_ControllerPosition.cpp:34
MyGUI::ControllerPosition::setFunction
void setFunction(const std::string &_value)
Definition MyGUI_ControllerPosition.cpp:114
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:61
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:37
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_value) override
Definition MyGUI_Widget.cpp:686
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_value) override
Definition MyGUI_Widget.cpp:632
MyGUI::Widget::setSize
void setSize(const IntSize &_value) override
Definition MyGUI_Widget.cpp:649
MyGUI::delegates::DelegateFunction
Definition MyGUI_Delegate.h:42
MyGUI::action::acceleratedMoveFunction
void acceleratedMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
Definition MyGUI_ActionController.h:39
MyGUI::action::jumpMoveFunction
void jumpMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
Definition MyGUI_ActionController.h:47
MyGUI::action::linearMoveFunction
void linearMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _k)
Definition MyGUI_ActionController.cpp:33
MyGUI::action::inertionalMoveFunction
void inertionalMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
Definition MyGUI_ActionController.cpp:42
MyGUI::utility::parseValue
T parseValue(const std::string &_value)
Definition MyGUI_StringUtility.h:112
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:99
MyGUI::types::TCoord< int >
MyGUI::types::TCoord::height
T height
Definition MyGUI_TCoord.h:25
MyGUI::types::TCoord::width
T width
Definition MyGUI_TCoord.h:24
MyGUI::types::TCoord::top
T top
Definition MyGUI_TCoord.h:23
MyGUI::types::TCoord::point
TPoint< T > point() const
Definition MyGUI_TCoord.h:185
MyGUI::types::TCoord::size
TSize< T > size() const
Definition MyGUI_TCoord.h:190
MyGUI::types::TCoord::left
T left
Definition MyGUI_TCoord.h:22
MyGUI::types::TPoint< int >
MyGUI::types::TPoint::left
T left
Definition MyGUI_TPoint.h:20
MyGUI::types::TPoint::top
T top
Definition MyGUI_TPoint.h:21
MyGUI::types::TSize< int >
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:20
MyGUI::types::TSize::height
T height
Definition MyGUI_TSize.h:21