MyGUI: MyGUI_ControllerPosition.cpp Source File

MyGUI 3.4.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"
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 {
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 // вызываем пользовательский делегат для подготовки
53 eventPreAction(_widget, this);
54 }
55
56 bool ControllerPosition::addTime(Widget* _widget, float _time)
57 {
58 mElapsedTime += _time;
59
60 if (mElapsedTime < mTime)
61 {
62 IntCoord coord;
63 eventFrameAction(mStartCoord, mDestCoord, coord, mElapsedTime / mTime);
64 if (mCalcPosition)
65 {
66 if (mCalcSize)
67 _widget->setCoord(coord);
68 else
69 _widget->setPosition(coord.point());
70 }
71 else if (mCalcSize)
72 _widget->setSize(coord.size());
73
74 // вызываем пользовательский делегат обновления
75 eventUpdateAction(_widget, this);
76
77 return true;
78 }
79
80 // поставить точно в конец
81 IntCoord coord;
82 eventFrameAction(mStartCoord, mDestCoord, coord, 1.0f);
83 if (mCalcPosition)
84 {
85 if (mCalcSize)
86 _widget->setCoord(coord);
87 else
88 _widget->setPosition(coord.point());
89 }
90 else if (mCalcSize)
91 _widget->setSize(coord.size());
92
93 // вызываем пользовательский делегат обновления
94 eventUpdateAction(_widget, this);
95
96 // вызываем пользовательский делегат пост обработки
97 eventPostAction(_widget, this);
98
99 return false;
100 }
101
102 void ControllerPosition::setProperty(std::string_view _key, std::string_view _value)
103 {
104 if (_key == "Time")
105 setTime(utility::parseValue<float>(_value));
106 else if (_key == "Coord")
107 setCoord(utility::parseValue<IntCoord>(_value));
108 else if (_key == "Size")
109 setSize(utility::parseValue<IntSize>(_value));
110 else if (_key == "Position")
111 setPosition(utility::parseValue<IntPoint>(_value));
112 else if (_key == "Function")
113 setFunction(_value);
114 }
115
116 void ControllerPosition::setFunction(std::string_view _value)
117 {
118 if (_value == "Linear")
119 setAction(MyGUI::newDelegate(action::linearMoveFunction));
120 else if (_value == "Inertional")
121 setAction(MyGUI::newDelegate(action::inertionalMoveFunction));
122 else if (_value == "Accelerated")
123 setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<30>));
124 else if (_value == "Slowed")
125 setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<4>));
126 else if (_value == "Jump")
127 setAction(MyGUI::newDelegate(action::jumpMoveFunction<5>));
128 }
129
130 void ControllerPosition::setTime(float _value)
131 {
132 mTime = _value;
133 }
134
135 void ControllerPosition::setAction(FrameAction::IDelegate* _value)
136 {
137 eventFrameAction = _value;
138 }
139
140} // namespace MyGUI
MyGUI_ActionController.h
MyGUI_ControllerPosition.h
MYGUI_DEBUG_ASSERT
#define MYGUI_DEBUG_ASSERT(exp, dest)
Definition MyGUI_Diagnostic.h:62
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:41
MyGUI::ControllerItem::eventPostAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventPostAction
Definition MyGUI_ControllerItem.h:53
MyGUI::ControllerItem::eventUpdateAction
EventPairAddParameter< EventHandle_WidgetPtr, EventHandle_WidgetPtrControllerItemPtr > eventUpdateAction
Definition MyGUI_ControllerItem.h:47
MyGUI::ControllerPosition::ControllerPosition
ControllerPosition()
Definition MyGUI_ControllerPosition.cpp:18
MyGUI::ControllerPosition::setAction
void setAction(FrameAction::IDelegate *_value)
Definition MyGUI_ControllerPosition.cpp:135
MyGUI::ControllerPosition::setTime
void setTime(float _value)
Definition MyGUI_ControllerPosition.cpp:130
MyGUI::ControllerPosition::setFunction
void setFunction(std::string_view _value)
Definition MyGUI_ControllerPosition.cpp:116
MyGUI::ControllerPosition::addTime
bool addTime(Widget *_widget, float _time) override
Definition MyGUI_ControllerPosition.cpp:56
MyGUI::ControllerPosition::setProperty
void setProperty(std::string_view _key, std::string_view _value) override
Definition MyGUI_ControllerPosition.cpp:102
MyGUI::ControllerPosition::setPosition
void setPosition(const IntPoint &_destPoint)
Definition MyGUI_ControllerPosition.cpp:38
MyGUI::ControllerPosition::prepareItem
void prepareItem(Widget *_widget) override
Definition MyGUI_ControllerPosition.cpp:46
MyGUI::ControllerPosition::setCoord
void setCoord(const IntCoord &_destCoord)
Definition MyGUI_ControllerPosition.cpp:23
MyGUI::ControllerPosition::setSize
void setSize(const IntSize &_destSize)
Definition MyGUI_ControllerPosition.cpp:30
MyGUI::ICroppedRectangle::getCoord
const IntCoord & getCoord() const
Definition MyGUI_ICroppedRectangle.h:56
MyGUI::Widget
widget description should be here.
Definition MyGUI_Widget.h:40
MyGUI::Widget::setSize
void setSize(const IntSize &_size) override
Definition MyGUI_Widget.cpp:693
MyGUI::Widget::setPosition
void setPosition(const IntPoint &_point) override
Definition MyGUI_Widget.cpp:676
MyGUI::Widget::setCoord
void setCoord(const IntCoord &_coord) override
Definition MyGUI_Widget.cpp:730
MyGUI::delegates::Delegate< const IntCoord &, const IntCoord &, IntCoord &, float >::IDelegate
DelegateFunction< Args... > IDelegate
Definition MyGUI_Delegate.h:160
MyGUI::action::acceleratedMoveFunction
void acceleratedMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
Definition MyGUI_ActionController.h:40
MyGUI::action::jumpMoveFunction
void jumpMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
Definition MyGUI_ActionController.h:52
MyGUI::action::linearMoveFunction
void linearMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _k)
Definition MyGUI_ActionController.cpp:30
MyGUI::action::inertionalMoveFunction
void inertionalMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
Definition MyGUI_ActionController.cpp:39
MyGUI::utility::parseValue
T parseValue(std::string_view _value)
Definition MyGUI_StringUtility.h:60
MyGUI
Definition MyGUI_ActionController.h:15
MyGUI::IntPoint
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
MyGUI::IntCoord
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
MyGUI::IntSize
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
MyGUI::newDelegate
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
Definition MyGUI_Delegate.h:100
MyGUI::types::TCoord::width
T width
Definition MyGUI_TCoord.h:22
MyGUI::types::TCoord::point
TPoint< T > point() const
Definition MyGUI_TCoord.h:160
MyGUI::types::TCoord::size
TSize< T > size() const
Definition MyGUI_TCoord.h:165
MyGUI::types::TPoint::left
T left
Definition MyGUI_TPoint.h:19
MyGUI::types::TPoint::top
T top
Definition MyGUI_TPoint.h:20
MyGUI::types::TSize::width
T width
Definition MyGUI_TSize.h:19
MyGUI::types::TSize::height
T height
Definition MyGUI_TSize.h:20