• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • Examples
  • File List
  • Globals

MyGUI_ControllerPosition.cpp

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

Generated on Sun Jan 30 2011 for MyGUI by  doxygen 1.7.1