MyGUI 3.2.0

- Main Page
- Related Pages
- Namespaces
- Data Structures
- Files
- Examples

- File List
- Globals

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