Blender V4.3
interface_drag.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
11#include "WM_api.hh"
12
13#include "interface_intern.hh"
14
16{
17 but->dragtype = WM_DRAG_ID;
18 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
20 but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
21 }
22 but->dragpoin = (void *)id;
23}
24
25void UI_but_drag_attach_image(uiBut *but, const ImBuf *imb, const float scale)
26{
27 but->imb = imb;
28 but->imb_scale = scale;
30}
31
34 int import_method,
35 int icon,
36 const ImBuf *imb,
37 float scale)
38{
39 wmDragAsset *asset_drag = WM_drag_create_asset_data(asset, import_method);
40
42 ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
43 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
45 }
46 but->dragpoin = asset_drag;
48 UI_but_drag_attach_image(but, imb, scale);
49}
50
52{
53 but->dragtype = WM_DRAG_RNA;
54 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
56 but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
57 }
58 but->dragpoin = (void *)ptr;
59}
60
61void UI_but_drag_set_path(uiBut *but, const char *path)
62{
64 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
66 }
69}
70
71void UI_but_drag_set_name(uiBut *but, const char *name)
72{
74 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
76 but->dragflag &= ~UI_BUT_DRAGPOIN_FREE;
77 }
78 but->dragpoin = (void *)name;
79}
80
81void UI_but_drag_set_image(uiBut *but, const char *path, int icon, const ImBuf *imb, float scale)
82{
83 ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
84 UI_but_drag_set_path(but, path);
85 UI_but_drag_attach_image(but, imb, scale);
86}
87
89{
90 if (but->dragpoin && (but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
92 }
93}
94
96{
97 return but->dragpoin != nullptr;
98}
99
101{
102 wmDrag *drag = WM_drag_data_create(C,
103 but->icon,
104 but->dragtype,
105 but->dragpoin,
108 /* wmDrag has ownership over dragpoin now, stop messing with it. */
109 but->dragpoin = nullptr;
110
111 if (but->imb) {
112 WM_event_drag_image(drag, but->imb, but->imb_scale);
113 }
114
116
117 /* Special feature for assets: We add another drag item that supports multiple assets. It
118 * gets the assets from context. */
120 WM_event_start_drag(C, ICON_NONE, WM_DRAG_ASSET_LIST, nullptr, WM_DRAG_NOP);
121 }
122}
#define ELEM(...)
void UI_but_dragflag_enable(uiBut *but, int flag)
@ UI_BUT_DRAGPOIN_FREE
@ UI_BUT_DRAG_FULL_BUT
@ WM_DRAG_NOP
Definition WM_types.hh:1180
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1181
@ WM_DRAG_RNA
Definition WM_types.hh:1159
@ WM_DRAG_PATH
Definition WM_types.hh:1160
@ WM_DRAG_ASSET_LIST
Definition WM_types.hh:1158
@ WM_DRAG_NAME
Definition WM_types.hh:1161
@ WM_DRAG_ASSET
Definition WM_types.hh:1154
@ WM_DRAG_ID
Definition WM_types.hh:1153
void ui_def_but_icon(uiBut *but, const int icon, const int flag)
void ui_but_drag_free(uiBut *but)
void UI_but_drag_set_image(uiBut *but, const char *path, int icon, const ImBuf *imb, float scale)
void UI_but_drag_attach_image(uiBut *but, const ImBuf *imb, const float scale)
void UI_but_drag_set_path(uiBut *but, const char *path)
void UI_but_drag_set_rna(uiBut *but, PointerRNA *ptr)
bool ui_but_drag_is_draggable(const uiBut *but)
void UI_but_drag_set_id(uiBut *but, ID *id)
void UI_but_drag_set_asset(uiBut *but, const blender::asset_system::AssetRepresentation *asset, int import_method, int icon, const ImBuf *imb, float scale)
void ui_but_drag_start(bContext *C, uiBut *but)
void UI_but_drag_set_name(uiBut *but, const char *name)
Definition DNA_ID.h:413
void * dragpoin
const ImBuf * imb
BIFIconID icon
eWM_DragDataType dragtype
float imb_scale
wmDragAsset * WM_drag_create_asset_data(const blender::asset_system::AssetRepresentation *asset, int import_method)
wmDragPath * WM_drag_create_path_data(blender::Span< const char * > paths)
void WM_event_start_drag(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
void WM_event_start_prepared_drag(bContext *C, wmDrag *drag)
wmDrag * WM_drag_data_create(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
void WM_event_drag_image(wmDrag *drag, const ImBuf *imb, float scale)
void WM_drag_data_free(eWM_DragDataType dragtype, void *poin)
PointerRNA * ptr
Definition wm_files.cc:4126