MyGUI: MyGUI_DDContainer.cpp Source File

MyGUI 3.4.3

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