MyGUI
3.2.0
Main Page
Related Pages
Namespaces
Data Structures
Files
Examples
File List
Globals
MyGUIEngine
src
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
Generated by
1.8.4