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"
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
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
39 {
40 mDestCoord.left = _destPoint.left;
41 mDestCoord.top = _destPoint.top;
42 mCalcPosition = true;
43 mCalcSize = false;
44 }
45
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")
106 else if (_key == "Coord")
108 else if (_key == "Size")
110 else if (_key == "Position")
112 else if (_key == "Function")
113 setFunction(_value);
114 }
115
116 void ControllerPosition::setFunction(std::string_view _value)
117 {
118 if (_value == "Linear")
120 else if (_value == "Inertional")
122 else if (_value == "Accelerated")
124 else if (_value == "Slowed")
126 else if (_value == "Jump")
128 }
129
131 {
132 mTime = _value;
133 }
134
136 {
137 eventFrameAction = _value;
138 }
139
140} // 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 setAction(FrameAction::IDelegate *_value)
void setFunction(std::string_view _value)
bool addTime(Widget *_widget, float _time) override
void setProperty(std::string_view _key, std::string_view _value) override
void setPosition(const IntPoint &_destPoint)
void prepareItem(Widget *_widget) override
void setCoord(const IntCoord &_destCoord)
void setSize(const IntSize &_destSize)
const IntCoord & getCoord() const
widget description should be here.
void setSize(const IntSize &_size) override
void setPosition(const IntPoint &_point) override
void setCoord(const IntCoord &_coord) override
void acceleratedMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
void jumpMoveFunction(const IntCoord &_startRect, const IntCoord &_destRect, IntCoord &_result, float _current_time)
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)
T parseValue(std::string_view _value)
types::TPoint< int > IntPoint
Definition MyGUI_Types.h:27
types::TCoord< int > IntCoord
Definition MyGUI_Types.h:36
types::TSize< int > IntSize
Definition MyGUI_Types.h:30
delegates::DelegateFunction< Args... > * newDelegate(void(*_func)(Args... args))
TPoint< T > point() const
TSize< T > size() const