MyGUI 3.2.0

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

- File List
- Globals

MyGUI_ControllerPosition.cpp
Go to the documentation of this file.
1
6 /*
7 This file is part of MyGUI.
8
9 MyGUI is free software: you can redistribute it and/or modify
10 it under the terms of the GNU Lesser General Public License as published by
11 the Free Software Foundation, either version 3 of the License, or
12 (at your option) any later version.
13
14 MyGUI is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU Lesser General Public License for more details.
18
19 You should have received a copy of the GNU Lesser General Public License
20 along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
21 */
22 #include "MyGUI_Precompiled.h"
23 #include "MyGUI_ControllerPosition.h"
24 #include "MyGUI_Gui.h"
25 #include "MyGUI_InputManager.h"
26 #include "MyGUI_WidgetManager.h"
27 #include "MyGUI_Widget.h"
28 #include "MyGUI_ActionController.h"
29
30 namespace MyGUI
31 {
32
33 ControllerPosition::ControllerPosition() :
34 mTime(1),
35 mElapsedTime(0),
36 mCalcPosition(false),
37 mCalcSize(false)
38 {
39 }
40
41 ControllerPosition::~ControllerPosition()
42 {
43 }
44
45 void ControllerPosition::setCoord(const IntCoord& _destCoord)
46 {
47 mDestCoord = _destCoord;
48 mCalcPosition = true;
49 mCalcSize = true;
50 }
51
52 void ControllerPosition::setSize(const IntSize& _destSize)
53 {
54 mDestCoord.width = _destSize.width;
55 mDestCoord.height = _destSize.height;
56 mCalcPosition = false;
57 mCalcSize = true;
58 }
59
60 void ControllerPosition::setPosition(const IntPoint& _destPoint)
61 {
62 mDestCoord.left = _destPoint.left;
63 mDestCoord.top = _destPoint.top;
64 mCalcPosition = true;
65 mCalcSize = false;
66 }
67
68 void ControllerPosition::prepareItem(Widget* _widget)
69 {
70 MYGUI_DEBUG_ASSERT(mTime > 0, "Time must be > 0");
71
72 mStartCoord = _widget->getCoord();
73
74 // вызываем пользовательский делегат для подготовки
75 eventPreAction(_widget);
76 }
77
78 bool ControllerPosition::addTime(Widget* _widget, float _time)
79 {
80 mElapsedTime += _time;
81
82 if (mElapsedTime < mTime)
83 {
84 IntCoord coord;
85 eventFrameAction(mStartCoord, mDestCoord, coord, mElapsedTime / mTime);
86 if (mCalcPosition)
87 {
88 if (mCalcSize) _widget->setCoord(coord);
89 else _widget->setPosition(coord.point());
90 }
91 else if (mCalcSize) _widget->setSize(coord.size());
92
93 // вызываем пользовательский делегат обновления
94 eventUpdateAction(_widget);
95
96 return true;
97 }
98
99 // поставить точно в конец
100 IntCoord coord;
101 eventFrameAction(mStartCoord, mDestCoord, coord, 1.0f);
102 if (mCalcPosition)
103 {
104 if (mCalcSize) _widget->setCoord(coord);
105 else _widget->setPosition(coord.point());
106 }
107 else if (mCalcSize) _widget->setSize(coord.size());
108
109 // вызываем пользовательский делегат обновления
110 eventUpdateAction(_widget);
111
112 // вызываем пользовательский делегат пост обработки
113 eventPostAction(_widget);
114
115 return false;
116 }
117
118 void ControllerPosition::setProperty(const std::string& _key, const std::string& _value)
119 {
120 if (_key == "Time")
121 setTime(utility::parseValue<float>(_value));
122 else if (_key == "Coord")
123 setCoord(utility::parseValue<IntCoord>(_value));
124 else if (_key == "Size")
125 setSize(utility::parseValue<IntSize>(_value));
126 else if (_key == "Position")
127 setPosition(utility::parseValue<IntPoint>(_value));
128 else if (_key == "Function")
129 setFunction(_value);
130 }
131
132 void ControllerPosition::setFunction(const std::string& _value)
133 {
134 if (_value == "Inertional")
135 setAction(MyGUI::newDelegate(action::inertionalMoveFunction));
136 else if (_value == "Accelerated")
137 setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<30>));
138 else if (_value == "Slowed")
139 setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<4>));
140 else if (_value == "Jump")
141 setAction(MyGUI::newDelegate(action::jumpMoveFunction<5>));
142 }
143
144 void ControllerPosition::setTime(float _value)
145 {
146 mTime = _value;
147 }
148
149 void ControllerPosition::setAction(FrameAction::IDelegate* _value)
150 {
151 eventFrameAction = _value;
152 }
153
154 } // namespace MyGUI
MyGUI::types::TCoord< int >
MyGUI::Widget
Definition: MyGUI_Widget.h:41
MyGUI::ControllerItem::eventUpdateAction
delegates::CMultiDelegate1< Widget * > eventUpdateAction
Definition: MyGUI_ControllerItem.h:59
MyGUI_ControllerPosition.h
MyGUI::types::TPoint< int >
MyGUI_ActionController.h
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition: MyGUI_ICroppedRectangle.h:76
MyGUI_Precompiled.h
MyGUI::types::TSize< int >
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:150
MyGUI_WidgetManager.h
MyGUI::ControllerPosition::setCoord
void setCoord(const IntCoord &_value)
Definition: MyGUI_ControllerPosition.cpp:45
MyGUI::action::inertionalMoveFunction
void inertionalMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
Definition: MyGUI_ActionController.cpp:59
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:36
MyGUI::types::TCoord::width
T width
Definition: MyGUI_TCoord.h:39
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition: MyGUI_Types.h:50
MyGUI::types::TCoord::top
T top
Definition: MyGUI_TCoord.h:38
MyGUI::ControllerPosition::setTime
void setTime(float _value)
Definition: MyGUI_ControllerPosition.cpp:144
MyGUI::ControllerPosition::setSize
void setSize(const IntSize &_value)
Definition: MyGUI_ControllerPosition.cpp:52
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:35
MyGUI::types::TSize::width
T width
Definition: MyGUI_TSize.h:35
MyGUI::ControllerPosition::setFunction
void setFunction(const std::string &_value)
Definition: MyGUI_ControllerPosition.cpp:132
MyGUI_InputManager.h
MyGUI::ControllerPosition::setAction
void setAction(FrameAction::IDelegate *_value)
Definition: MyGUI_ControllerPosition.cpp:149
MyGUI::ControllerItem::eventPostAction
delegates::CMultiDelegate1< Widget * > eventPostAction
Definition: MyGUI_ControllerItem.h:66
MyGUI::ControllerPosition::~ControllerPosition
virtual ~ControllerPosition()
Definition: MyGUI_ControllerPosition.cpp:41
MyGUI::delegates::IDelegate4
Definition: MyGUI_Delegate.h:41
MyGUI_Widget.h
MyGUI::ControllerPosition::setProperty
virtual void setProperty(const std::string &_key, const std::string &_value)
Definition: MyGUI_ControllerPosition.cpp:118
MYGUI_DEBUG_ASSERT
#define MYGUI_DEBUG_ASSERT(exp, dest)
Definition: MyGUI_Diagnostic.h:83
MyGUI::ControllerItem::eventPreAction
delegates::CMultiDelegate1< Widget * > eventPreAction
Definition: MyGUI_ControllerItem.h:52
MyGUI_Gui.h
MyGUI::types::TSize::height
T height
Definition: MyGUI_TSize.h:36
MyGUI::ControllerPosition::setPosition
void setPosition(const IntPoint &_value)
Definition: MyGUI_ControllerPosition.cpp:60
MyGUI::types::TCoord::left
T left
Definition: MyGUI_TCoord.h:37
MyGUI::types::TCoord::height
T height
Definition: MyGUI_TCoord.h:40
MyGUI::ControllerPosition::ControllerPosition
ControllerPosition()
Definition: MyGUI_ControllerPosition.cpp:33