MyGUI 3.0.1
|
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(Widget* _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(Widget* _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 else if (_key == "Function") setFunction(_value); 00122 } 00123 00124 void ControllerPosition::setFunction(const std::string& _value) 00125 { 00126 if (_value == "Inertional") setAction(MyGUI::newDelegate(action::inertionalMoveFunction)); 00127 else if (_value == "Accelerated") setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<30>)); 00128 else if (_value == "Slowed") setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<4>)); 00129 else if (_value == "Jump") setAction(MyGUI::newDelegate(action::jumpMoveFunction<5>)); 00130 } 00131 00132 } // namespace MyGUI