Blender V5.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
8
10
11#include "ED_asset.hh"
12
13#include "WM_api.hh"
14
15#include "interface_intern.hh"
16
17namespace blender::ui {
18
20{
21 but->dragtype = WM_DRAG_ID;
22 if (but->dragflag & BUT_DRAGPOIN_FREE) {
25 }
26 but->dragpoin = static_cast<void *>(id);
27}
28
29void button_drag_attach_image(Button *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
46 but, icon, BUT_ICON_PREVIEW); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
47 if (but->dragflag & BUT_DRAGPOIN_FREE) {
49 }
50 but->dragpoin = asset_drag;
52 but->drag_preview_icon_id = preview_icon;
53}
54
56{
57 but->dragtype = WM_DRAG_RNA;
58 if (but->dragflag & BUT_DRAGPOIN_FREE) {
61 }
62 but->dragpoin = static_cast<void *>(ptr);
63}
64
65void button_drag_set_path(Button *but, const char *path)
66{
68 if (but->dragflag & BUT_DRAGPOIN_FREE) {
70 }
71 but->dragpoin = WM_drag_create_path_data(Span(&path, 1));
73}
74
75void button_drag_set_name(Button *but, const char *name)
76{
78 if (but->dragflag & BUT_DRAGPOIN_FREE) {
81 }
82 but->dragpoin = (void *)name;
83}
84
85void button_drag_set_image(Button *but, const char *path, int icon, const ImBuf *imb, float scale)
86{
87 def_but_icon(but, icon, 0); /* no flag UI_HAS_ICON, so icon doesn't draw in button */
88 button_drag_set_path(but, path);
90}
91
93{
94 if (but->dragpoin && (but->dragflag & BUT_DRAGPOIN_FREE)) {
96 }
97}
98
100{
101 return but->dragpoin != nullptr;
102}
103
105{
107 but->icon,
108 but->dragtype,
109 but->dragpoin,
112 /* wmDrag has ownership over dragpoin now, stop messing with it. */
113 but->dragpoin = nullptr;
114
115 if (but->imb) {
116 WM_event_drag_image(drag, but->imb, but->imb_scale);
117 }
118 else if (but->drag_preview_icon_id) {
120 }
121
123
124 /* Special feature for assets: We add another drag item that supports multiple assets. It
125 * gets the assets from context. */
128 }
129
130 if (but->dragtype == WM_DRAG_PATH) {
132 }
133}
134
135} // namespace blender::ui
Main runtime representation of an asset.
#define C
Definition RandGen.cpp:29
#define ELEM(...)
constexpr Span()=default
float3x3 scale(float3x3 mat, float2 scale)
void button_drag_attach_image(Button *but, const ImBuf *imb, float scale)
void button_drag_start(bContext *C, Button *but)
void button_drag_set_image(Button *but, const char *path, int icon, const ImBuf *imb, float scale)
void button_drag_set_name(Button *but, const char *name)
void button_drag_set_rna(Button *but, PointerRNA *ptr)
void button_drag_set_asset(Button *but, const asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings, int icon, int preview_icon)
void button_drag_set_path(Button *but, const char *path)
void def_but_icon(Button *but, const int icon, const int64_t flag)
bool button_drag_is_draggable(const Button *but)
void button_dragflag_enable(Button *but, int flag)
void button_drag_free(Button *but)
void button_drag_set_id(Button *but, ID *id)
wmDragAsset * WM_drag_create_asset_data(const asset_system::AssetRepresentation *asset, const AssetImportSettings &import_settings)
void WM_event_start_drag(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
@ WM_DRAG_NAME
Definition WM_types.hh:1303
@ WM_DRAG_ASSET
Definition WM_types.hh:1294
@ WM_DRAG_RNA
Definition WM_types.hh:1301
@ WM_DRAG_PATH
Definition WM_types.hh:1302
@ WM_DRAG_ASSET_LIST
Definition WM_types.hh:1300
void WM_event_drag_path_override_poin_data_with_space_file_paths(const bContext *C, wmDrag *drag)
void WM_event_drag_image(wmDrag *drag, const ImBuf *imb, float scale)
wmDrag * WM_drag_data_create(bContext *C, int icon, eWM_DragDataType type, void *poin, uint flags)
@ WM_DRAG_FREE_DATA
Definition WM_types.hh:1324
@ WM_DRAG_NOP
Definition WM_types.hh:1323
int BIFIconID
Definition ED_asset.hh:30
void WM_drag_data_free(eWM_DragDataType dragtype, void *poin)
void WM_event_drag_preview_icon(wmDrag *drag, int icon_id)
void WM_event_start_prepared_drag(bContext *C, wmDrag *drag)
wmDragPath * WM_drag_create_path_data(Span< const char * > paths)
eWM_DragDataType dragtype