Blender V4.5
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 "UI_interface.hh"
14
15#include "WM_api.hh"
16
17#include "interface_intern.hh"
18
20{
21 but->dragtype = WM_DRAG_ID;
22 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
25 }
26 but->dragpoin = (void *)id;
27}
28
29void UI_but_drag_attach_image(uiBut *but, const ImBuf *imb, const float scale)
30{
31 but->imb = imb;
32 but->imb_scale = scale;
34}
35
38 const AssetImportSettings &import_settings,
39 BIFIconID icon,
40 BIFIconID preview_icon)
41{
42 wmDragAsset *asset_drag = WM_drag_create_asset_data(asset, import_settings);
43
45 ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
46 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
48 }
49 but->dragpoin = asset_drag;
51 but->drag_preview_icon_id = preview_icon;
52}
53
55{
56 but->dragtype = WM_DRAG_RNA;
57 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
60 }
61 but->dragpoin = (void *)ptr;
62}
63
64void UI_but_drag_set_path(uiBut *but, const char *path)
65{
67 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
69 }
72}
73
74void UI_but_drag_set_name(uiBut *but, const char *name)
75{
77 if (but->dragflag & UI_BUT_DRAGPOIN_FREE) {
80 }
81 but->dragpoin = (void *)name;
82}
83
84void UI_but_drag_set_image(uiBut *but, const char *path, int icon, const ImBuf *imb, float scale)
85{
86 ui_def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
87 UI_but_drag_set_path(but, path);
88 UI_but_drag_attach_image(but, imb, scale);
89}
90
92{
93 if (but->dragpoin && (but->dragflag & UI_BUT_DRAGPOIN_FREE)) {
95 }
96}
97
99{
100 return but->dragpoin != nullptr;
101}
102
104{
106 but->icon,
107 but->dragtype,
108 but->dragpoin,
111 /* wmDrag has ownership over dragpoin now, stop messing with it. */
112 but->dragpoin = nullptr;
113
114 if (but->imb) {
115 WM_event_drag_image(drag, but->imb, but->imb_scale);
116 }
117 else if (but->drag_preview_icon_id) {
119 }
120
122
123 /* Special feature for assets: We add another drag item that supports multiple assets. It
124 * gets the assets from context. */
127 }
128
129 if (but->dragtype == WM_DRAG_PATH) {
131 }
132}
Main runtime representation of an asset.
#define ELEM(...)
int BIFIconID
Definition ED_asset.hh:29
#define C
Definition RandGen.cpp:29
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:1225
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1226
@ WM_DRAG_RNA
Definition WM_types.hh:1204
@ WM_DRAG_PATH
Definition WM_types.hh:1205
@ WM_DRAG_ASSET_LIST
Definition WM_types.hh:1203
@ WM_DRAG_NAME
Definition WM_types.hh:1206
@ WM_DRAG_ASSET
Definition WM_types.hh:1199
@ WM_DRAG_ID
Definition WM_types.hh:1198
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)
Definition DNA_ID.h:404
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:4226