MyGUI 3.2.2

MyGUI_DDContainer.cpp
Go to the documentation of this file.
1 /*
2 * This source file is part of MyGUI. For the latest info, see http://mygui.info/
3 * Distributed under the MIT License
4 * (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
5 */
6
7 #include "MyGUI_Precompiled.h"
8 #include "MyGUI_DDContainer.h"
9 #include "MyGUI_InputManager.h"
10 #include "MyGUI_LayerManager.h"
11
12 namespace MyGUI
13 {
14
15 DDContainer::DDContainer() :
16 mDropResult(false),
17 mNeedDrop(false),
18 mStartDrop(false),
19 mOldDrop(nullptr),
20 mCurrentSender(nullptr),
21 mDropSenderIndex(ITEM_NONE),
22 mDropItem(nullptr),
23 mNeedDragDrop(false),
24 mReseiverContainer(nullptr)
25 {
26 }
27
28 void DDContainer::onMouseButtonPressed(int _left, int _top, MouseButton _id)
29 {
30 // смещение внутри виджета, куда кликнули мышкой
31 mClickInWidget = InputManager::getInstance().getLastPressedPosition(MouseButton::Left) - getAbsolutePosition();
32
33 mouseButtonPressed(_id);
34
35 Base::onMouseButtonPressed(_left, _top, _id);
36 }
37
38 void DDContainer::onMouseButtonReleased(int _left, int _top, MouseButton _id)
39 {
40 mouseButtonReleased(_id);
41
42 Base::onMouseButtonReleased(_left, _top, _id);
43 }
44
45 void DDContainer::onMouseDrag(int _left, int _top, MouseButton _id)
46 {
47 mouseDrag(_id);
48
49 Base::onMouseDrag(_left, _top, _id);
50 }
51
52 void DDContainer::mouseButtonPressed(MouseButton _id)
53 {
54 if (MouseButton::Left == _id)
55 {
56 // сбрасываем инфу для дропа
57 mDropResult = false;
58 mOldDrop = nullptr;
59 mDropInfo.reset();
60 mReseiverContainer = nullptr;
61
62 // сбрасываем, чтобы обновился дропный виджет
63 mCurrentSender = nullptr;
64 mStartDrop = false;
65
66 }
67 // если нажата другая клавиша и был дроп то сбрасываем
68 else
69 {
70 endDrop(true);
71 }
72 }
73
74 void DDContainer::mouseButtonReleased(MouseButton _id)
75 {
76 if (MouseButton::Left == _id)
77 {
78 endDrop(false);
79 }
80 }
81
82 void DDContainer::mouseDrag(MouseButton _id)
83 {
84 if (MouseButton::Left != _id)
85 return;
86
87 // нужно ли обновить данные
88 bool update = false;
89
90 // первый раз дропаем елемент
91 if (!mStartDrop && mDropSenderIndex != ITEM_NONE)
92 {
93 mStartDrop = true;
94 mNeedDrop = false;
95 update = true;
96 // запрос на нужность дропа по индексу
97 mDropInfo.set(this, mDropSenderIndex, nullptr, ITEM_NONE);
98 mReseiverContainer = nullptr;
99
100 eventStartDrag(this, mDropInfo, mNeedDrop);
101
102 if (mNeedDrop)
103 {
104 eventChangeDDState(this, DDItemState::Start);
105 }
106 else
107 {
108 // сбрасываем фокус мыши (не обязательно)
109 InputManager::getInstance().resetMouseCaptureWidget();
110 }
111 }
112
113 // дроп не нужен
114 if (!mNeedDrop)
115 {
116 return;
117 }
118
119 // делаем запрос, над кем наша мыша
120 const IntPoint& point = InputManager::getInstance().getMousePosition();
121 Widget* item = LayerManager::getInstance().getWidgetFromPoint(point.left, point.top);
122
123 updateDropItems();
124
125 // если равно, значит уже спрашивали
126 if (mOldDrop == item) return;
127 mOldDrop = item;
128
129 // сбрасываем старую подсветку
130 if (mReseiverContainer) mReseiverContainer->_setContainerItemInfo(mDropInfo.receiver_index, false, false);
131
132 mDropResult = false;
133 mReseiverContainer = nullptr;
134 Widget* receiver = nullptr;
135 size_t receiver_index = ITEM_NONE;
136 // есть виджет под нами
137 if (item)
138 {
139 // делаем запрос на индекс по произвольному виджету
140 receiver = item->_getContainer();
141 // работаем только с контейнерами
142 if (receiver && receiver->isType<DDContainer>())
143 {
144 receiver_index = receiver->_getItemIndex(item);
145
146 // подписываемся на информацию о валидности дропа
147 mReseiverContainer = static_cast<DDContainer*>(receiver);
148 mReseiverContainer->_eventInvalideContainer.clear();
149 mReseiverContainer->_eventInvalideContainer += newDelegate(this, &DDContainer::notifyInvalideDrop);
150
151 // делаем запрос на возможность дропа
152 mDropInfo.set(this, mDropSenderIndex, mReseiverContainer, receiver_index);
153
154 eventRequestDrop(this, mDropInfo, mDropResult);
155
156 // устанавливаем новую подсветку
157 mReseiverContainer->_setContainerItemInfo(mDropInfo.receiver_index, true, mDropResult);
158 }
159 else
160 {
161 mDropInfo.set(this, mDropSenderIndex, nullptr, ITEM_NONE);
162 }
163 }
164 // нет виджета под нами
165 else
166 {
167 mDropInfo.set(this, mDropSenderIndex, nullptr, ITEM_NONE);
168 }
169
170 DDItemState state;
171
172 DDWidgetState data(mDropSenderIndex);
173 data.update = update;
174
175 if (receiver == nullptr)
176 {
177 data.accept = false;
178 data.refuse = false;
179 state = DDItemState::Miss;
180 }
181 else if (mDropResult)
182 {
183 data.accept = true;
184 data.refuse = false;
185 state = DDItemState::Accept;
186 }
187 else
188 {
189 data.accept = false;
190 data.refuse = true;
191 state = DDItemState::Refuse;
192 }
193
194 updateDropItemsState(data);
195
196 eventChangeDDState(this, state);
197 }
198
199 void DDContainer::endDrop(bool _reset)
200 {
201 if (mStartDrop)
202 {
203 removeDropItems();
204
205 // сбрасываем старую подсветку
206 if (mReseiverContainer) mReseiverContainer->_setContainerItemInfo(mDropInfo.receiver_index, false, false);
207
208 if (_reset) mDropResult = false;
209 eventDropResult(this, mDropInfo, mDropResult);
210 eventChangeDDState(this, DDItemState::End);
211
212 // сбрасываем инфу для дропа
213 mStartDrop = false;
214 mDropResult = false;
215 mNeedDrop = false;
216 mOldDrop = nullptr;
217 mDropInfo.reset();
218 mReseiverContainer = nullptr;
219 mDropSenderIndex = ITEM_NONE;
220 }
221 }
222
223 void DDContainer::removeDropItems()
224 {
225 mDropItem = nullptr;
226 }
227
228 void DDContainer::updateDropItems()
229 {
230
231 if (mDropItem == nullptr)
232 {
233 requestDragWidgetInfo(this, mDropItem, mDropDimension);
234 }
235
236 const IntPoint& point = InputManager::getInstance().getMousePositionByLayer();
237
238 if (mDropItem)
239 {
240 mDropItem->setCoord(point.left - mClickInWidget.left + mDropDimension.left, point.top - mClickInWidget.top + mDropDimension.top, mDropDimension.width, mDropDimension.height);
241 mDropItem->setVisible(true);
242 }
243 }
244
245 void DDContainer::updateDropItemsState(const DDWidgetState& _state)
246 {
247 eventUpdateDropState(this, mDropItem, _state);
248 }
249
250 void DDContainer::notifyInvalideDrop(DDContainer* _sender)
251 {
252 mouseDrag(MouseButton::Left);
253 }
254
255 void DDContainer::setPropertyOverride(const std::string& _key, const std::string& _value)
256 {
258 if (_key == "NeedDragDrop")
259 setNeedDragDrop(utility::parseValue<bool>(_value));
260
261 else
262 {
263 Base::setPropertyOverride(_key, _value);
264 return;
265 }
266
267 eventChangeProperty(this, _key, _value);
268 }
269
270 void DDContainer::setNeedDragDrop(bool _value)
271 {
272 mNeedDragDrop = _value;
273 }
274
275 bool DDContainer::getNeedDragDrop() const
276 {
277 return mNeedDragDrop;
278 }
279
280 void DDContainer::_setContainerItemInfo(size_t _index, bool _set, bool _accept)
281 {
282 }
283
284 void DDContainer::resetDrag()
285 {
286 _resetContainer(false);
287 }
288
289 } // namespace MyGUI
MyGUI::ICroppedRectangle::getAbsolutePosition
const IntPoint & getAbsolutePosition() const
Definition: MyGUI_ICroppedRectangle.h:67
MyGUI::Widget
Widget properties. Widget_skin_childs Skin childs. Widget widget description should be here...
Definition: MyGUI_Widget.h:29
MyGUI::Widget::_getItemIndex
virtual size_t _getItemIndex(Widget *_item)
Definition: MyGUI_Widget.cpp:1300
MyGUI::DDItemInfo::set
void set(DDContainer *_sender, size_t _sender_index, DDContainer *_receiver, size_t _receiver_index)
Definition: MyGUI_DDItemInfo.h:71
MyGUI::DDContainer::mouseDrag
void mouseDrag(MouseButton _id)
Definition: MyGUI_DDContainer.cpp:82
MyGUI::types::TPoint< int >
MyGUI::DDItemState::End
Definition: MyGUI_DDItemInfo.h:21
MyGUI::InputManager::getMousePositionByLayer
IntPoint getMousePositionByLayer()
Definition: MyGUI_InputManager.cpp:596
MyGUI::DDContainer::getNeedDragDrop
bool getNeedDragDrop() const
Definition: MyGUI_DDContainer.cpp:275
MyGUI::DDContainer::mDropDimension
IntCoord mDropDimension
Definition: MyGUI_DDContainer.h:136
MyGUI_LayerManager.h
MyGUI::DDWidgetState::refuse
bool refuse
Definition: MyGUI_DDItemInfo.h:115
MyGUI_Precompiled.h
MyGUI::DDContainer::resetDrag
void resetDrag()
Definition: MyGUI_DDContainer.cpp:284
MyGUI::DDItemState::Miss
Definition: MyGUI_DDItemInfo.h:22
MyGUI::DDContainer::mDropInfo
DDItemInfo mDropInfo
Definition: MyGUI_DDContainer.h:130
MyGUI::DDItemInfo::reset
void reset()
Definition: MyGUI_DDItemInfo.h:79
MyGUI::newDelegate
delegates::IDelegate0 * newDelegate(void(*_func)())
Definition: MyGUI_Delegate.h:118
MyGUI::DDContainer::mouseButtonReleased
void mouseButtonReleased(MouseButton _id)
Definition: MyGUI_DDContainer.cpp:74
MyGUI::Singleton< InputManager >::getInstance
static InputManager & getInstance()
Definition: MyGUI_Singleton.h:38
MyGUI::DDItemState
Definition: MyGUI_DDItemInfo.h:15
MyGUI::Widget::isType
virtual bool isType(const std::type_info &_type) const
Definition: MyGUI_Widget.h:41
MyGUI::Widget::_resetContainer
virtual void _resetContainer(bool _update)
Definition: MyGUI_Widget.cpp:1035
MyGUI::DDItemState::Start
Definition: MyGUI_DDItemInfo.h:20
MyGUI::DDContainer::mStartDrop
bool mStartDrop
Definition: MyGUI_DDContainer.h:125
MyGUI::ITEM_NONE
const size_t ITEM_NONE
Definition: MyGUI_Macros.h:17
MyGUI::DDContainer::onMouseButtonPressed
virtual void onMouseButtonPressed(int _left, int _top, MouseButton _id)
Definition: MyGUI_DDContainer.cpp:28
MyGUI::DDWidgetState
Definition: MyGUI_DDItemInfo.h:98
MyGUI::Widget::setVisible
virtual void setVisible(bool _value)
Definition: MyGUI_Widget.cpp:965
MyGUI::DDContainer::mClickInWidget
IntPoint mClickInWidget
Definition: MyGUI_DDContainer.h:138
MyGUI::InputManager::resetMouseCaptureWidget
void resetMouseCaptureWidget()
Definition: MyGUI_InputManager.cpp:667
nullptr
#define nullptr
Definition: MyGUI_Prerequest.h:29
MyGUI::DDContainer::mReseiverContainer
DDContainer * mReseiverContainer
Definition: MyGUI_DDContainer.h:143
MyGUI::types::TPoint::top
T top
Definition: MyGUI_TPoint.h:21
MyGUI_DDContainer.h
MyGUI::types::TCoord::width
T width
Definition: MyGUI_TCoord.h:24
MyGUI::Widget::setCoord
virtual void setCoord(const IntCoord &_value)
Definition: MyGUI_Widget.cpp:689
MyGUI::DDItemState::Refuse
Definition: MyGUI_DDItemInfo.h:24
MyGUI::types::TCoord::top
T top
Definition: MyGUI_TCoord.h:23
MyGUI::MouseButton
Definition: MyGUI_MouseButton.h:15
MyGUI::DDContainer::mNeedDragDrop
bool mNeedDragDrop
Definition: MyGUI_DDContainer.h:141
MyGUI::DDContainer::_setContainerItemInfo
virtual void _setContainerItemInfo(size_t _index, bool _set, bool _accept)
Definition: MyGUI_DDContainer.cpp:280
MyGUI::DDContainer::eventUpdateDropState
delegates::CMultiDelegate3< DDContainer *, Widget *, const DDWidgetState & > eventUpdateDropState
Definition: MyGUI_DDContainer.h:101
MyGUI::DDWidgetState::update
bool update
Definition: MyGUI_DDItemInfo.h:111
MyGUI
Definition: MyGUI_ActionController.h:14
MyGUI::DDContainer::onMouseButtonReleased
virtual void onMouseButtonReleased(int _left, int _top, MouseButton _id)
Definition: MyGUI_DDContainer.cpp:38
MyGUI::Widget::eventChangeProperty
EventHandle_WidgetStringString eventChangeProperty
Definition: MyGUI_Widget.h:266
MyGUI::types::TPoint::left
T left
Definition: MyGUI_TPoint.h:20
MyGUI::DDContainer::mDropSenderIndex
size_t mDropSenderIndex
Definition: MyGUI_DDContainer.h:132
MyGUI::DDContainer::mOldDrop
Widget * mOldDrop
Definition: MyGUI_DDContainer.h:127
MyGUI::DDContainer::removeDropItems
virtual void removeDropItems()
Definition: MyGUI_DDContainer.cpp:223
MyGUI::DDItemInfo::receiver_index
size_t receiver_index
Definition: MyGUI_DDItemInfo.h:95
MyGUI::DDContainer::onMouseDrag
virtual void onMouseDrag(int _left, int _top, MouseButton _id)
Definition: MyGUI_DDContainer.cpp:45
MyGUI::Widget::_getContainer
Widget * _getContainer()
Definition: MyGUI_Widget.cpp:1310
MyGUI::DDContainer::eventChangeDDState
EventHandle_EventHandle_DDContainerPtrDDItemState eventChangeDDState
Definition: MyGUI_DDContainer.h:74
MyGUI::InputManager::getLastPressedPosition
const IntPoint & getLastPressedPosition(MouseButton _id) const
Definition: MyGUI_InputManager.cpp:638
MyGUI::DDContainer::mDropItem
Widget * mDropItem
Definition: MyGUI_DDContainer.h:135
MyGUI::DDContainer::updateDropItems
virtual void updateDropItems()
Definition: MyGUI_DDContainer.cpp:228
MyGUI::DDContainer::mouseButtonPressed
void mouseButtonPressed(MouseButton _id)
Definition: MyGUI_DDContainer.cpp:52
MyGUI_InputManager.h
MyGUI::DDContainer::mNeedDrop
bool mNeedDrop
Definition: MyGUI_DDContainer.h:124
MyGUI::DDContainer
DDContainer properties. DDContainer_skin_childs Skin childs. DDContainer widget description should b...
Definition: MyGUI_DDContainer.h:27
MyGUI::MouseButton::Left
Definition: MyGUI_MouseButton.h:21
MyGUI::DDContainer::setNeedDragDrop
void setNeedDragDrop(bool _value)
Definition: MyGUI_DDContainer.cpp:270
MyGUI::DDContainer::updateDropItemsState
virtual void updateDropItemsState(const DDWidgetState &_state)
Definition: MyGUI_DDContainer.cpp:245
MyGUI::DDContainer::eventDropResult
EventHandle_DDContainerPtrCDDItemInfoRefBool eventDropResult
Definition: MyGUI_DDContainer.h:67
MyGUI::DDContainer::setPropertyOverride
virtual void setPropertyOverride(const std::string &_key, const std::string &_value)
Definition: MyGUI_DDContainer.cpp:255
MyGUI::LayerManager::getWidgetFromPoint
Widget * getWidgetFromPoint(int _left, int _top)
Definition: MyGUI_LayerManager.cpp:195
MyGUI::DDContainer::eventStartDrag
EventHandle_DDContainerPtrCDDItemInfoRefBoolRef eventStartDrag
Definition: MyGUI_DDContainer.h:51
MyGUI::DDContainer::mCurrentSender
Widget * mCurrentSender
Definition: MyGUI_DDContainer.h:128
MyGUI::InputManager::getMousePosition
const IntPoint & getMousePosition() const
Definition: MyGUI_InputManager.cpp:647
MyGUI::DDContainer::DDContainer
DDContainer()
Definition: MyGUI_DDContainer.cpp:15
MyGUI::DDContainer::mDropResult
bool mDropResult
Definition: MyGUI_DDContainer.h:123
MyGUI::types::TCoord::left
T left
Definition: MyGUI_TCoord.h:22
MyGUI::DDContainer::requestDragWidgetInfo
EventHandle_EventHandle_DDContainerPtrWidgetPtrRefIntCoordRef requestDragWidgetInfo
Definition: MyGUI_DDContainer.h:82
MyGUI::DDContainer::eventRequestDrop
EventHandle_DDContainerPtrCDDItemInfoRefBoolRef eventRequestDrop
Definition: MyGUI_DDContainer.h:59
MyGUI::DDContainer::_eventInvalideContainer
delegates::CMultiDelegate1< DDContainer * > _eventInvalideContainer
Definition: MyGUI_DDContainer.h:93
MyGUI::types::TCoord::height
T height
Definition: MyGUI_TCoord.h:25
MyGUI::DDWidgetState::accept
bool accept
Definition: MyGUI_DDItemInfo.h:113
MyGUI::DDItemState::Accept
Definition: MyGUI_DDItemInfo.h:23
MyGUI::DDContainer::notifyInvalideDrop
virtual void notifyInvalideDrop(DDContainer *_sender)
Definition: MyGUI_DDContainer.cpp:250
MyGUI::DDContainer::endDrop
void endDrop(bool _reset)
Definition: MyGUI_DDContainer.cpp:199