Blender V5.0
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
8
10
11#include "ED_asset.hh"
12
13#include "WM_api.hh"
14
15#include "interface_intern.hh"
16
18{
19 but->dragtype = WM_DRAG_ID;
20 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
23 }
24 but->dragpoin = (void *)id;
25}
26
27void UI_but_drag_attach_image(uiBut *but, const ImBuf *imb, const float scale)
28{
29 but->imb = imb;
30 but->imb_scale = scale;
32}
33
36 const AssetImportSettings &import_settings,
37 BIFIconID icon,
38 BIFIconID preview_icon)
39{
40 wmDragAsset *asset_drag = WM_drag_create_asset_data(asset, import_settings);
41
43 ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
44 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
46 }
47 but->dragpoin = asset_drag;
49 but->drag_preview_icon_id = preview_icon;
50}
51
53{
54 but->dragtype = WM_DRAG_RNA;
55 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
58 }
59 but->dragpoin = (void *)ptr;
60}
61
62void UI_but_drag_set_path(uiBut *but, const char *path)
63{
65 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
67 }
70}
71
72void UI_but_drag_set_name(uiBut *but, const char *name)
73{
75 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
78 }
79 but->dragpoin = (void *)name;
80}
81
82void UI_but_drag_set_image(uiBut *but, const char *path, int icon, const ImBuf *imb, float scale)
83{
84 ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
85 UI_but_drag_set_path(but, path);
86 UI_but_drag_attach_image(but, imb, scale);
87}
88
90{
91 if (but->dragpoin && (but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
93 }
94}
95
97{
98 return but->dragpoin != nullptr;
99}
100
102{
104 but->icon,
105 but->dragtype,
106 but->dragpoin,
109 /* wmDrag has ownership over dragpoin now, stop messing with it. */
110 but->dragpoin = nullptr;
111
112 if (but->imb) {
113 WM_event_drag_image(drag, but->imb, but->imb_scale);
114 }
115 else if (but->drag_preview_icon_id) {
117 }
118
120
121 /* Special feature for assets: We add another drag item that supports multiple assets. It
122 * gets the assets from context. */
125 }
126
127 if (but->dragtype == WM_DRAG_PATH) {
129 }
130}
Main runtime representation of an asset.
#define ELEM(...)
int BIFIconID
Definition ED_asset.hh:28
#define C
Definition RandGen.cpp:29
@ UI_BUT_DRAGPOIN_FREE
@ UI_BUT_DRAG_FULL_BUT
void UI_but_dragflag_enable(uiBut *but, int flag)
@ WM_DRAG_NOP
Definition WM_types.hh:1229
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1230
@ WM_DRAG_RNA
Definition WM_types.hh:1207
@ WM_DRAG_PATH
Definition WM_types.hh:1208
@ WM_DRAG_ASSET_LIST
Definition WM_types.hh:1206
@ WM_DRAG_NAME
Definition WM_types.hh:1209
@ WM_DRAG_ASSET
Definition WM_types.hh:1202
@ WM_DRAG_ID
Definition WM_types.hh:1201
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_asset(uiBut *but, const blender::asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings, BIFIconID icon, BIFIconID preview_icon)
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_start(bContext *C, uiBut *but)
void UI_but_drag_set_name(uiBut *but, const char *name)
const char * name
Definition DNA_ID.h:414
int8_t dragflag
void * dragpoin
const ImBuf * imb
BIFIconID drag_preview_icon_id
BIFIconID icon
eWM_DragDataType dragtype
float imb_scale
wmDragAsset * WM_drag_create_asset_data(const blender::asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings)
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)
void WM_event_drag_path_override_poin_data_with_space_file_paths(const 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_event_drag_preview_icon(wmDrag *drag, int icon_id)
void WM_drag_data_free(eWM_DragDataType dragtype, void *poin)
PointerRNA * ptr
Definition wm_files.cc:4238