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