MyGUI_ControllerPosition.cpp
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#include "MyGUI_Precompiled.h"
#include "MyGUI_ControllerPosition.h"
#include "MyGUI_Gui.h"
#include "MyGUI_InputManager.h"
#include "MyGUI_WidgetManager.h"
#include "MyGUI_Widget.h"
#include "MyGUI_ActionController.h"
namespace MyGUI
{
ControllerPosition::ControllerPosition()
{
setFunction("Linear");
}
void ControllerPosition::setCoord(const IntCoord& _destCoord)
{
mDestCoord = _destCoord;
mCalcPosition = true;
mCalcSize = true;
}
void ControllerPosition::setSize(const IntSize& _destSize)
{
mDestCoord.width = _destSize.width;
mDestCoord.height = _destSize.height;
mCalcPosition = false;
mCalcSize = true;
}
void ControllerPosition::setPosition(const IntPoint& _destPoint)
{
mDestCoord.left = _destPoint.left;
mDestCoord.top = _destPoint.top;
mCalcPosition = true;
mCalcSize = false;
}
void ControllerPosition::prepareItem(Widget* _widget)
{
MYGUI_DEBUG_ASSERT(mTime > 0, "Time must be > 0");
mStartCoord = _widget->getCoord();
// вызываем пользовательский делегат для подготовки
eventPreAction(_widget, this);
}
bool ControllerPosition::addTime(Widget* _widget, float _time)
{
mElapsedTime += _time;
if (mElapsedTime < mTime)
{
IntCoord coord;
eventFrameAction(mStartCoord, mDestCoord, coord, mElapsedTime / mTime);
if (mCalcPosition)
{
if (mCalcSize)
_widget->setCoord(coord);
else
_widget->setPosition(coord.point());
}
else if (mCalcSize)
_widget->setSize(coord.size());
// вызываем пользовательский делегат обновления
eventUpdateAction(_widget, this);
return true;
}
// поставить точно в конец
IntCoord coord;
eventFrameAction(mStartCoord, mDestCoord, coord, 1.0f);
if (mCalcPosition)
{
if (mCalcSize)
_widget->setCoord(coord);
else
_widget->setPosition(coord.point());
}
else if (mCalcSize)
_widget->setSize(coord.size());
// вызываем пользовательский делегат обновления
eventUpdateAction(_widget, this);
// вызываем пользовательский делегат пост обработки
eventPostAction(_widget, this);
return false;
}
void ControllerPosition::setProperty(std::string_view _key, std::string_view _value)
{
if (_key == "Time")
setTime(utility::parseValue<float>(_value));
else if (_key == "Coord")
setCoord(utility::parseValue<IntCoord>(_value));
else if (_key == "Size")
setSize(utility::parseValue<IntSize>(_value));
else if (_key == "Position")
setPosition(utility::parseValue<IntPoint>(_value));
else if (_key == "Function")
setFunction(_value);
}
void ControllerPosition::setFunction(std::string_view _value)
{
if (_value == "Linear")
setAction(MyGUI::newDelegate(action::linearMoveFunction));
else if (_value == "Inertional")
setAction(MyGUI::newDelegate(action::inertionalMoveFunction));
else if (_value == "Accelerated")
setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<30>));
else if (_value == "Slowed")
setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<4>));
else if (_value == "Jump")
setAction(MyGUI::newDelegate(action::jumpMoveFunction<5>));
}
void ControllerPosition::setTime(float _value)
{
mTime = _value;
}
void ControllerPosition::setAction(FrameAction::IDelegate* _value)
{
eventFrameAction = _value;
}
} // 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