Blender V5.0
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
8
9#include "BLI_listbase.h"
10
11#include "UI_interface.hh"
12
13namespace blender::ui {
14
19
21 const ARegion & /*region*/, const wmEvent & /*event*/) const
22{
23 return DropLocation::Into;
24}
25
27 const ARegion &region,
28 const wmEvent &event,
29 const DropTargetInterface &drop_target,
30 const ListBase &drags)
31{
32 const char *disabled_hint_dummy = nullptr;
33 LISTBASE_FOREACH (const wmDrag *, drag, &drags) {
34 if (!drop_target.can_drop(*drag, &disabled_hint_dummy)) {
35 return false;
36 }
37
38 const std::optional<DropLocation> drop_location = drop_target.choose_drop_location(region,
39 event);
40 if (!drop_location) {
41 return false;
42 }
43
44 const DragInfo drag_info{*drag, event, *drop_location};
45 return drop_target.on_drop(&C, drag_info);
46 }
47
48 return false;
49}
50
51std::string drop_target_tooltip(const ARegion &region,
52 const DropTargetInterface &drop_target,
53 const wmDrag &drag,
54 const wmEvent &event)
55{
56 const char *disabled_hint_dummy = nullptr;
57 if (!drop_target.can_drop(drag, &disabled_hint_dummy)) {
58 return {};
59 }
60
61 const std::optional<DropLocation> drop_location = drop_target.choose_drop_location(region,
62 event);
63 if (!drop_location) {
64 return {};
65 }
66
67 const DragInfo drag_info{drag, event, *drop_location};
68 return drop_target.drop_tooltip(drag_info);
69}
70
71} // namespace blender::ui
#define LISTBASE_FOREACH(type, var, list)
#define C
Definition RandGen.cpp:29
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)
const wmDrag & drag_data
const DropLocation drop_location
const wmEvent & event