Blender V4.3
interface_drop.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
9#include "UI_interface.hh"
10
11namespace blender::ui {
12
13DragInfo::DragInfo(const wmDrag &drag, const wmEvent &event, const DropLocation drop_location)
14 : drag_data(drag), event(event), drop_location(drop_location)
15{
16}
17
19 const ARegion & /*region*/, const wmEvent & /*event*/) const
20{
21 return DropLocation::Into;
22}
23
25 const ARegion &region,
26 const wmEvent &event,
27 const DropTargetInterface &drop_target,
28 const ListBase &drags)
29{
30 const char *disabled_hint_dummy = nullptr;
31 LISTBASE_FOREACH (const wmDrag *, drag, &drags) {
32 if (!drop_target.can_drop(*drag, &disabled_hint_dummy)) {
33 return false;
34 }
35
36 const std::optional<DropLocation> drop_location = drop_target.choose_drop_location(region,
37 event);
38 if (!drop_location) {
39 return false;
40 }
41
42 const DragInfo drag_info{*drag, event, *drop_location};
43 return drop_target.on_drop(&C, drag_info);
44 }
45
46 return false;
47}
48
49std::string drop_target_tooltip(const ARegion &region,
50 const DropTargetInterface &drop_target,
51 const wmDrag &drag,
52 const wmEvent &event)
53{
54 const char *disabled_hint_dummy = nullptr;
55 if (!drop_target.can_drop(drag, &disabled_hint_dummy)) {
56 return {};
57 }
58
59 const std::optional<DropLocation> drop_location = drop_target.choose_drop_location(region,
60 event);
61 if (!drop_location) {
62 return {};
63 }
64
65 const DragInfo drag_info{drag, event, *drop_location};
66 return drop_target.drop_tooltip(drag_info);
67}
68
69} // namespace blender::ui
#define LISTBASE_FOREACH(type, var, list)
virtual bool on_drop(bContext *C, const DragInfo &drag) const =0
virtual bool can_drop(const wmDrag &drag, const char **r_disabled_hint) const =0
virtual std::string drop_tooltip(const DragInfo &drag) const =0
virtual std::optional< DropLocation > choose_drop_location(const ARegion &region, const wmEvent &event) const
bool drop_target_apply_drop(bContext &C, const ARegion &region, const wmEvent &event, const DropTargetInterface &drop_target, const ListBase &drags)
std::string drop_target_tooltip(const ARegion &region, const DropTargetInterface &drop_target, const wmDrag &drag, const wmEvent &event)
DragInfo(const wmDrag &drag, const wmEvent &event, DropLocation drop_location)