MyGUI  3.0.1
MyGUI_ControllerPosition.cpp
Go to the documentation of this file.
1 
7 /*
8  This file is part of MyGUI.
9 
10  MyGUI is free software: you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  MyGUI is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18  GNU Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with MyGUI. If not, see <http://www.gnu.org/licenses/>.
22 */
23 #include "MyGUI_Precompiled.h"
25 #include "MyGUI_Gui.h"
26 #include "MyGUI_InputManager.h"
27 #include "MyGUI_WidgetManager.h"
28 #include "MyGUI_Widget.h"
29 #include "MyGUI_ActionController.h"
30 
31 namespace MyGUI
32 {
33 
35  mTime(1),
36  mElapsedTime(0),
37  mCalcPosition(false),
38  mCalcSize(false)
39  {
40  }
41 
42  void ControllerPosition::setCoord(const IntCoord& _destCoord)
43  {
44  mDestCoord = _destCoord;
45  mCalcPosition = true;
46  mCalcSize = true;
47  }
48 
49  void ControllerPosition::setSize(const IntSize& _destSize)
50  {
51  mDestCoord.width = _destSize.width;
52  mDestCoord.height = _destSize.height;
53  mCalcPosition = false;
54  mCalcSize = true;
55  }
56 
57  void ControllerPosition::setPosition(const IntPoint& _destPoint)
58  {
59  mDestCoord.left = _destPoint.left;
60  mDestCoord.top = _destPoint.top;
61  mCalcPosition = true;
62  mCalcSize = false;
63  }
64 
65  void ControllerPosition::prepareItem(Widget* _widget)
66  {
67  MYGUI_DEBUG_ASSERT(mTime > 0, "Time must be > 0");
68 
69  mStartCoord = _widget->getCoord();
70 
71  // вызываем пользовательский делегат для подготовки
72  eventPreAction(_widget);
73  }
74 
75  bool ControllerPosition::addTime(Widget* _widget, float _time)
76  {
77  mElapsedTime += _time;
78 
79  if (mElapsedTime < mTime)
80  {
81  IntCoord coord;
82  eventFrameAction(mStartCoord, mDestCoord, coord, mElapsedTime/mTime);
83  if (mCalcPosition)
84  {
85  if (mCalcSize) _widget->setCoord(coord);
86  else _widget->setPosition(coord.point());
87  }
88  else if (mCalcSize) _widget->setSize(coord.size());
89 
90  // вызываем пользовательский делегат обновления
91  eventUpdateAction(_widget);
92 
93  return true;
94  }
95 
96  // поставить точно в конец
97  IntCoord coord;
98  eventFrameAction(mStartCoord, mDestCoord, coord, 1.0f);
99  if (mCalcPosition)
100  {
101  if (mCalcSize) _widget->setCoord(coord);
102  else _widget->setPosition(coord.point());
103  }
104  else if (mCalcSize) _widget->setSize(coord.size());
105 
106  // вызываем пользовательский делегат обновления
107  eventUpdateAction(_widget);
108 
109  // вызываем пользовательский делегат пост обработки
110  eventPostAction(_widget);
111 
112  return false;
113  }
114 
115  void ControllerPosition::setProperty(const std::string& _key, const std::string& _value)
116  {
117  if (_key == "Time") setTime(utility::parseValue<float>(_value));
118  else if (_key == "Coord") setCoord(utility::parseValue<IntCoord>(_value));
119  else if (_key == "Size") setSize(utility::parseValue<IntSize>(_value));
120  else if (_key == "Position") setPosition(utility::parseValue<IntPoint>(_value));
121  else if (_key == "Function") setFunction(_value);
122  }
123 
124  void ControllerPosition::setFunction(const std::string& _value)
125  {
126  if (_value == "Inertional") setAction(MyGUI::newDelegate(action::inertionalMoveFunction));
127  else if (_value == "Accelerated") setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<30>));
128  else if (_value == "Slowed") setAction(MyGUI::newDelegate(action::acceleratedMoveFunction<4>));
129  else if (_value == "Jump") setAction(MyGUI::newDelegate(action::jumpMoveFunction<5>));
130  }
131 
132 } // namespace MyGUI