MyGUI  3.2.0
MyGUI_ControllerPosition.cpp
Go to the documentation of this file.
00001 
00006 /*
00007     This file is part of MyGUI.
00008 
00009     MyGUI is free software: you can redistribute it and/or modify
00010     it under the terms of the GNU Lesser General Public License as published by
00011     the Free Software Foundation, either version 3 of the License, or
00012     (at your option) any later version.
00013 
00014     MyGUI is distributed in the hope that it will be useful,
00015     but WITHOUT ANY WARRANTY; without even the implied warranty of
00016     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00017     GNU Lesser General Public License for more details.
00018 
00019     You should have received a copy of the GNU Lesser General Public License
00020     along with MyGUI.  If not, see <http://www.gnu.org/licenses/>.
00021 */
00022 #include "MyGUI_Precompiled.h"
00023 #include "MyGUI_ControllerPosition.h"
00024 #include "MyGUI_Gui.h"
00025 #include "MyGUI_InputManager.h"
00026 #include "MyGUI_WidgetManager.h"
00027 #include "MyGUI_Widget.h"
00028 #include "MyGUI_ActionController.h"
00029 
00030 namespace MyGUI
00031 {
00032 
00033     ControllerPosition::ControllerPosition() :
00034         mTime(1),
00035         mElapsedTime(0),
00036         mCalcPosition(false),
00037         mCalcSize(false)
00038     {
00039     }
00040 
00041     ControllerPosition::~ControllerPosition()
00042     {
00043     }
00044 
00045     void ControllerPosition::setCoord(const IntCoord& _destCoord)
00046     {
00047         mDestCoord = _destCoord;
00048         mCalcPosition = true;
00049         mCalcSize = true;
00050     }
00051 
00052     void ControllerPosition::setSize(const IntSize& _destSize)
00053     {
00054         mDestCoord.width = _destSize.width;
00055         mDestCoord.height = _destSize.height;
00056         mCalcPosition = false;
00057         mCalcSize = true;
00058     }
00059 
00060     void ControllerPosition::setPosition(const IntPoint& _destPoint)
00061     {
00062         mDestCoord.left = _destPoint.left;
00063         mDestCoord.top = _destPoint.top;
00064         mCalcPosition = true;
00065         mCalcSize = false;
00066     }
00067 
00068     void ControllerPosition::prepareItem(Widget* _widget)
00069     {
00070         MYGUI_DEBUG_ASSERT(mTime > 0, "Time must be > 0");
00071 
00072         mStartCoord = _widget->getCoord();
00073 
00074         // вызываем пользовательский делегат для подготовки
00075         eventPreAction(_widget);
00076     }
00077 
00078     bool ControllerPosition::addTime(Widget* _widget, float _time)
00079     {
00080         mElapsedTime += _time;
00081 
00082         if (mElapsedTime < mTime)
00083         {
00084             IntCoord coord;
00085             eventFrameAction(mStartCoord, mDestCoord, coord, mElapsedTime / mTime);
00086             if (mCalcPosition)
00087             {
00088                 if (mCalcSize) _widget->setCoord(coord);
00089                 else _widget->setPosition(coord.point());
00090             }
00091             else if (mCalcSize) _widget->setSize(coord.size());
00092 
00093             // вызываем пользовательский делегат обновления
00094             eventUpdateAction(_widget);
00095 
00096             return true;
00097         }
00098 
00099         // поставить точно в конец
00100         IntCoord coord;
00101         eventFrameAction(mStartCoord, mDestCoord, coord, 1.0f);
00102         if (mCalcPosition)
00103         {
00104             if (mCalcSize) _widget->setCoord(coord);
00105             else _widget->setPosition(coord.point());
00106         }
00107         else if (mCalcSize) _widget->setSize(coord.size());
00108 
00109         // вызываем пользовательский делегат обновления
00110         eventUpdateAction(_widget);
00111 
00112         // вызываем пользовательский делегат пост обработки
00113         eventPostAction(_widget);
00114 
00115         return false;
00116     }
00117 
00118     void ControllerPosition::setProperty(const std::string& _key, const std::string& _value)
00119     {
00120         if (_key == "Time")
00121             setTime(utility::parseValue<float>(_value));
00122         else if (_key == "Coord")
00123             setCoord(utility::parseValue<IntCoord>(_value));
00124         else if (_key == "Size")
00125             setSize(utility::parseValue<IntSize>(_value));
00126         else if (_key == "Position")
00127             setPosition(utility::parseValue<IntPoint>(_value));
00128         else if (_key == "Function")
00129             setFunction(_value);
00130     }
00131 
00132     void ControllerPosition::setFunction(const std::string& _value)
00133     {
00134         if (_value == "Inertional")
00135             setAction(MyGUI::newDelegate(action::inertionalMoveFunction));
00136         else if (_value == "Accelerated")
00137             setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<30>));
00138         else if (_value == "Slowed")
00139             setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<4>));
00140         else if (_value == "Jump")
00141             setAction(MyGUI::newDelegate(action::jumpMoveFunction<5>));
00142     }
00143 
00144     void ControllerPosition::setTime(float _value)
00145     {
00146         mTime = _value;
00147     }
00148 
00149     void ControllerPosition::setAction(FrameAction::IDelegate* _value)
00150     {
00151         eventFrameAction = _value;
00152     }
00153 
00154 } // namespace MyGUI