Blender  V3.3
interface_drag.cc
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
7 #include "UI_interface.h"
8 
9 #include "WM_api.h"
10 
11 #include "interface_intern.h"
12 
13 void UI_but_drag_set_id(uiBut *but, ID *id)
14 {
15  but->dragtype = WM_DRAG_ID;
16  if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
19  }
20  but->dragpoin = (void *)id;
21 }
22 
23 void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale)
24 {
25  but->imb = imb;
26  but->imb_scale = scale;
27 }
28 
30  const AssetHandle *asset,
31  const char *path,
32  struct AssetMetaData *metadata,
33  int import_type,
34  int icon,
35  struct ImBuf *imb,
36  float scale)
37 {
38  wmDragAsset *asset_drag = WM_drag_create_asset_data(asset, metadata, path, import_type);
39 
40  /* FIXME: This is temporary evil solution to get scene/viewlayer/etc in the copy callback of the
41  * #wmDropBox.
42  * TODO: Handle link/append in operator called at the end of the drop process, and NOT in its
43  * copy callback.
44  * */
45  asset_drag->evil_C = static_cast<bContext *>(but->block->evil_C);
46 
47  but->dragtype = WM_DRAG_ASSET;
48  ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
49  if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
51  }
52  but->dragpoin = asset_drag;
54  UI_but_drag_attach_image(but, imb, scale);
55 }
56 
58 {
59  but->dragtype = WM_DRAG_RNA;
60  if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
63  }
64  but->dragpoin = (void *)ptr;
65 }
66 
67 void UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free)
68 {
69  but->dragtype = WM_DRAG_PATH;
70  if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
73  }
74  but->dragpoin = (void *)path;
75  if (use_free) {
77  }
78 }
79 
80 void UI_but_drag_set_name(uiBut *but, const char *name)
81 {
82  but->dragtype = WM_DRAG_NAME;
83  if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
86  }
87  but->dragpoin = (void *)name;
88 }
89 
91 {
92  but->dragtype = WM_DRAG_VALUE;
93 }
94 
96  uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free)
97 {
98  but->dragtype = WM_DRAG_PATH;
99  ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
100  if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
101  WM_drag_data_free(but->dragtype, but->dragpoin);
103  }
104  but->dragpoin = (void *)path;
105  if (use_free) {
107  }
108  UI_but_drag_attach_image(but, imb, scale);
109 }
110 
112 {
113  if (but->dragpoin && (but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
114  WM_drag_data_free(but->dragtype, but->dragpoin);
115  }
116 }
117 
119 {
120  return but->dragpoin != nullptr;
121 }
122 
124 {
125  wmDrag *drag = WM_drag_data_create(C,
126  but->icon,
127  but->dragtype,
128  but->dragpoin,
129  ui_but_value_get(but),
131  WM_DRAG_NOP);
132  /* wmDrag has ownership over dragpoin now, stop messing with it. */
133  but->dragpoin = NULL;
134 
135  if (but->imb) {
136  WM_event_drag_image(drag, but->imb, but->imb_scale);
137  }
138 
140 
141  /* Special feature for assets: We add another drag item that supports multiple assets. It
142  * gets the assets from context. */
143  if (ELEM(but->dragtype, WM_DRAG_ASSET, WM_DRAG_ID)) {
145  }
146 }
#define ELEM(...)
#define C
Definition: RandGen.cpp:25
#define WM_DRAG_PATH
Definition: WM_types.h:1050
@ WM_DRAG_NOP
Definition: WM_types.h:1058
@ WM_DRAG_FREE_DATA
Definition: WM_types.h:1059
#define WM_DRAG_NAME
Definition: WM_types.h:1051
#define WM_DRAG_ASSET_LIST
Definition: WM_types.h:1048
#define WM_DRAG_ASSET
Definition: WM_types.h:1044
#define WM_DRAG_RNA
Definition: WM_types.h:1049
#define WM_DRAG_VALUE
Definition: WM_types.h:1052
#define WM_DRAG_ID
Definition: WM_types.h:1043
double ui_but_value_get(uiBut *but)
Definition: interface.cc:2492
void ui_def_but_icon(uiBut *but, const int icon, const int flag)
Definition: interface.cc:4244
void ui_but_drag_free(uiBut *but)
void UI_but_drag_set_image(uiBut *but, const char *path, int icon, struct ImBuf *imb, float scale, const bool use_free)
void UI_but_drag_set_path(uiBut *but, const char *path, const bool use_free)
void UI_but_drag_set_asset(uiBut *but, const AssetHandle *asset, const char *path, struct AssetMetaData *metadata, int import_type, int icon, struct ImBuf *imb, float scale)
void UI_but_drag_set_rna(uiBut *but, PointerRNA *ptr)
void UI_but_drag_set_value(uiBut *but)
bool ui_but_drag_is_draggable(const uiBut *but)
void UI_but_drag_set_id(uiBut *but, ID *id)
void ui_but_drag_start(bContext *C, uiBut *but)
void UI_but_drag_attach_image(uiBut *but, struct ImBuf *imb, const float scale)
void UI_but_drag_set_name(uiBut *but, const char *name)
@ UI_BUT_DRAGPOIN_FREE
The meta-data of an asset. By creating and giving this for a data-block (ID.asset_data),...
Definition: DNA_ID.h:368
void * evil_C
short dragflag
void * dragpoin
uiBlock * block
struct ImBuf * imb
BIFIconID icon
char dragtype
float imb_scale
struct bContext * evil_C
Definition: WM_types.h:1087
void WM_event_start_drag(bContext *C, int icon, int type, void *poin, double value, unsigned int flags)
Definition: wm_dragdrop.cc:237
void WM_event_drag_image(wmDrag *drag, ImBuf *imb, float scale)
Definition: wm_dragdrop.cc:288
void WM_event_start_prepared_drag(bContext *C, wmDrag *drag)
Definition: wm_dragdrop.cc:229
void WM_drag_data_free(int dragtype, void *poin)
Definition: wm_dragdrop.cc:294
wmDrag * WM_drag_data_create(bContext *C, int icon, int type, void *poin, double value, unsigned int flags)
Definition: wm_dragdrop.cc:177
wmDragAsset * WM_drag_create_asset_data(const AssetHandle *asset, AssetMetaData *metadata, const char *path, int import_type)
Definition: wm_dragdrop.cc:561
PointerRNA * ptr
Definition: wm_files.c:3480